x86汇编:除法浮点异常除以11

时间:2017-03-24 22:10:57

标签: assembly x86 nasm division floating-point-exceptions

我试图将public class Context { @Bean public BBB bObject(){ return new AAA(); } @Bean public CCC cObject(){ return new AAA(); } } 除以859091以获得商和余数,但我在线上获得浮点异常:

  

div bx

这是 SASM 的代码:

11

1 个答案:

答案 0 :(得分:1)

你的分数溢出是因为商不适合16位整数。

您可以将被除数分为上半部分和下半部分,以产生高达32位的商和16位的余数。 dx = 0000 : ax = upper_dividend / divisor的剩余部分成为第2分部的第2分红的上半部分,因此第2分部计算dx = remainder : ax = lower_dividend / divisor,其中任何一个都不能溢出,因为余数严格小于除数。这个过程可以延长更长的红利和商数,每个被除数和商的一个步骤,每个除数步骤的剩余部分成为下一步的部分红利的上半部分。

使用MASM语法的示例:

dvnd    dd 859091
dvsr    dw 11
;       ...
;       bx:ax will end up = quotient of dvnd/dvsr, dx = remainder
        mov     di,dvsr
        xor     dx,dx
        mov     ax,word ptr dvnd+2      ;ax = upr dvnd
        div     di                      ;ax = upr quot, dx = rmdr
        mov     bx,ax                   ;bx = upr quot
        mov     ax,word ptr dvnd        ;ax = lwr dvnd
        div     di                      ;ax = lwr quot, dx = rmdr

四字的例子:

dvnd    dq 0123456789abcdefh
dvsr    dw 012h
quot    dq 0
rmdr    dw 0
;       ...
        mov     di,dvsr
        xor     dx,dx                   ;dx = 1st upr half dvnd = 0

        mov     ax,word ptr dvnd+6      ;ax = 1st lwr half dvnd
        div     di                      ;ax = 1st quot, dx = rmdr = 2nd upr half dvnd
        mov     word ptr quot+6,ax

        mov     ax,word ptr dvnd+4      ;ax = 2nd lwr half dvnd
        div     di                      ;ax = 2nd quot, dx = rmdr = 3rd upr half dvnd
        mov     word ptr quot+4,ax

        mov     ax,word ptr dvnd+2      ;ax = 3rd lwr half dvnd
        div     di                      ;ax = 3rd quot, dx = rmdr = 4th upr half dvnd
        mov     word ptr quot+2,ax

        mov     ax,word ptr dvnd        ;ax = 4th lwr half dvnd
        div     di                      ;ax = 4th quot, dx = rmdr
        mov     word ptr quot,ax

        mov     rmdr,dx