Basic operations such as addition and subtraction will be performed on two BCD numbers using Assembly programming.
Addition of two BCD Numbers
Aim:
To perform the addition of two BCD numbers using Assembly language for 8086 microprocessor.
Software Used:
MASM
Program Code:
CODE SEGMENT
ASSUME CS:CODE
ORG 1000H
MOV SI,1100H
MOV CL,00H
MOV AX,[SI]
MOV BX,[SI]+2
ADD AL,BL
DAA
MOV DL,AL
MOV AL,AH
ADC AL,BH
DAA
MOV DH,AL
JNC SKIP
INC CL
SKIP: MOV [SI+4],DX
MOV [SI+6],CL
HLT
CODE ENDS
END
ASSUME CS:CODE
ORG 1000H
MOV SI,1100H
MOV CL,00H
MOV AX,[SI]
MOV BX,[SI]+2
ADD AL,BL
DAA
MOV DL,AL
MOV AL,AH
ADC AL,BH
DAA
MOV DH,AL
JNC SKIP
INC CL
SKIP: MOV [SI+4],DX
MOV [SI+6],CL
HLT
CODE ENDS
END
Sample Input and Output:
Operand 1: 3378h
Operand 2: 8698h
Input | Output | ||
Address | Data | Address | Data |
3000 | 78 | 3004 | 76 |
3001 | 33 | 3005 | 20 |
3002 | 98 | 3006 | 01 |
3003 | 86 |
|
|
Result:
Sum = 2076h, Carry = 01h
Subtraction of two BCD Numbers
Aim:
To perform the subtraction of two BCD numbers using Assembly language for 8086 microprocessor.
To perform the subtraction of two BCD numbers using Assembly language for 8086 microprocessor.
Software Used:
MASM
Program Code:
CODE SEGMENT
ASSUME CS:CODE
ORG 1000H
MOV SI,1100H
MOV CL,00H
MOV AX,[SI]
MOV BX,[SI+2]
SUB AL,BL
DAS
MOV DL,AL
MOV AL,AH
SBB AL,BH
DAS
MOV DH,AL
JNC SKIP
INC CL
SKIP: MOV [SI+4],DX
MOV [SI+6],CL
HLT
CODE ENDS
END
Sample Input and Output:
Operand 1: 9572h
Operand 2: 4793h
Input | Output | ||
Address | Data | Address | Data |
3000 | 72 | 3004 | 79 |
3001 | 95 | 3005 | 47 |
3002 | 93 | 3006 | 00 |
3003 | 47 |
|
|
Result:
Difference = 4779h, Borrow = 00h
No comments:
Post a Comment