; 16 BIT ADDITION
ORG 0000H ;
; SAY R7 HAS LOWER BYTE 34
; R6 HAS HIGHER BYTE 24
; MAKING NUMBER 2434
MOV R7, #34H ;
MOV R6, #24H ;
; ANOTHER NUMBER SAY 3345
; WITH R5 LOWER BYTE 45
; R4 HIGHER BYTE 33
MOV R5,#45H ;
MOV R4, #33H ;
; NOW ADDING
MOV A, R5 ;
; ADDING LOWER BYTE
ADD A , R7 ;
MOV R3, A ;
; R3 BEING LOWER BYTE OF ANSWER
MOV A, R6 ;
; NOW ADD WITH CARRY
ADDC A, R4 ;
MOV R2,A ;
END
ORG 0000H ;
; SAY R7 HAS LOWER BYTE 34
; R6 HAS HIGHER BYTE 24
; MAKING NUMBER 2434
MOV R7, #34H ;
MOV R6, #24H ;
; ANOTHER NUMBER SAY 3345
; WITH R5 LOWER BYTE 45
; R4 HIGHER BYTE 33
MOV R5,#45H ;
MOV R4, #33H ;
; NOW ADDING
MOV A, R5 ;
; ADDING LOWER BYTE
ADD A , R7 ;
MOV R3, A ;
; R3 BEING LOWER BYTE OF ANSWER
MOV A, R6 ;
; NOW ADD WITH CARRY
ADDC A, R4 ;
MOV R2,A ;
END
How we get the carry bit!!
ReplyDeletein this example we'll not get a carry as these are simple hexadecimals. the carry will be generated if you have the lower bytes like AB, BC etc. It'll get stored in carry flag and when the next higher byte is added with ADDC instruction, that carry will be added automatically.
DeleteOo
Deletethat's right, but how to do addition of n-16 bit nos.?? it should be done during runtime
ReplyDeleteUse HL and DE pair register and a loop to pull data into HL and DE and then add them the same way shown here. After addition you need to put the data back into some other address for storage.
DeletePlease give flow chart of execution
ReplyDelete