Since I already wrote a MIPS program for the 2.1, editing it for this would be too trivial as the problems are nearly identical; i decided to convert the MIPS asm into ARM assembly as I went along.
a. f = g – f;
b. f = i + (h – 2);
I am assuming f,g,h,i are offsets 0, 4, 8, 12 respectively of $s1
2.2.1 For the C statements above, what s the corresponding MIPS
assembly code? Use a minimal number of MIPS assembly instructions.
a)
MIPS
|
ARM
|
lw $r1, 0($s1) #f is 0 away from $s1
lw $r2, 4($s1) #g is 4 away from $s1
sub $r1, $r2, $r1 #f = g - f
sw $r1, 0($s1) #store f in $s1 offset 0
|
ldr r0, [r4, #0]
ldr r1, [r4, #4]
sub r0, r1, r0
str r0, [r4, #0]
|
b)
MIPS
|
ARM
|
lw $r1, 0($s1) #f is 0 away from $s1
lw $r3, 8($s1) #h is 8 away from $s1
lw $r4, 12($s1) #g is 12 away from $s1
addi $r3, $r3, -2 #h = h-2
add $r1, $r4, $r3 #f = i+h
sw $r1, 0($s1) #store f in $s1 offset 0
|
ldr r0, [r4, #0]
ldr r2, [r4, #8]
ldr r3, [r4, #12]
sub r2, r2, #2
add r0, r3, r2
str r0, [r4, #0]
|
2.2.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?
a)4
b)6
2.2.3 If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what s the end value of f?
a)
sub $r1, $r2, $r1 #f = g - f $f = 2-1 = 1
f = 1
b)
sub $r3, $r3, 2 #h = h-2 h = 3 - 2 = 1
add $r1, $r4, $r3 #f = i+h f = 4 + 1 = 5
f = 5
a. addi f, f, 4
b. add f, g, h
sub f, i, f
Converted into ARM
a) add f,f,#4
b) add f.g,h
sub f,i,f
2.2.4 For the MIPS assembly instructions above, what s a correspond-
ng C statement?
a) f += 4
b) f = g+h
f = i-f
2.2.5 If the variables f, g, h, and i have values 1, 2, 3, and 4, respec-
tvey, what s the end value of f?
a) f = 1 + 4 = 4
b) f = 2+3 = 5
f = 4-5 = -1
The first jump I have taken into ARM. I have stayed mostly to MIPS. I used a couple sources including the book to help me along.
The second link being by far the most helpful.
This exercise was just a repeat of the first. No new concept to try out, just practice makes perfect.
No comments:
Post a Comment