Question

3. (a) Rewrite the following C language nested for loop using ARM assembly language. Use register 10 to store index i and reg

Need help as soon as possible. Thanks!

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

Given 'C' language code is a nested for loop.

I have used the notations:

  • ( )10 to represent number in decimal system.
  • ( )16 to represent number in hexadecimal system.
  • I have used suffix 'h' after the number in code to represent the number as hexadecimal.

Below I am attaching the logic in both the 'C' language and AVR assmbly language so that your understanding would be better.

Instruction for Logic mov ro, #04h bge done1 mov r1, #12h Logic in C language code Logic in ARM assembly code It is given t

The required ARM assembly language code is:

mov Mo, #04h loop1: Cmp Mo, #0Ah bge done1 bropa: mov M,, #12h loop2: cmp M,,#osh bge donea sub r, er, #01h b loop2. donea: a

In the above code, I have used labels as follows:

  • loop1 to denote starting of main loop
  • loop2 to denote starting of nested loop
  • done1 to denote the line of code to be executed after breaking the main loop
  • done2 to denote the line of code to be executed after breaking the nested loop

Explaination of code:

  • mov r0, #04h - This instruction will load the value of (04)16 into the r0 register
  • cmp r0, #0Ah - This instruction will compare the data in r0 register with value (0A)h.
  • bge done1 - If 'greater than or equal to' condition is satisfied in above comparision then this instruction will make the code to branch (jump) to the line of code labelled as 'done1'. .
  • mov r1, #12h - This instruction will load the value of (12)16 into the r1 register
  • cmp r1, #05h - This instruction will compare the data in r1 register with value (05)h.
  • bge done2 -  If 'greater than or equal to' condition is satisfied in above comparision then this instruction will make the code to branch (jump) to the line of code labelled as 'done2'. .
  • The dotted lines are to represent any statement inside of nested for loop as given in question.
  • sub r1, r1, #01h - This instruction will substract the value of (01)16 from the r1 register and store the result in r1 register
  • b loop2 - This instruction will make the execution of code to branch (jump) unconditionally to the line of code labelled as 'loop2'
  • add r0, r0, #01h - This instruction will add the value of (01)16 to the r0 register and store the result in r0 register
  • b loop1 - This instruction will make the execution of code to branch (jump) unconditionally to the line of code labelled as 'loop1'

Add a comment
Know the answer?
Add Answer to:
Need help as soon as possible. Thanks! 3. (a) Rewrite the following C language nested for...
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