Arithmetic Instructions: BCD Number System
Arithmetic Instructions: BCD Number System
ARITHMETIC
INSTRUCTIONS
1 BCD Number
System
AT THE END OF SESSION, WE WILL BE
ABLE
Understand BCD numbers
BCD Addition and DA instruction
Abdullah Gubbi
Subtraction
Multiplication
Division
Signed Arithmetic
2
Abdullah Gubbi
3
Abdullah Gubbi
4
Abdullah Gubbi
5
Abdullah Gubbi
6
ASSUME THAT 5 BCD DATA ITEMS ARE STORED IN
RAM LOCATIONS STARTING AT 40H, AS SHOWN
BELOW. WRITE A PROGRAM TO FIND THE SUM OF
ALL THE NUMBERS. THE RESULT MUST BE IN BCD.
40=(71), ,41=(11), 42=(65), 43=(59),44=(37)
MOV R0,#40H ; Load pointer
Abdullah Gubbi
MOV R2,#5 ; Load counter
CLR A ; A=0
MOV R7,A ; Clear R7
AGAIN: ADD A,@R0 ; add the byte pointer to by R0
DA A ; adjust for BCD
JNC NEXT ; if CY=0 don’t accumulate carry
INC R7 ; keep track of carries
NEXT: INC R0 ; increment pointer
DJNZ R2,AGAIN ; repeat until R2 is 0
7
Abdullah Gubbi
8
Abdullah Gubbi
9
Abdullah Gubbi
10
Abdullah Gubbi
11
Abdullah Gubbi
12
ARITHMETIC INSTRUCTIONS
APPLICATION FOR DIV
Write a program to get hex data in the range of 00 –
FFH from port 1 and convert it to decimal. Save it in
R7, R6 and R5.
Abdullah Gubbi
MOV A,#0FFH
MOV P1,A ; make P1 an input port
MOV A,P1 ; read data from P1
MOV B,#10 ; B=0A hex
DIV AB ; divide by 10
MOV R7,B ; save lower digit
MOV B,#10
DIV AB ; divide by 10 once more
MOV R6,B ; save the next digit 13
MOV R5,A ; save the last digit
ASSUMING THAT P1 HAS A VALUE OF
FDH FOR DATA, ANALYZE PROGRAM.
To convert a binary (hex) value to decimal, we divide it
by 10 repeatedly until the quotient is less than 10.
After each division the remainder is saves.
Abdullah Gubbi
• Q R
FD/0A = 19 3 (low digit)
19/0A = 2 5 (middle digit)
2 (high digit)
Therefore, we have FDH=253.
14
Abdullah Gubbi
15
Abdullah Gubbi
16
Abdullah Gubbi
17
Abdullah Gubbi
18
Abdullah Gubbi
19
Abdullah Gubbi
20