Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

;A program to compute the sum, difference, ;and absolute difference of two signe

ID: 2085801 • Letter: #

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

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 instruction·BL 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 subroutine

Explanation / Answer

8086 Assembly Language Program to add two 32-bit signed & unsigned number


code:

MOV AX,5000H ; Initialize DATA SEGMENT
MOV DS,AX ; to 5000H
MOV AX,[1000H] ; take lower 16-bit of NUM1 in AX
MOV BX,[2000H] ; take lower 16-bit of NUM2 in BX
ADD AX,BX ; AX = AX + BX
MOV [3000H],AX ; Store lower 16-bit result at NUM3
MOV AX,[1002H] ; take higher 16-bit of NUM1 in AX
MOV BX,[2002H] ; take higher 16-bit of NUM2 in BX
ADC AX,BX ; AX = AX + BX + CF (add with carry)
MOV [3002H],AX ; Store higher 16-bit result at NUM3
HLT ; Halt 8086

data segment
abc dd 9ABCDEF0h
def dd 12345678h
ghi dw ?
data ends

code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov dl,00h
mov ax, word ptr abc
mov bx, word ptr def
sub ax,bx
mov word ptr ghi,ax
mov ax, word ptr abc+2
mov bx, word ptr def+2
sbb ax,bx
mov word ptr ghi+2,ax
jnc move
inc dl
move: mov byte ptr ghi+4,dl
int 3
code ends
end start
output:-
C:TASM>masm an32sub.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.

Object filename [an32sub.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:

50288 + 450368 Bytes symbol space free

      0 Warning Errors
      0 Severe Errors

C:TASM>link an32sub.obj

Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.

Run File [AN32SUB.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment

C:TASM>debug an32sub.exe
-g

AX=8888 BX=1234 CX=0038 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0B97 ES=0B87 SS=0B97 CS=0B98 IP=0027   NV UP EI NG NZ NA PE NC
0B98:0027 CC            INT     3
-d 0B97:0000

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote