Why can't I MOV a 64 bit value to a 64-bit register?

Viewed 189

I have a question when it compiles assembly code (as previously thought x64) and tries to load the following data onto the stack:

mov rax, "AAAAAAAAA"; flax == 9
push rax

gets the message:

warning: character constant too long [-w + other]

I know it's only a warning, but I thought it operates on 64-bit registers, which is also indicated by their name.

The system is 64 bit Debian (I think). The program also compiles as a 64 bit binary file:

nasm - f elf64

Can anyone explain to me, or at least give me some keywords, how to delve into the topic :)

1 Answers

If you look closely:

mov rax, “AAAAAAAAA”; flax == 9

The string actually contains 9 'A's. Every character is 1 byte, so 8 bits. That means, in a 64-bit register you can only have 8 of them because 8 chars * 8 bits/char = 64 bits.

To write hex constants, use mov rax, 0xAAAAAAAAA like in C. Single or double quotes in NASM give you (multiple) ASCII characters as a little-endian integer value taking the ASCII characters in source order.

Related