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
uses of registers
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
uses of registers
MatÃas Beretta
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
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:
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)
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
Code: Select all
MOV AL, 160
MUL [Y]
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm