整数溢出问题 [英] Integer Overflow problem

查看:89
本文介绍了整数溢出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直遇到整数溢出问题,我不知道如何解决它,任何人都可以帮忙吗? edx conatins 181和eax包含174

I keep getting a integer overflow problem and i have no idea how to solve it can anyone help? edx conatins 181 and eax contains 174

       xor eax,edx       
       mov edx,2
       div edx   

推荐答案

假设您在谈论x86,div edx并没有任何意义-32位div将edx:eax除以指定的目标寄存器.幸运的是,要除以2,您根本不需要使用div.

Assuming you're talking about x86, div edx doesn't really make sense -- a 32-bit div divides edx:eax by the specified target register. Fortunately, to divide by 2, you don't really need to use div at all.

mov eax, 174
mov edx, 181

xor eax, edx
shr eax, 1

如果出于某些原因确实坚持使用div,则需要使用其他寄存器.请注意,x86期望除法结果适合一个寄存器,因此除法前,您需要将edx设为零:

If you do insist on using a div for some reason, you want to use a different register. Note that the x86 expects the result of the division to fit in one register, so you'll need to zero edx before the division:

mov eax, 174
mov edx, 181

xor eax, edx
xor edx, edx
mov ebx, 2
div ebx

这篇关于整数溢出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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