0

So I have some ASM code that needs to get the value pointed by the SI register and store it to AL. I'm new to ASM, so i'm pretty sure an obvious solution exists.

The command i'm using to assemble this is:

gnu -c code.asm -o assembled_code

The code I tried is:

movb (%si), al

but it just gives me error: invalid operand for instruction

TheMystZ
  • 80
  • 1
  • 8
  • 16-bit addressing modes aren't encodeable in 64-bit mode. What environment are you hoping to *run* you code in? On bare metal as a legacy MBR bootloader (16-bit mode)? If so, use build options and `.code16`. Or as a user-space process under x86-64 Linux (32 or 64-bit mode are possible)? If so, don't write 16-bit code. – Peter Cordes Nov 24 '21 at 07:35
  • You just edited to add a new line. Is `movl $si_pointer, si` the actual line with the error? I doubt it, that should assemble just fine as a 32-bit store to memory at the symbol `si`, which would assemble but probably have a link error unless you defined an `si:` label somewhere. (If you'd used the `%si` register, it would be a size mismatch; `l` is 32-bit operand size, but `%si` is a 16-bit register.) – Peter Cordes Nov 24 '21 at 07:38
  • Error on second line. Just added 1st for clarification – TheMystZ Nov 24 '21 at 07:40
  • Ok, well as I said it does the opposite of clarifying: it doesn't write to %si, and if you changed it so it did you'd get `Error: incorrect register '%si' used with 'l' suffix`. I'd suggest removing it; people that know AT&T syntax x86 assembly already understand that %si holds a pointer. It's a total distraction from your [mcve]. – Peter Cordes Nov 24 '21 at 07:43
  • Yeah, just forgot SI was 16bit. – TheMystZ Nov 24 '21 at 07:45
  • From your later question, another bug was that `al` was missing a `%` decorator, so it was the symbol / global variable name `al`. – Peter Cordes Nov 24 '21 at 09:28

0 Answers0