x86 Assembly:除法浮点异常除以11

编程入门 行业动态 更新时间:2024-10-07 22:28:42
本文介绍了x86 Assembly:除法浮点异常除以11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将859091除以11以获得商和余数,但是我在网上遇到了浮点异常:

I'm trying to divide 859091 by 11 to obtain the quotient and the remainder, but I'm getting Floating Point Exception on line:

div bx

这是我的 SASM 代码:

%include "io.inc" section .data dividend dd 859091 divisor dw 11 section .text global CMAIN CMAIN: push ebp mov ebp, esp xor eax, eax xor ebx, ebx xor edx, edx mov ax, word [dividend] mov dx, word [dividend + 2] mov bx, word [divisor] test bx, bx jz exit div bx exit: leave ret

推荐答案

由于商不适合16位整数,因此您将获得除法溢出.

You're getting divide overflow because the quotient doesn't fit within a 16 bit integer.

您可以将红利分成上半部分和下半部分,以产生最多32位的商和16位的余数. dx = 0000 : ax = upper_dividend / divisor的余数成为第二除法的第二个红利的上半部分,因此第二个除法计算dx = remainder : ax = lower_dividend / divisor,这两个均不能溢出,因为余数严格小于除数.此过程可以扩展为更长的股息和商,每个单词和商数一个步骤,而每个除法步骤的其余部分将成为下一步部分股息的上半部分.

You can split up the dividend into upper and lower halves to produce up to a 32 bit quotient and 16 bit remainder. The remainder of dx = 0000 : ax = upper_dividend / divisor becomes the upper half of 2nd dividend for the 2nd division, so the 2nd division calculates dx = remainder : ax = lower_dividend / divisor, neither of which can't overflow because the remainder is strictly less than the divisor. This process can be extended for longer dividends and quotients, one step per word of dividend and quotient, with the remainder of each divide step becoming the upper half of the partial dividend for the next step.

使用MASM语法的示例:

Example using MASM syntax:

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

更多推荐

x86 Assembly:除法浮点异常除以11

本文发布于:2023-11-29 09:09:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:除法   浮点   异常   Assembly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!