Fall 2018/19 - Lecture Notes # 8: - Unsigned Addition and Subtraction - Addition of Multiword Numbers
Fall 2018/19 - Lecture Notes # 8: - Unsigned Addition and Subtraction - Addition of Multiword Numbers
8086
Ex: Show how the flag register is affected by the following addition
MOV AL,0F5H
ADD AL,0BH
If CF=1 prior to this instruction, then after execution of this instruction, source is added to
destination plus 1. If CF=0, source is added to destination plus 0. Used widely in multibyte and
multiword additions.
Ex: Write a program to calculate the total sum of 5 bytes of data. Each byte represents the daily
wages of a worker. This person does not make more than $255 (FFH) a day. The decimal data is
as follows: 125, 235, 197, 91, and 48.
Note that these numbers are converted to hex by the assembler as follows: 125=7DH, 235=EBH, 197=C5H, 91=5BH,
48=30H.
EENG410: MICROPROCESSORS I
8086
Unsigned Addition and Subtraction
• Unsigned Addition
• Addition of individual byte data
;This program adds 5 unsigned byte numbers.
.MODEL SMALL
.STACK 64
.DATA
COUNT EQU 05
DATA DB 125,235,197,91,48
ORG 0008H
SUM DW ?
.CODE
MAIN: MOV AX, @DATA
MOV DS,AX
MOV CX,COUNT ;CX is the loop counter
MOV SI,OFFSET DATA ;SI is the data pointer
MOV AX,00 ;AX will hold the sum
BACK: ADD AL,[SI] ;add the next byte to AL
ADC AH,00 ;add 1 to AH if CF =1
INC SI ;increment data pointer
DEC CX ;decrement loop counter
JNZ BACK ;if not finished, go add next byte
MOV SUM,AX ;store sum
MOV AH,4CH
INT 21H ;go back to DOS
END MAIN
EENG410: MICROPROCESSORS I
8086
Unsigned Addition and Subtraction
• Unsigned Addition
• Addition of individual byte data
In the above program following lines of the program can be replaced with an
alternative coding as follows.
Classwork: Repeat the previous program for the addition of the five word given above.
Analysis: 548FB9963CE7H
+ 3FCD4FA23B8DH
944D08387874H
Use ADC to add the two numbers word by word. You can also use byte by byte addition.
Note: LOOP BACK ;is the equivalent of the following two instructions
DEC CX
JNZ BACK
EENG410: MICROPROCESSORS I
8086
Unsigned Addition and Subtraction
• Unsigned Addition
• Addition of multiword numbers
; This program is an example for Multiword addition
.MODEL SMALL
.STACK 64
.DATA
DATA1 DQ 548FB9963CE7H
ORG 0010H
DATA2 DQ 3FCD4FA23B8DH
ORG 00020H
DATA3 DQ (?)
.CODE
MAIN: MOV AX, @DATA
MOV DS,AX
CLC ;clear carry before the first addition
MOV SI,OFFSET DATA1 ;SI is the data pointer for operand1
MOV DI,OFFSET DATA2 ;DI is the data pointer for operand2
MOV BX,OFFSET DATA3 ;BX is the data pointer for the sum
MOV CX,04 ;CX is the loop counter
BACK: MOV AX,[SI] ;move the first operand to AX
ADC AX,[DI] ;add the second operand to AX
MOV [BX],AX ;store the sum
INC SI ;point to next word of operand1
INC SI
INC DI ;point to next word of operand2
INC DI
INC BX ;point to next word of sum
INC BX
LOOP BACK ;if not finished, continue adding
MOV AH,4CH
INT 21H ;go back to DOS
END MAIN