汇编程序8086将32位数字除以16位数字 [英] Assembler 8086 divide 32 bit number in 16 bit number

查看:810
本文介绍了汇编程序8086将32位数字除以16位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将32位数字除以16位数字。
例如10000000h除以2000h。根据设计目的,我尝试将
用除数除以右4个数字,然后除以除数4。

I try to divide 32 bit number in 16 bit number. For example 10000000h divide by 2000h.According the desgin I try to do I divide 4 right digits with the divisor and then the 4 left digit by the divisor.

这是我的代码:

.DATA 
num dd 10000000h
divisor dw 2000h 

result dd ? 
remainder dw ? 

.CODE
main:

mov ax,@DATA    
mov ds,ax 

xor dx,dx
mov cx ,word ptr divisor
mov bx,offset num
mov ax,[bx]
div cx

mov bx,offset result 
mov [bx],ax 
mov bx,offset num
mov ax,[bx+2]


mov ax,[bx+2]
div cx 
mov bx,offset result 
mov [bx+2],ax 

我的可变结果为零。不知道分隔设计是否有问题或只是一个小错误。

I got zero in variable result. Not sure if the problem with the design of the divide or just a little mistake.

推荐答案

下面的方法类似于长手用铅笔和纸进行除法,将2位分子除以一位除数。例如99/4:

The method below is similar to long hand division on pencil and paper, dividing a 2 digit numerator by a single digit divisor. For example 99/4:

    2 4    (quotient)
  -----
4 | 9 9
    8
    -
    1 9
    1 6
      -
      3    (remainder)

从dx = 0和ax =分子的高阶开始。在第一个div指令之后,dx中的余数是第二个除法的分子高阶的剩余部分。只要除数是16位值,就可以增强此方法以处理任何大小的分子和商。

Start off with dx = 0 and ax = high order of numerator. After the first div instruction, the remainder in dx is what's left of the high order of the numerator for the second divide. This method could be enhanced to handle a numerator and quotient of any size, as long as the divisor is a 16 bit value.

num     dd      10000000h
dvsr    dw      2000h 
quot    dd      ?
rmdr    dw      ?
;       ...
        mov     cx,dvsr                ;cx = dvsr
        xor     dx,dx                  ;dx = 0
        mov     ax,word ptr [num+2]    ;ax = high order numerator
        div     cx                     ;dx = rem, ax = high order quotient
        mov     word ptr [quot+2],ax   ;store high order quotient
        mov     ax,word ptr [num]      ;ax = low  order numerator
        div     cx                     ;dx = rem, ax = low  order quotient
        mov     word ptr [quot],ax     ;store low  order quotient
        mov     word ptr [rmdr],dx     ;store remainder

这篇关于汇编程序8086将32位数字除以16位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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