0

Basically I am wondering if I can use explicit local register variables to pin a variable to either rax, rbx, rcx or rdx and then use the registers 1 byte extension in inline assembly.

I want to let the compiler decide which register would be best to use but it needs to be one of these and I need to be able to access its 1 byte extension register in the inline assembly.

Is there any way to do this?

Edit: I need to stayoff the stackoverflow for a bit, getting a bit too lazy for my own good

Noah
  • 1,647
  • 1
  • 9
  • 18
  • 3
    I think you're asking if you can use a `uint64_t` input to an `asm` statement and then access the low-byte partial register of whatever register the compiler picks. You don't need register-asm variables for that, and partial registers aren't called "extension registers". See https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#x86-Operand-Modifiers - use `%b0` to get the low byte of whatever register the compiler picked for operand `0`. In 64-bit mode, *every* register has a low-byte partial register, like `r8b` or `sil`. – Peter Cordes Aug 22 '20 at 21:41
  • Not sure why you want to use explicit local variables if you want to let the compiler choose. Just use a 8 bit variable and register and be done with it. – Jester Aug 22 '20 at 21:42
  • @PeterCordes Use the `q` constraint to have gcc pick a register for which the `b` modifier is valid. – fuz Aug 22 '20 at 22:01
  • 1
    @fuz: yup, that's good documentation, or good if you want to write it so the same asm statement could compile for 32-bit mode, where `q` isn't equivalent to `r`. – Peter Cordes Aug 22 '20 at 22:03

0 Answers0