x86 - How can I add two 16 bit numbers in assembly language in microprocessor 8086 -


hey using window 7 x86. want add 2 16 bit numbers.

when add 3+3 answer correct when add 7+7 it's not working. , want add 2 numbers 75+75 answer should 150.

what procedure please tell me. thanx in advance

.model small .stack 100h .data num db 9 dup(0) result dw 9 dup (0) .code main proc mov ax,@data mov ds,ax  mov ah, 1 int 21h    ; input user mov num, al    ; store in array   int 21h              ;get 2nd number user mov num+1, al        ;store in array @ num[1] index  mov al, num          ;mov number al add dl, num+1        ;add num[1] in num in dl  sub dl, 48           ; subract assci become number 0 ~ 9  mov ah, 2            ; output int 21h  mov ah, 4ch int 21h main endp end main 

here code add 2 16-bit numbers on 8086:

.model small .data db "enter first number$" b db "enter second number$" c db "the sum is: $" d db 00h  .code start: mov ax,@data mov ds,ax mov dx,offset mov ah,09h int 21h  mov ah,01h int 21h mov bh,al mov ah,01h int 21h mov bl,al  mov dx,offset b mov ah,09h int 21h mov ah,01h int 21h mov ch,al mov ah,01h int 21h   mov cl,al add al,bl mov ah,00h aaa add bh,ah add bh,ch mov d,al mov al,bh mov ah,00h aaa mov bx,ax add bx,3030h  mov dx,offset c mov ah,09h int 21h  mov dl,bh mov ah,02h int 21h mov dl,bl mov ah,02h int 21h mov dl,d add dl,30h mov ah,02h int 21h end start 

the trick here lies in using 'aaa' command unpack digits.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -