Question

I am trying to track the EAX register through each snippet of the code in a MASM32 program. I need help with explaining why it is the value it is. This is what I have:

.DATA
 alfa BYTE 96h

.CODE
 start:

 MOV EAX,0  ; move 0 to eax 
 MOV AL,alfa ; move 96h to AL, this says the value of eax is now positive 150
 MOVZX EAX,alfa ; still says EAX is 96h and value is  positive 150
 MOVSX EAX,alfa  ; says value is negative 106 and eax register is FFFFFF96

 call DumpRegs
 call WriteInt
exit
END start

I am using DumpRegs to display the registers and WriteInt to print the value of EAX. I have some questions:

  1. When MOV AL, alfa, it moves alfa into the EAX register, isn't AL an 8-bit register? why does it do this? Why does WriteInt say that the value is +150?
  2. What do MOVZX and MOVSX do?
  3. What does MOVZX EAX, alfa do? None of the values had changed?
  4. MOVSX EAX, alfa, why is it -106 and the EAX register FFFFFF96? Is it because it is negative?
Was it helpful?

Solution

You initialze eax to 0 so the value is 0

mov eax, 0
EAX-----
    AX--
    AHAL
00000000

mov al, 96h

EAX-----
    AX--
    AHAL
00000096

The remainder of the register doesn't change when AL is adressed, so it stays the same.

To illustrate this:

mov eax, -1
EAX-----
    AX--
    AHAL
ffffffff

mov al, 96h

EAX-----
    AX--
    AHAL
ffffff96

movesx loads the value with sign extension. Since 096h is a negative (highest bit is set) it will extend the sign to the whole 32 bit register.

movzx doe not sign extend and clears the bits.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top