Program to add two multibyte numbers
8051 MICROCONTROLLER
Programs:
1.Program to add two multibyte numbers using 8051 .
mov r4,#0h ;move 00 to r4
mov r3,#0h ;move 00 to r3
mov dptr,#9000h ; Load 9000h into dptr register
movx a,@dptr ;move the data from memory location to a register
mov r0,a ;move the data from a to r0
inc dptr ;increment dptr
movx a,@dptr ;move the data from memory location to a
movx a,@dptr ;move the data from memory location to a
mov r1,a ;move the data from a register to r1
inc dptr ;increment dptr
movx a,@dptr ;move the data from memory to a
mov r2,a ;move the data form a to r2
inc dptr ;increment dptr
movx a,@dptr ; move the data from memory location to a register
clr c ;clear carry bit
add a,r1 ;add a and r1
jnc res ;if no carry, jump to label res
mov r3,a ;move data from a to r3
mov a,r0 ;move data from r0 to a
addc a,r2 ; add with carry and r2
jnc end1 ;if no carry, jump to label end1
inc r4 ;increment r4
ajmp end1 ;jump to label end1
res:mov r3,a ; move data from a to r3
mov a,r0 ; move data from r0 to a
add a,r2 ;add a and r2
jnc end1 ; if no carry, jump to label end1
inc r4 ;increment r4
end1:mov r5,a ;move data from a to r5
mov dptr,#900ah ;load 9000h into dptr register
mov a,r4 ; move data from r4 to a
movx @dptr,a ;move data from a to memory location
mov a,r5 ;move data from r5 to a
inc dptr ;increment dptr
movx @dptr,a ; move data from a to memory location
mov a,r3 ; move data from r3 to a
inc dptr ; increment dptr
movx @dptr,a ; move data from a to memory location
here:sjmp here
end
Input Location:9000h,9001h,9002h,9003h
Output Location:900ah
Input Data: 1111 1111(hex)
Output : 2222h
2 nd method
mov r1,#0ffh ;load r1 with immediate data
mov r2,#0ffh ; load r1 with immediate data
mov r3,#0ffh ;load r1 with immediate data
mov r4,#0ffh ;load r1 with immediate data
clr c ;Clear carry bit
mov a,r1 ;move data from r1 to a
add a,r4 ;add a and r4
mov 31h,a ;move data from a to internal RAM location 31h
mov a,r2 ;move data from r2 to a
addc a,r3 ;add with carry a and r3
mov 32h,a ; move data from a to internal RAM location 32h
mov a,#00 ;Clear a register
addc a,#00 ;add with carry and 0
mov 33h,a ; move data from a to internal RAM location 33h
here:sjmp here
end