Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 806 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error moving a constant byte value into %ebx

#1


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?
Reply

#2
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][1] (Ctrl-F for "p. 183").


[1]:

[To see links please register here]

Reply

#3
For 64-bit x86; there is nothing wrong with the instruction `movb $0x0F, (%ebx)`. It assembles to 0x67, 0xC6, 0x03, 0x0F.

The book is wrong.

Note that all instructions can be bugs (simple example: using `add` when you wanted to use `sub`), and `movb $0x0F, (%ebx)` may be a bug (e.g. maybe the value was supposed to be `0xFF`, maybe it was supposed to use a different register, maybe it was supposed to use `rbx`, maybe it was supposed to be a `lea`, ..). This doesn't mean that it's always a bug (e.g. 32-bit addresses are perfectly legal and sometimes desirable in 64 bit code).
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through