在 8086 中使用 16 位寄存器操作 32 位数字 [英] manipulating 32 bit numbers with 16 bit registers in 8086

查看:59
本文介绍了在 8086 中使用 16 位寄存器操作 32 位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来获取两个 6 位十进制数并显示它们的相加,但是在 16 位 8086我将数字定义为双字并将 LO 放在字 1 中,将 HO 放在字 2 中.类似于下面的代码但我不知道接下来要做什么,有人可以建议我下一步操作的算法吗?谢谢

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

在这个程序中di 是存储通过循环产生的数字的地方当用户输入数字时di 将乘以 10,新的数字将添加到 di喜欢:获得28的过程di=0*10+2=2di=2*10*+8=28

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

推荐答案

我将提供一个独立的示例,而不是遵循您未注释的代码.

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

假设您在 DX:AX 中有一个 32 位数字,在 CX:BX 中有一个 32 位数字(这种表示法意味着高 16 位存储在 DX 中,而低 16 位存储在 AX 中).要添加这些值并将结果保留在 DX:AX 中,您将:

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

add 指令将两个值相加并设置 C(进位)位为 1 或 0,具体取决于是否有进位.adc 指令将两个值相加加上进位位的值(然后再次设置进位位).通过这种方式,您可以通过继续执行更多的 adc 指令来添加任意大小的值.

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.

这篇关于在 8086 中使用 16 位寄存器操作 32 位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆