In: Computer Science
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0 and initially containing 0 . Also assume base of array Arr is in $s3
while ( k < = 10 )
{
Arr[k] = k ;
k = k + 1;
}
1). ANSWER :
GIVENTHAT :
Converted Code:
main:
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #12
.L3:
ldr r3, [fp, #-8]
cmp r3, #10
bgt .L2
ldr r3, [fp, #-8]
lsl r3, r3, #2
sub r2, fp, #4
add r3, r2, r3
ldr r2, [fp, #-8]
str r2, [r3, #-4]
ldr r3, [fp, #-8]
add r3, r3, #1
str r3, [fp, #-8]
b .L3
.L2:
mov r3, #0
mov r0, r3
add sp, fp, #0
ldr fp, [sp], #4
bx lr
__static_initialization_and_destruction_0(int, int):
push {fp, lr}
add fp, sp, #4
sub sp, sp, #8
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r3, [fp, #-8]
cmp r3, #1
bne .L7
ldr r3, [fp, #-12]
ldr r2, .L8
cmp r3, r2
bne .L7
ldr r0, .L8+4
bl std::ios_base::Init::Init() [complete object constructor]
ldr r2, .L8+8
ldr r1, .L8+12
ldr r0, .L8+4
bl __aeabi_atexit
.L7:
nop
sub sp, fp, #4
pop {fp, pc}
.L8:
.word 65535
.word _ZStL8__ioinit
.word __dso_handle
.word _ZNSt8ios_base4InitD1Ev
_GLOBAL__sub_I_main:
push {fp, lr}
add fp, sp, #4
ldr r1, .L11
mov r0, #1
bl __static_initialization_and_destruction_0(int, int)
pop {fp, pc}
.L11:
.word 65535