2

I have a byte-array of characters declared in .data

chars db 'spipopd'

and I have set rdi to point to the base index of this array

mov rdi, chars

At some point, I want to put a character from the array into an 8-bit register. The first statement below produces a valid value, but the second one causes r9b to contain void upon entering the gdb command print $r9b.

mov al, [rdi]   ; produces valid value in gdb
mov r9b, [rdi]  ; r9b = void, according to gdb

Any of the register r8b to r15b has the same effect. As I understand, both al and r9b are 8-bit, so why does one work, and the other doesn't? My hunch is that, although they are both 8-bit in size, they have some subtle differences that elude me.

The Intel documentation states:

"REX prefixes are used to generate 64-bit operand sizes or reference registers R8-R15."

Is this related to my problem?

harold
  • 61,398
  • 6
  • 86
  • 164
InvalidBrainException
  • 2,312
  • 8
  • 32
  • 41
  • No. The REX prefix is part of the opcode and it doesn't affect the execution of the instruction self. – Gunther Piez Apr 30 '12 at 08:58
  • 2
    How did you determine that the value in `al` is correct? I thought GDB only supported printing the full register, which means `print $al` wouldn't work either, but `print $rax` and `print $r9` would. You could use `print $r9 & 0xff` to get just the low byte, though. – ughoavgfhw Apr 30 '12 at 19:10
  • Could it be that you're running the code in a 32-bit code segment and you don't have access to R8-R15? These registers apparently only are accessible from 64-bit code segments. – BitBank May 08 '12 at 19:54

1 Answers1

1

"void" isn't really a value that a register can have, so that looks like gdb is just not recognizing r9b as a register name.

Note that there are two different notations for the low-byte registers, r9b and r9l, and different sources use different names.

Breaking a random program in main and trying it myself, I get this output:

(gdb) print $r9b
$1 = void
(gdb) print $r9l
$2 = 16

Apparently gdb only recognizes the $r9l notation.

olsner
  • 981
  • 7
  • 6