0

I'm writing some NASM code, running on an x86 architecture.

As part of an exercise to write a procedure to print a number as hexedecimal (the exact details of my implementation of this are irrelevant, as far as I can tell), I need to copy a byte from one string to another.

Here are my strings:

hex_digits:
    db '0123456789abcdef'
hex_out:
    db '0000'

Let's say I the byte in hex_digits at the axth index, to the third index in hex_out.

In C, this would look like this:

hex_out[3] = hex_digits[ax]

And here's my assembly:

mov cx, [hex_digits+ax]
mov [hex_out+3], cx

Shouldn't this work? Well -- clearly not, but I've read about how effective addresses work, here. After reading that, I was convinced that I understood effective addresses, but it seems that's not the case.

I'm sure it's something glaringly obvious, but I'm fairly new to nasm.

Thanks!

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Jacob Garby
  • 773
  • 7
  • 22

0 Answers0