Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error moving a constant byte value into %ebx

I'm working through Computer Systems, A Programmer's Perspective (3rd edition), and Practice Problem 3.3 contains the following line:

movb $0xF, (%ebx)

I'm supposed to find out what's wrong with this line of x86-64 assembly, and the answer key states: "Cannot use %ebx as address register", which doesn't make sense to me. My understanding is that this line intends to copy 0xF to a location in main memory, however %ebx is a 32-bit register, memory addresses are 64 bits wide on 64-bit machines, and so %ebx cannot hold a memory address, therefore it cannot be dereferenced (dereferencing is what the parentheses around %ebx represent, correct?). However, looking a few pages back in the book (page 183, if you have it) there is an example detailing the five mov operand--destination combinations, one of which is:

movb $-17, (%esp)         Immediate--Memory, 1 byte

%esp is a 32-bit register just like %ebx! And this example shows a byte value being moved to a dereferenced 32-bit register! Which doesn't make sense to me, because how can %esp contain a 64-bit address? Do I completely misunderstand assembly?

like image 928
Peter Delevoryas Avatar asked Jul 26 '15 02:07

Peter Delevoryas


1 Answers

You are right that,

movb $-17, (%esp)         Immediate--Memory, 1 byte

should not be allowed. In fact the authors have posted this as a typo. Check out their errata list (Ctrl-F for "p. 183").

like image 73
FahimApple Avatar answered Nov 15 '22 08:11

FahimApple