-1

I'm attempting to write out the value of each integer in an array in decimal form. I'm using a premade function to do the conversion, but it requires that the data be padded with zeroes to output properly. Is it possible to use movzx or something similar when copying values from an array? I've tried using this: movzx eax, intArray[esi] but I'm unable to get it working.

Any help is much appreciated, thanks.

xboxmods
  • 53
  • 2
  • 3
  • 6

1 Answers1

0

You need to tell the assembler what size it is extending from. Because of the register, it knows the destination is 32 bits, but it doesn't know how big the source is. Example assuming source size of bytes:

movzx eax, byte intArray[esi]
ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • okay, it's a DWORD array and I tried using: `movzx eax, byte intArray[esi]` but couldn't get it to assemble. – xboxmods Oct 09 '11 at 02:13
  • 2
    If you're moving from dword to dword, there's no padding to be done, since the source is already the same size as the destination. You can just use `mov`. – ughoavgfhw Oct 09 '11 at 02:20
  • Ok, well. If that's the case, I'm not sure why the numbers are all coming out wrong. I guess this narrows things down at least. Thanks. – xboxmods Oct 09 '11 at 02:22
  • @xboxmods: If ESI is an element index (rather than a byte offset), then you'd want `mov intArray[esi*4]`. Also, this answer is NASM syntax (`byte` not `byte ptr`), but if you were using MASM the `byte` keyword would be an integer `1`. And I think until recently NASM would require `[intArray + esi]` not `intArray[esi]`, but MASM or GAS `.intel_syntax noprefix` would treat them the same. Anyway, not a [mcve] of your problem. – Peter Cordes Dec 03 '22 at 11:33
  • This question seems like a mess. Fortunately, we have [How to load a single byte from address in assembly](https://stackoverflow.com/q/20727379) as a canonical Q&A for byte loads. – Peter Cordes Dec 03 '22 at 11:33