A
A
Alexey Nikolaev2015-12-24 09:24:31
assembler
Alexey Nikolaev, 2015-12-24 09:24:31

How to divide numbers in incomplete registers?

Good morning!
I'm trying to divide two numbers using idiv. The problem is that it works with full registers (ax, bx), while my values ​​​​are stored in half registers with the db type. If I try to divide like this, then the program freezes, and if I try to convert, huge values ​​are obtained. How to be?

; поделим a / b
; так зависает
mov al, dl
mov bl, dh
cwd
idiv bl

; так тоже зависает, а напрямую mov ax, dl нельзя
mov ah, dl
mov ah, 00
mov bh, dh
mov bh, 00
cwd
idiv bl

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2015-12-24
@jcmvbkbc

In addition to manually resetting the upper halves of 16-bit registers, there are (starting with i386) movzx and movsx instructions that move data between registers of different sizes, expanding them with zero or a sign.
Those.

mov al, dl
mov ah, 0

This
movzx ax, dl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question