Jump to content
Sign in to follow this  
cenorasped

Divisão assembly

Recommended Posts

cenorasped

pessoal alguém me consegue explicar porque o código seguinte dá Divide overflow ???

Processador: 8086

mov ax, 10h
mov cx, 2h
div cx

Obrigado!

Edited by cenorasped

Share this post


Link to post
Share on other sites
KTachyon

Limpa o registo DX antes de fazer a divisão.

mov ax, 10h
xor dx, dx             ; ou mov dx, 0
mov cx, 2h
div cx

Explicação:

Citação
DIV performs unsigned integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:

For DIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.

For DIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.

For DIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.

http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoca.html

Traduzindo: Se estás a utilizar registos de 16 ou 32 bits, o numerador é DX:AX. Ou seja:

(DX:AX)/CX

  • Vote 2

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.