0

A homework question I don't understand the answer to:

Assuming all registers start at 0, what is the value of the RBX registers at the end of this assembly code?

mov $31, %bl
sal $32, %rbx
movl $32, %ebx
sar $31, %rbx

I predicted that the answer would be 62, by assuming that movl $32, %ebx should only affect the lower 32 bits. However, when I run this code in SASM, it seems that movl also zeros-out the upper 32 bits, and the answer is 0. Is this expected behavior? Is this a bug in SASM? Why does movl affect the upper 32 bits?

NeatNit
  • 526
  • 1
  • 4
  • 14
  • 3
    SASM doesn't emulate the instructions, it single-steps them on your actual CPU. You can usually trust what a debugger shows you. (bugs in a debugger are *possible* but typically only affect how information is displayed in the UI, not corrupting the architectural state. But this is not a bug, it's good ISA design.) – Peter Cordes Apr 29 '20 at 12:29
  • Thanks (genuinely), whoever marked this as duplicate. I couldn't for the life of me find the answer via web search. No idea why. – NeatNit Apr 29 '20 at 15:09
  • No worries. That Q&A has been one of the more useful canonical duplicate targets to point people at. Apparently not all x86-64 intros/tutorials cover this critical point. (And BTW, I didn't know that SO hides the close voters from low-rep users, but apparently it does.) – Peter Cordes Apr 29 '20 at 15:25

0 Answers0