Question

Write an ARM assembly language program to translate the following sequence of statements . Assume x...

Write an ARM assembly language program to translate the following sequence of statements . Assume x and y are memory locations that store two unsigned integers. Use the following: x is in R1, y is in R2, and z in R3. Make sure that your program works for any value of x and y.

if (x > 15)

{

    x = 1;

    if (y > 15) {

         y = 2;

        }

else {

      y = y + 2;

     }

}

else {

     x = x + 1;

     }

z = x + y;

I have solution but not sure! and it is not completed yet! (the solution should be something like that)

.global main

.func main

.text

.data

X :      .word

Y :

Z :

Main :

         Ldr r1, =x

         Ldr r1, [r1]

         Ldr r2, = y

         Ldr r2, [r2]

         Ldr r3, =z

         Ldr r3, [r3]

         Cmp r1, #15

         Ble falseBlock

         Mov r1, #2

else:

         add r1, r1, #1

         b end

         add r3, r1, r2

end :

         bx lr

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

main:
; storing the values
   MOV   %rsp, %rbp
   SUB   $48, %rsp
   CALL   __main
   CMP   $15, -4(%rbp)
   J   Loop2
;moving the values
   MOV   $1, -4(%rbp)
   CMP   $15, -8(%rbp)
;checkgin the condition
   jle   Loop3
   MOV   $2, -8(%rbp)
   JMP   Loop4
Loop3:
;going for the annother condition
   ADD   $2, -8(%rbp)
   jmp   Loop4
Loop2:
;going for the else condition
   ADD   $1, -4(%rbp)
Loop4:
; ending the last loop by finalizing the result
   MOV   -4(%rbp), %edx
   MOV   -8(%rbp), %eax
   MOV   %edx, %eax
   MOV   %eax, -12(%rbp)
   MOV   $0, %eax
   ADD   $48, %rsp
ENDP
END

Add a comment
Know the answer?
Add Answer to:
Write an ARM assembly language program to translate the following sequence of statements . Assume x...
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