Question

2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 vari

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Assuming we have a C code like this :

void fillZ() {
    int x[10];
    int y[10];
    int z[10];
    int i=0;
    while(i++<=10){
        if(x[i]==y[i])
            z[i]=x[i]*y[i];
        else
            z[i]=x[i]+y[i];
    }  
}

Then the ARM gcc 8.2 (WinCE) code for the above will be below :

fillZ():
        str     fp, [sp, #-4]!
        add     fp, sp, #0
        sub     sp, sp, #124
        mov     r3, #0
        str     r3, [fp, #-4]
.L5:
        ldr     r3, [fp, #-4] //start while(i++<=10){
        add     r2, r3, #1
        str     r2, [fp, #-4]
        cmp     r3, #10
        movle   r3, #1
        movgt   r3, #0
        and     r3, r3, #255
        cmp     r3, #0
        beq     .L6                //end while(i++<=10){
        ldr     r3, [fp, #-4]        //start if(x[i]==y[i])
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r2, [r3, #-44]
        ldr     r3, [fp, #-4]
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r3, [r3, #-84]
        cmp     r2, r3
        bne     .L3                //end if(x[i]==y[i])
        ldr     r3, [fp, #-4] //start z[i]=x[i]*y[i];
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r1, [r3, #-44]
        ldr     r3, [fp, #-4]
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r3, [r3, #-84]
        mul     r2, r3, r1
        ldr     r3, [fp, #-4]
        lsl     r3, r3, #2
        add     r3, fp, r3
        str     r2, [r3, #-124]
        b       .L5            //end z[i]=x[i]*y[i];
.L3:
        ldr     r3, [fp, #-4] //start else z[i]=x[i]+y[i];
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r2, [r3, #-44]
        ldr     r3, [fp, #-4]
        lsl     r3, r3, #2
        add     r3, fp, r3
        ldr     r3, [r3, #-84]
        add     r2, r2, r3
        ldr     r3, [fp, #-4]
        lsl     r3, r3, #2
        add     r3, fp, r3
        str     r2, [r3, #-124] //end else z[i]=x[i]+y[i];
        b       .L5                 
.L6:
        nop
        add     sp, fp, #0
        ldr     fp, [sp], #4
        mov     pc, lr

Please note, the comments(//) are used for understanding purpose.

Add a comment
Know the answer?
Add Answer to:
2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 variables Let R1, R2, R3 contain the starting addresses of arrays X, Y and Z r...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT