3

I am trying to learn how to shuffle a deck using assembly language. I am fluent in java and I can easily translate java into C but I'm having a hard time with ASM. this is the block of code I have issues with right now:

MOV R8, [RDI+RSI*4]

MOV R9, [RDI+RDX*4]

MOV  [RDI+RSI*4], R9

MOV  [RDI+RDX*4], R8

I keep getting

error: impossible combination of address sizes

It was run with the command

nasm -f elf FILE-NAME.asm

I'm guessing it has issues with the registers I am using but I have no idea about the rules in assembly. I am learning using tutorialspoint but if anyone has any recommendations about other places I could learn better about it, that would be helpful. I also saw on this answer that all the registers used have the same size, so why the error?

droidnoob
  • 333
  • 5
  • 17

1 Answers1

13

You're writing 64bit code, but your -f elf will put NASM in 32bit mode. Use elf64 instead:

$ cat foo.asm
MOV R8, [RDI+RSI*4]

$ nasm -f elf foo.asm
foo.asm:1: error: impossible combination of address sizes

$ nasm -f elf64 foo.asm
(no output)
that other guy
  • 116,971
  • 11
  • 170
  • 194