computer organization and assembly language
CSE2312-001 (Summer 2020) Homework #2
Notes:
- With this homework, we move from abstract processor concepts to the ARM processor as used on the RPi when running Rasbian operating system.
- All numbers are in base-10 unless otherwise noted. - If part of a problem is not solvable, explain why in the answer area. - Print out this form and handwrite your answers in the spaces below. - Place the hw2_prob5.s file and the scanned answers to problems 1, 2, 3, and 4 in
a single zip file with name lastname_hw2.zip, where lastname is your last name as listed in MyMav.
- Submit the single zip file to Canvas before 11:59:00pm on July 11, 2020.
1. Assuming R1 contains 0x12345678, R2 contains 1, and R0 contains 0x50000000, write the contents of the memory locations below after the STR instruction writes to memory, assuming that each operation is independent. If a number not known, mark the blank with an “X”.
a. STR R1, [R0]; assuming little-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
b. STRH R1, [R0]; assuming big-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
c. STRB R1, [R0]; assuming little-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
d. STR R1, [R0]; assuming big-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
e. STRH R1, [R0]; assuming little-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
f. STRB R1, [R0]; assuming big-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
g. STRB R1, [R0, R2]; assuming big-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
h. STRH R1, [R0, R2]; assuming big-endian convention:
Value at address 0x50000000 is ______
Value at address 0x50000001 is ______
Value at address 0x50000002 is ______
Value at address 0x50000003 is ______
2. Assuming the memory locations contain the data below.
Address Data
0x50000000 0x12 0x50000001 0x34 0x50000002 0x96 0x50000003 0xA8
What is the value of R0 (all 32-bits in hex) after each of the following instructions executes assuming big-endian convention:
a. LDR R0, [R1] assuming R1 = 0x50000000
b. LDRH R0, [R1, R2] assuming R1 = 0x50000000 and R2 = 2
c. LDRSH R0, [R1] assuming R1 = 0x50000002
d. LDRB R0, [R1] assuming R1 = 0x50000003
e. LDRSB R0, [R1] assuming R1 = 0x50000003
f. LDRSB R0, [R1, R2] assuming R1 = 0x50000000 and R2 = 3
3. For each of these C functions, specify the ARM7 register(s) in which each argument is passed and result is returned.
a. uint32_t fn4(uint8_t a, uint32_t b, int16_t c, uint32_t d)
a is passed in: ______________________
b is passed in: ______________________
c is passed in: ______________________
d is passed in: ______________________
the result is returned in: ______________________
b. uint64_t fn3(uint64_t a, int16_t b, uint8_t c)
a is passed in: ______________________
b is passed in: ______________________
c is passed in: ______________________
the result is returned in: ______________________
4. Determine the value of the 12-bit value stored as for operand2 for the 32bit immediate value of the following instructions, where m = n ROR 2s as described in the lectures:
a. MOV R0, #0x81000
s = __________ n = ______________________
b. MOV R0, #67584
s = __________ n = ______________________
c. Show the encoding with MVN to move a value of -17 to R0.
s = __________ n = ______________________
5. Write assembly functions that implement the following C functions:
a. uint64_t addU32_U64(uint32_t x, uint32_t y) // returns x+y
b. uint64_t subU64(uint64_t x, uint64_t y) // returns (x-y)%(264) – this means that the result is limited to 64-bits, since the carry out of bit 63 is lost
c. int8_t minS8(int8_t x, int8_t y) // returns the minimum of x, y
d. uint32_t maxU32(uint32_t x, uint32_t y) // returns the minimum of x, y
e. bool isLessThanU16(uint16_t x, uint16_t y) // returns 1 if x<y, 0 else
f. bool isGreaterThanS16(int16_t x, int16_t y) // returns 1 if x<y, 0 else
g. uint32_t shiftLeftU32 (uint32_t x, uint32_t p) // returns x << p = x*2^p for p = 0..31
h. int32_t shiftLeftS32 (int32_t x, uint32_t p) // returns x << p = x*2^p for p = 0..31
i. uint32_t shiftU32(uint32_t x, int32_t p) // return x*2^p for p = -31..31
j. uint16_t shiftU16(uint16_t x, int32_t p) // return x*2^p for p = -31..31
k. bool isEqualU8(uint8_t x, uint8_t y) // returns 1 if x=y, 0 if x!=y
l. bool isEqualS8(int8_t x, int8_t y) // returns 1 if x=y, 0 if x!=y
m. bool isStrSame(const char* str1, const char* str2) // returns 1 the strings are the same, 0 otherwise
n. void strCopy(char* strTo, const char* strFrom) // copies strFrom to strTo
All of the functions above should be present in a single file named hw2_prob5.s with functions callable from a C program. You do not need to submit the C files.