Program to add two BCD numbers


21. Program to add two BCD numbers :

mov dptr,#9000h ;move dptr with 9000h
movx a,@dptr ; move data from external memory location to a
mov b,a ;move data from a to b
inc dptr ;increment dptr
movx a,@dptr ; move data from external memory location to a
add a,b ;add a and b
da a ;decimal adjust accumulator after addition
jc down ;if carry, jump to label down
inc dptr ;increment dptr
movx @dptr,a ;move data from a to external memory location
sjmp last ;jump to label last
down:mov r2,a ;move data from a to r2
mov a,#01h ;move data 01h to a
movx @dptr,a ;move data from a to external memory location
inc dptr ;increment dptr
mov a,r2 ;move data from r2 to a
movx @dptr,a ;move data from external memory location to a
last:sjmp last
end


Web Statistics