Saturday, September 12, 2009

Sub routine to perform the task of DAA(8085)


Statement:Assume the DAA instruction is not present. Write a sub routine which will perform the same task as DAA.

Sample Problem:
Execution of DAA instruction:
1. If the value of the low order four bits (03-00) in the accumulator is greater than 9 or if auxiliary carry flag is set, the instruction adds 6 '(06) to the low-order four bits.
2. If the value of the high-order four bits (07-04) in the accumulator is greater than 9 or if carry flag is set, the instruction adds 6(06) to the high-order four bits.

Source Program:
LXI SP, 27FFH : Initialize stack pointer
MOV E, A : Store the contents of accumulator
ANI 0FH : Mask upper nibble
CPI 0A H : Check if number is greater than 9
JC SKIP : if no go to skip
MOV A, E : Get the number
ADI 06H : Add 6 in the number
JMP SECOND : Go for second check
SKIP: PUSH PSW : Store accumulator and flag contents in stack
POP B : Get the contents of accumulator in B register and flag register contents in C register
MOV A, C : Get flag register contents in accumulator
ANI 10H : Check for bit 4
JZ SECOND : if zero, go for second check
MOV A, E : Get the number
ADI 06 : Add 6 in the number
SECOND: MOV E, A : Store the contents of accumulator
ANI FOH : Mask lower nibble
RRC
RRC
RRC
RRC : Rotate number 4 bit right
CPI 0AH : Check if number is greater than 9
JC SKIPl : if no go to skip 1
MOV A, E : Get the number
ADI 60 H : Add 60 H in the number
JMP LAST : Go to last
SKIP1: JNC LAST : if carry flag = 0 go to last
MOV A, E : Get the number
ADI 60 H : Add 60 H in the number
LAST: HLT

No comments:

Post a Comment