0
.data
onebyte        BYTE         78h
oneWord        WORD         1234h
oneDword       DWORD        1234 5678h

.code 
mov    eax, 0                ; EAX = 0000 0000h
mov    al, oneWord           ; EAX = 0000 00078h
mov    ax, oneWorod          ; EAX = 0000 1234h
mov    eax, oneDword         ; EAX = 1234 5678h
mov    ax, 0                 ; EAX = 1234 0000h

Here on the last instruction as it is shown in the example, the register value changes as follows "1234 0000" because the right part of 32-bit Register is called AX(16bit AH(8bit) AL(8bit)) and that's why the 0 replaced the last 2-bytes of the register. What if I wanted to change the first (high) 2-byte word of the register value ("1234") instead of the AX part (like this EAX = 0000 5678h)...

I'm new maybe I've skipped some part or forgot but the first half also should have a register name like AX or something right? Because as far as I remember the book hasn't (as of chapter 4) explained the first half of the register name yet...

Here are the screenshots of register explanation by the book so far. Upload 1 Upload 2

Also what are the other half of the registers name if you see the pic AX for the right part of the register what about the left part of the register?

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Shay
  • 3
  • 3
  • 1
    Shift left by 16 bits, then shift 16 bits right? Of if you have a non-zero value you want to replace the 16 top bits with then rotate, move, and rotate back? – Some programmer dude Nov 02 '21 at 13:01
  • 2
    Also note that when you say "4byte" what you really mean is "4 *hexadecimal **digits***" which is **two** bytes. – Some programmer dude Nov 02 '21 at 13:02
  • @Someprogrammerdude Nope, such a replacement is not valid. The Go assembler actually used to do that and it caused some hard to find issues with misassembled code. The problem being that `xor ax, ax` affects flags but `mov ax, 0` doesn't. – fuz Nov 02 '21 at 13:10
  • Oh and I nearly forgot, you could do a bitwise AND with `0000ffffh`. – Some programmer dude Nov 02 '21 at 13:18
  • Besides the duplicates, see also [Why do x86-64 instructions on 32-bit registers zero the upper part of the full 64-bit register?](https://stackoverflow.com/q/11177137) and [Why doesn't GCC use partial registers?](https://stackoverflow.com/q/41573502) for some performance reasons why more partial registers wasn't something CPU architects were keen to add. – Peter Cordes Nov 02 '21 at 13:24

0 Answers0