Now we are doing things slightly differently, and bringing in the handling of negatives.
Since a good portion of this is still repeated, I am removing load/store instructions form the writeup because they will not change from the previous two examples. I am however going to continue my ARM conversions.
r0==f
r1==g
r2==h
r3==i
a. f = –g – f;
b. f = g + (–f – 5);
2.3.1 For the C statements above, what s the corresponding MIPS
assembly code? Use a minimal number of MIPS assembly instructions.
a)
MIPS
|
Comment
|
ARM
|
sub $r1, $zero, r1
sub $r0, $r1, $r0
|
#g = 0 - g
#f = g - f
|
sub r1, #0, r1
sub r0, r1, r0
|
b)
MIPS
|
Comment
|
ARM
|
sub $r0, $zero, r0
addi $r0, $r0, -5
add $r0, $r1, $r0
|
#f = 0 - f
#f = f-5
#f = g+f
|
sub r0, #0, r0
sub r0, r0, #5
add r0,r1,r0
|
2.3.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?
a) 2 subtractions = 2 Instructions
b) 1 subtract, 1 add immediate, 1 add = 3 instructions
2.3.3 I the variables f, g, h, i, and j have values 1, 2, 3, 4, and 5, respectively, what s the end value o f?
f=1 g=2 h=3 i=4
a)g = 0 - 2 = -2
f = -2 - 1 = -3
b)f = 0-1 = -1
f = -1-5 = -6
f = 2 + -6 = -4
a. addi f, f, 4
b. add f, g, h
sub f, i, f
Converted to ARM
a. add f, f, #4
b. add f,g,h
sub f,i,f
2.2.4 [5] <2.2> For the MIPS assembly instructions above, what is a corresponding C statement?
a) f += 4
b) f = g+h
f = i-f
f = i - (g + h)
2.2.5 [5] <2.2> I the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what s the end value of f?
f=1 g=2 h=3 i=4
a) f = 1 + 4 = 5
b) f = 2 + 3 = 5
f = 4 - 5 = -1
I could find no $zero equivalent in ARM, and found no example of a negative being added in ARM, so I am assuming you must use sub instead. This exercise went extremely quickly as, while adding another instruction, is still the same stuff gone over in the previous two exercises.
No comments:
Post a Comment