Search This Blog

Monday, August 8, 2011

Assembly program for Simple 2 16bit number addition using registers

; 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

4 comments:

  1. Replies
    1. in 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.

      Delete
  2. that's right, but how to do addition of n-16 bit nos.?? it should be done during runtime

    ReplyDelete
    Replies
    1. Use 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.

      Delete