Se está descargando tu SlideShare. ×

Convert the following C code to MIPS - for (i-0- i - n- i++) { A-i- -.docx

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Próximo SlideShare
Chapter Eight(3)
Cargando en…3
×

1 de 2 Anuncio

Convert the following C code to MIPS - for (i-0- i - n- i++) { A-i- -.docx

Convert the following C code to MIPS
. for (i=0; i < n; i++) {
A[i] = A[i] + i;
}
Solution
main()
{
int A[10],i,n;
for (i=0; i < n; i++)
{
A[i] = A[i] + i;
}
}
code in mips i have so far:
main:
@ args = 0, pretend = 0, frame = 48
@ frame_needed = 1, uses_anonymous_args = 0
push    {r7}
sub     sp, sp, #52
mov     r3, #0
str     r3, [r7, #44]
b       .L2
.L3:
ldr     r3, [r7, #44]
lsl     r3, r3, #2
ldr     r2, [r3, #-48]
ldr     r3, [r7, #44]
ldr     r3, [r7, #44]
lsl     r3, r3, #2
str     r2, [r3, #-48]
ldr     r3, [r7, #44]
str     r3, [r7, #44]
.L2:
ldr     r2, [r7, #44]
ldr     r3, [r7, #40]
cmp     r2, r3
ite     ge
movge   r3, #0
movlt   r3, #1
uxtb    r3, r3
cmp     r3, #0
bne     .L3
mov     r3, #0
mov     r0, r3
mov     sp, r7
pop     {r7}
bx      lr
.

Convert the following C code to MIPS
. for (i=0; i < n; i++) {
A[i] = A[i] + i;
}
Solution
main()
{
int A[10],i,n;
for (i=0; i < n; i++)
{
A[i] = A[i] + i;
}
}
code in mips i have so far:
main:
@ args = 0, pretend = 0, frame = 48
@ frame_needed = 1, uses_anonymous_args = 0
push    {r7}
sub     sp, sp, #52
mov     r3, #0
str     r3, [r7, #44]
b       .L2
.L3:
ldr     r3, [r7, #44]
lsl     r3, r3, #2
ldr     r2, [r3, #-48]
ldr     r3, [r7, #44]
ldr     r3, [r7, #44]
lsl     r3, r3, #2
str     r2, [r3, #-48]
ldr     r3, [r7, #44]
str     r3, [r7, #44]
.L2:
ldr     r2, [r7, #44]
ldr     r3, [r7, #40]
cmp     r2, r3
ite     ge
movge   r3, #0
movlt   r3, #1
uxtb    r3, r3
cmp     r3, #0
bne     .L3
mov     r3, #0
mov     r0, r3
mov     sp, r7
pop     {r7}
bx      lr
.

Anuncio
Anuncio