Reputation: 16724
why am I getting error: value out of range.
in the following code?
mov eax,dword ptr "abcdlol$"
I want to put the address of "abcdlol"
into eax
register but looks like isn't this value that FASM is copying into eax
.
An example In C code: int *p="lol";
How to fix this? Is this an assembler's limitation?
Upvotes: 1
Views: 3402
Reputation: 49
Back to basics:
EAX can store only 4 bytes. "abcdlol$" is 8 bytes. So instead of putting the value directly, you should put the address of it into EAX as suggested by other posters. But if you insist, use two registers:
mov eax,"abcd" ;4 bytes
mov ebx,"lol$" ;4 bytes
or in 64-bit,
mov rax,"abcdlol$"
You should tell the difference between passing immediate values and passing addresses to the registers.
Upvotes: 0
Reputation: 10570
It FASM syntax it should be:
mov eax,my_string my_string db "abcdlol$"
You can also use lea
:
lea eax,[my_string] my_string db "abcdlol$"
Whether to use ASCIIZ string (terminated with 0) or some other terminator depends on what you are going to do with the string. It seems that you are using $
as string terminator, that is used by DOS print string function. Check that $
is the right string terminator for the OS API functions you are going to use (if any). For example printf
requires zero-terminated (ASCIIZ) strings.
See FASM HelloWorld .exe program see an example of FASM syntax.
dword ptr
and the like are needed only when addressing the memory. mov eax,abcdlol
is just a mov eax,immed32
. Processor does not worry whether you're you're going to use the value stored in eax
as a number or as a pointer.
Upvotes: 4
Reputation: 2363
This should work:
mystring db "abcdlol", 0
mov eax,mystring
Upvotes: 1