Loading a register from a “db 0” doesn't load a 0 into EAX?

后端 未结 1 1534
萌比男神i
萌比男神i 2021-01-24 03:50

I\'ve been bashing my head against the wall for over an hour and I can\'t understand why the below doesn\'t work. If I change b: db 1 to b: db 0 then i

1条回答
  •  误落风尘
    2021-01-24 04:47

    You've declared b as a byte:

    b: db 1
    

    but you load it as a dword:

    mov eax, dword [b]
    

    This explains why the zero flag is unset even when b is 0: because it's loading the next 3 bytes as well.

    Just change your declaration:

    b: dd 1 
    

    Alternatively, you could load a byte with zero extension: movzx eax, byte [b]


    Similarly, you load a qword from z but you only defined it as a dd dword. See Which variable size to use (db, dw, dd) with x86 assembly?

    Also, use default rel so all addressing modes pick RIP-relative addressing without having to say [rel b] everywhere.

    0 讨论(0)
提交回复
热议问题