# Divisão assembly

## Recommended Posts

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

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

Edited by cenorasped
##### Share on other sites

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.

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

`(DX:AX)/CX`

`“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

## Create an account

Register a new account

×

• #### Revista PROGRAMAR

• Wiki
• IRC
×
• Create New...