Question
;A program to compute the sum, difference, ;and absolute difference of two signed ;32-bit numbers. ;------Assembler Directives---------------- THUMB ; uses Thumb instructions ; Data Variables
;A program to compute the sum, difference,
;and absolute difference of two signed
;32-bit numbers.
;------Assembler Directives----------------
THUMB ; uses Thumb instructions
; Data Variables
AREA DATA, ALIGN=2 ; places objects in data memory (RAM)
EXPORT SUM [DATA,SIZE=4] ; export public varialbe "SUM" for use elsewhere
EXPORT DIFF [DATA,SIZE=4] ; export public varialbe "DIFF" for use elsewhere
EXPORT ABS [DATA,SIZE=4] ; export public varialbe "ABS" for use elsewhere
SUM SPACE 4 ; allocates 4 uninitialized bytes in RAM for SUM
DIFF SPACE 4 ; allocates 4 uninitialized bytes in RAM for DIFF
ABS SPACE 4 ; allocates 4 uninitialized bytes in RAM for ABS
; Code
AREA |.text|, CODE, READONLY, ALIGN=2 ; code in flash ROM
EXPORT Start ; export public function "start" for use elsewhere
NUM1 DCD -1 ; 32-bit constant data NUM1 = -1
NUM2 DCD 2 ; 32-bit constant data NUM2 = 2
;-------End of Assembler Directives----------
GET_SUM ; subroutine GET_SUM
ADD R0, R1, R2 ; R0=R1+R2
LDR R3, =SUM ; R3=&SUM, R3 points to SUM
STR R0, [R3] ; store the sum of NUM1 and NUM2 to SUM
BX LR ; subroutine return
GET_DIFF ; subroutine GET_DIFF
SUBS R0, R1, R2 ; R0=R1-R2
LDR R3, =DIFF ; R3=&DIFF, R3 points to DIFF
STR R0, [R3] ; store the different of NUM1 and NUM2 to DIFF
BMI GET_ABS ; check condition code, if N=1 (i.e. the difference is negative),
; branch to GET_ABS to calculate the absolute difference
STR_ABS ; label STR_ABS, store the absolute difference
LDR R3, =ABS ; R3=&ABS, R3 points to ABS
STR R0, [R3] ; store the absolute difference to ABS
BX LR ; subroutine return
GET_ABS ; label GET_ABS, calculate the absolute difference if the difference is negative
RSB R0, R0, #0 ; R0=0-R0;
B STR_ABS ; branch to STR_ABS to store the result
Start LDR R1, NUM1 ; R1=NUM1
LDR R2, NUM2 ; R2=NUM2
BL GET_SUM
BL GET_DIFF
ALIGN ; make sure the end of this section is aligned
END ; end of file
Questions 1. Create a table as shown below to record the values of important registers and variables when the Steps PCLRNZCV RO 2. What are the addresses of variables SUM, DIFF, and ABS? What values are stored at these addresses when the simulation is completed? 3. In this program, consider the following items including SUM, DIFF, ABS, NUM1, NUM2, and all the instructions, which are stored in RAM and which are stored in ROM? ENGR 478 4. What is the address of instructionBL GET. SUMin memory? What does this instruction do? After executing this instruction, what are the values stored in PC and LR? Why? 5. What does the instruction "BI GET_ABS" do? 6. After executing "SUBS R0, R1, R2", what are the values of the condition code flags? Why? 7. Edit sins, modify NUM1 and NUM2 to be 5 and 3 respectively and simulate the program again. What are the values stored in SUM, DIFF, and ABS after the simulation? 8. Add a new function to the sample program which compares the values of NUMI and NUM2 and stores the larger value into a new variable LARGER. You need to a. Define a new 32-bit variable LARGER b. Design a subroutine GET LARGER, draw the flowchart of the subroutine, and write assembly code to implement this subroutineStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started