Search code examples
assemblyx86fasm

error: value out of range in FASM x86 assembly


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?


Solution

  • 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.