Page 1 of 1

uses of registers

Posted: Fri Sep 28, 2007 3:24 pm
by matias_beretta
well, i am doing a procedure that converts an X and Y variables to a selector:

mov ah, [Y]
mov al, 160
mul ah

I know the result is the same, but usually, the ax is used with dx to make arithmetical operations (for historical reasons, i read).

What is the correct way of writing the code to make a multiplication?

if i have to use dx , i use dh, or dl???

I know this is a little stupid, but it's helpful to make my code more readable...

thanks

Posted: Fri Sep 28, 2007 5:02 pm
by JAAman
MUL always uses eAX as input, and eDX:eAX as output

the secondary input can be any r/m value (r/m8, r/m16, r/m32, r/m64)

eDX could be used for the second input, since its dirtied for output anyway, but there is no particular reason it must be so

the only restriction, is that the 2 source operands must be the same bit-length, and the result will be 2x the bit-length of the source operands

Code: Select all


mov ah, [Y]
mov al, 160
mul ah
this should be perfectly valid -- though be aware, that AH will be corrupted by the result (as the result will be stored in AX) -- i would do it like this:

Code: Select all

MOV AL, 160
MUL [Y]
this will do exactly the same thing with 1 fewer instructions -- the only time this cannot be used would be if you needed to change the bit-length of the memory-stored value, but you arent doing this (you are loading an 8-bit value, and multiplying an 8-bit value)

thanks

Posted: Sat Sep 29, 2007 6:23 am
by matias_beretta
thanks , that is a good idea....