1

I am in an introductory assembly class in university. I am using the yasm assembler, and I understand that movsx moves a lower sized value to the higher sized register. I also understand that movsxd is for moving a double word into a higher sized, 64bit, register. But, when I test things out, movsx and movsxd have to same behavior with double words.

Here is my example code:

    segment .data
a   dd      0xf000000f ; -268435441
    segment .text
    global main
main:
    movsx   rax, dword [a]
    movsxd  rbx, dword [a]
    ret

I feel since movsxd exists it should have some different behavior then movsx but when I run the code above and look at the values in the registers, there is no difference. Maybe I am not understanding it's intended use, or maybe I am misunderstanding something else. Any help would be great, thanks!

---Edit---
Also forgot to mention I am on Windows 11 x64

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 3
    According to the intel manual, `movsx r64, r/m32` does not exist. Apparently yasm accepts it anyway. – Jester Oct 20 '22 at 22:21
  • Ok, so it's just the assembler helping me out, sometimes that's nice, but while learning it let's me get away with bad practices. Thank you so much! – Jackson Brienen Oct 20 '22 at 22:23
  • 2
    You can always look at the machine code (e.g. with `objdump -d foo.obj` or get NASM or YASM to make a "listing" file like `yasm -l foo.lst.txt -fwin64 foo.asm`). If it assembles to the same machine code, it will necessarily run the same everywhere. (So use something like `movsx rax, dword [rcx]`, to avoid the RIP-relative addressing mode which would make for differences between `[a]` in two insns. Except you didn't use `default rel`). – Peter Cordes Oct 21 '22 at 00:22
  • Thanks @PeterCordes I took a look at the lst file, and, at least for my setup, it compiles to the same machine code. Thank you for the idea! – Jackson Brienen Oct 21 '22 at 01:10

0 Answers0