uses of registers

Programming, for all ages and all languages.
Post Reply
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

uses of registers

Post 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
Matías Beretta
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post 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)
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

thanks

Post by matias_beretta »

thanks , that is a good idea....
Matías Beretta
Post Reply