Question

Find out what the following assembly code calculates AREA my code, CODE EXPORT main ALIGN ENTRY main PROC MOVS MOVS MOVS r0,#0 r1,#15 r2,#0 loop CMP BGT MLA ADDS r2,r1 stop re,r2,r2,ro r2,r2,#1 loop % The final result is saved in register r0 stop B stop ENDP END

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

Program calculates sum of squares of numbers from 0-15.

  • __main: Deals with three registers, r0 to save total sum, r1 to act as loop counter, r2 to save numbers from 0-15
  • Loop: loop compares r2 and r1 so that loop executes only till r2 value is less than equal to 15. BGT instruction is executed when this value is greater than 15 and it stops the loop. MLA instruction is used for Multiply-accumulate, its syntax is as below:

MLA         Rd, Rn, Rm, Ra

Rd is destination register

Rn, Rm registers holding the values to be multiplied.

Ra register holding the value to be added.

Thus its equivalent to Rd = (Rn*Rm) + Ra

Heere Rn and Rm both are r2 thus square of the value stored in r2 and adding this value to the sum stored in r0. After this it increments the value in r2 by one and loop executes again for next value calculating square and adding to the sum.

  • Stop: End of the program

If this helps please give a thumbs up. Good Luck!!

Add a comment
Know the answer?
Add Answer to:
Find out what the following assembly code calculates AREA my code, CODE EXPORT main ALIGN ENTRY...
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
  • 13) (4 pts) Squaring a number is useful in many other algorithms. This assembly routine calculates...

    13) (4 pts) Squaring a number is useful in many other algorithms. This assembly routine calculates the square of an unsigned integer. How long does this take in clock cycles (worst case). Assume ARM 32 bit instruction set and the integer is in R0 before we begin. AREA L.textl, CODE, READONLY PROC EXPORT square square MOV R1,RO; CMP R1, #0 ANDS R3,RO,R1 BNE skip ADD RO,R1, LSL R3; MOV R2,R2, LSL #1 CMP R2, #0 BNE loop BX LR loop...

  • 6 (10 points) What are incorrect in the following assembly program? 1 AREA myCode, CODE EXPORT...

    6 (10 points) What are incorrect in the following assembly program? 1 AREA myCode, CODE EXPORT main main PROC 4 PROC sum 5 6 ENDP 7 8 ENDP 9 END 10 AREA myData, DATA myStr DCB "mid term" DCD 1,2,3,4,5 11 12 13 Please point out the line number of the incorrect code and give correct ones. 23 6 (10 points) What are incorrect in the following assembly program? 1 AREA myCode, CODE EXPORT main main PROC 4 PROC sum...

  • This code needs to be written in Assembly language using Keil uvision 5. Please use Keil...

    This code needs to be written in Assembly language using Keil uvision 5. Please use Keil Assembler. Or ARM assembly. Thanks. int main(void) { // initializing int R0 = 5; int R1 = 10; // for loop addition with CMP while(RO <=| 10) R$++; // for loop subtraction without CMP#10 while(R1 > 0) R1--; // if else statement if (RO > 0) R0 = 10; R1 = 10; else | R0 = 20; R1 = 30; // must using branching...

  • 6 (10 points) What are incorrect in the following assembly program? 1 AREA myCode, CODE EXPORT...

    6 (10 points) What are incorrect in the following assembly program? 1 AREA myCode, CODE EXPORT main main PROC 4 PROC sum 5 6 ENDP 7 8 ENDP 9 END 10 AREA myData, DATA myStr DCB "mid term" DCD 1,2,3,4,5 11 12 13 Please point out the line number of the incorrect code and give correct ones. 23

  • AREA .text, CODE, READONLY, ALIGN=2 GET tm4c123gh6pm. 3 EXPORT Start OOC Jan WN PP Start MOV...

    AREA .text, CODE, READONLY, ALIGN=2 GET tm4c123gh6pm. 3 EXPORT Start OOC Jan WN PP Start MOV RO, #0x80; MOV Ri, #Ox1; BL Logic B Stop 12 Stop 13 14 Logic 25 ORR R2, RO, R1; BX LR After executing instruction in Line 14, the value of R14 is: the address of instruction in Line 10 the address of instruction in Line 12 the address of instruction in Line 14 the address of instruction in Line 15

  • Problem 1 Consider the piece of ARM Cortex MO+ assembly code given below and answer the...

    Problem 1 Consider the piece of ARM Cortex MO+ assembly code given below and answer the following questions: mw 1.AGAIN CMP RO, #10 BLE LESSEQUAL MOVS RO, #0 B DONE LESSEQUAL ADDS RO, RO, R1 B AGAIN 5. DONE 1. Assume RO is initialized with the value 20, what is the value of RO when the code above completes execution? How many times is Instruction 5 executed? Assume RO is initialized with the value o, and R1 with the value...

  • X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code...

    X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code INCLUDE Irvine32.inc         .data       KeyPrompt BYTE "Enter the passphrase: ",0       TextPrompt BYTE "Enter the plaintest: ",0           str1 BYTE "The passphrase has length:",0           str2 BYTE "The plaintest has length:",0       KeyIs BYTE "The passphrase: ",0       PlainTextIs BYTE "The plaintext: ",0       CipherTextIs BYTE "The ciphertext: ",0       KMAX = 64                        ; passphrase buffer maximum size       BMAX = 128                       ; test...

  • Implement the following statements using MS430 assembly instructions. You may use more than one, ...

    Implement the following statements using MS430 assembly instructions. You may use more than one, but you should minimize the number of instructions required. You can use both native and emulated instructions. Use hex notation for all numbers 1. (a) Move the word located in register R14 to R15 (b) Increment the word in R6 by 2. (c) Perform a bitwise ANDing of the word located at address 0x0240 with the datum in R15, placing the results in R15. (d) Rotate...

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