manipulating 32 bit numbers with 16 bit registers in 8086

五迷三道 提交于 2020-12-25 04:00:57

问题


Im trying to write a program which get two 6-digit decimal numbers and show the addition of them, but in 16 bit 8086 i defined numbers as double word and put LO in WORD 1 and HO in word 2. similar to below code but i dont have any idea to do next, can any body suggest me algorithm for next operations? Thnx

x dd(?)
    next_no:
    mov cl,2
    mov ch,4

two_bit:
getch

sub al,30h
mov bl,10
mul bl
mov di,ax
add word ptr x+2,di

dec cl
jnz two_bit
fourbit:
getch
sub al,30h
mov bl,10
mul bl
mov di,ax
add word ptr x,di
dec ch
jnz fourbit

in this program di is a place to storing the number made through the loop when user enter a number di will multiple to 10 and the new digit will add to di like: proccess of getting 28 di=0*10+2=2 di=2*10*+8=28


回答1:


Rather than follow your uncommented code, I'll present an independent example.

Suppose you have one 32-bit number in DX:AX and one 32-bit number in CX:BX (this notation means that the high 16 bites are stored in DX for example, and the low 16 bits in AX). To add these values and leave the result in DX:AX, you would:

    add ax,bx
    adc dx,cx

The add instruction adds the two values and sets the C (carry) bit to 1 or 0 depending on whether there was a carry or not. The adc instruction adds the two values plus the value of the carry bit (and then sets the carry bit again). In this way, you can add values of any size by continuing with more adc instructions.



来源:https://stackoverflow.com/questions/8352704/manipulating-32-bit-numbers-with-16-bit-registers-in-8086

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!