0

the orginally is

mov ax, 0FFFFh; <--- in this mov 0FFFFh = -1, I get it

inc ax, 0FFFFh; <--- bc increment by 1, so is 0, it will become 0000h, I get it


can someone help me to explain why the answer is FF00h for this variation?

mov ax, 0FFFFh;
inc al;  
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Linux
  • 31
  • 2

1 Answers1

1

al is the low 8 bits of ax. 8-bit instructions that use al as an operand only operate on those 8 bits. In particular, as you see, carries out of al do not affect anything else.

See How do AX, AH, AL map onto EAX?

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • 1
    Looks like just a duplicate. Last month I edited the top answer on that linked question to add the fact that "Writing AL, AH, or AX merges into the full AX/EAX/RAX", making it a good dup target for questions like this. – Peter Cordes Mar 27 '21 at 17:25
  • I do understand AL is lower part of AX, so, I wonder the anwser is 00FFh not FF00h – Linux Mar 27 '21 at 19:47
  • 1
    @Linux The answer *is* `FF00h`: `AL` is incremented and wraps around from `FFh` to `00h`, and `AH` is unchanged at `FFh`. Note that the "low", i.e. least-significant bits are written on the right. So for instance when `AX = 1234h`, you have `AH = 12h` and `AL = 34h`. You'd get `00FF` if you did `inc ah`. – Nate Eldredge Mar 27 '21 at 19:55
  • 1
    @Linux: Maybe you're confused that x86 is little-endian and so the least-significant byte occupies the lowest address in memory? But AX is a register, not memory. Even in memory, when talking about words instead of their individual bytes, we continue to write them in usual numerical notation with the least-significant bits on the right. – Nate Eldredge Mar 27 '21 at 19:59
  • yes, I still confusing with the mapping – Linux Mar 27 '21 at 20:49
  • because if I perform "mov ax 1234h" "sub al 35h" I will get 12FFh, and because didn't borrow from ah, so the 12 didn't change, but if I "sub ax 35h", it will become 11FFh – Linux Mar 27 '21 at 21:09
  • @Linux: Yes, exactly. When you operate on AX you are doing 16-bit operations, and you will get carries/borrows from the low half to the high half. – Nate Eldredge Mar 27 '21 at 23:38