Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer Overflow problem

Tags:

x86

assembly

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   
like image 516
user700176 Avatar asked Apr 09 '11 18:04

user700176


1 Answers

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

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
like image 103
Jerry Coffin Avatar answered Sep 23 '22 20:09

Jerry Coffin