Need help with some Homework question due 11.50 tonight. pl ease. 1. What is the
ID: 3550198 • Letter: N
Question
Need help with some Homework question due 11.50 tonight. please.
1. What is the difference between the behavior of lb and lbu?
_____________________________________________
_____________________________________________
2. The machine instructions generated from addi and andi both contain a 16 bit immediate. This 16 bit immediate must be expanded to 32 bits before either operation can take place. What is the difference in how the expansion is carried out?
_____________________________________________
_____________________________________________
Suppose the length and width of a rectangle are in r3 and r5 respectively. Write these three code fragments related to the rectangle. Assume the values to be computed will all fit in 32 bits. Use whatever temporary registers you need. I have given you more space than you need for each of these.
3.Give a code fragment that would place the perimeter of the rectangle in r6.
________________________________________________
________________________________________________
________________________________________________
________________________________________________
________________________________________________
4. Give a code fragment that would place the area of the rectangle in r7.
________________________________________________
________________________________________________
________________________________________________
________________________________________________
________________________________________________
5. Give a code fragment that would place the square of the diagonal of the rectangle in r8. (Remember Pythagorus)
________________________________________________
________________________________________________
________________________________________________
________________________________________________
________________________________________________
________________________________________________
(6)
Explanation / Answer
1:
lb loads the byte at the address provided and pads the reamining 3 bytes depending on the sign of the byte at the address.
Example: if the byte at address is 0x84(signbit is 1) then it will load 0xFFFFFF84 (pad all the remaining 3 bytes with 1)
if the byte at address is 0x74(signbit is 0) then it will load 0x00000074 (pad all the remaining 3 bytes with 0)
Where as lbu just loads the byte at address with just padding the zeros.
Examples: if the byte at address is 0x84(signbit is 1) then it will load 0x00000084 (pad all the remaining 3 bytes with 0)
if the byte at address is 0x74(signbit is 0) then it will load 0x00000074 (pad all the remaining 3 bytes with 0)
2:
16 bit immediate in addi will be sign extended but the immediate in andi will be padded with zeros
Example: addi
if the 16 bit immediate is 0x8412(signbit is 1) then it will load 0xFFFF8412 (pad all the remaining 2 bytes with 1)
if the 16 bit immediate is 0x7412(signbit is 0) then it will load 0x00007412 (pad all the remaining 2 bytes with 0)
Example: andi
if the 16 bit immediate is 0x8412(signbit is 1) then it will load 0x00008412 (pad all the remaining 2 bytes with 0)
if the 16 bit immediate is 0x7412(signbit is 0) then it will load 0x00007412 (pad all the remaining 2 bytes with 0)
3:
perimeter is 2time (width + lenght)
ADD r6,r3,r5;
ADD r6,r6,r6;
4:
area is widht times length
MUL r7,r3,r5
5:
MUL r8,r3,r3; // store the widht square in r8
MUL r7,r5,r5; // store the length square in r7
ADD r8,r7,r8; // add r7 and r8
6:
array: .word 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
la $6,array;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.