简体   繁体   English

错误:FASM x86组件中的值超出范围

[英]error: value out of range in FASM x86 assembly

why am I getting error: value out of range. 为什么我会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 . 我想将"abcdlol"的地址放入eax寄存器,但看起来不是FASM复制到eax

An example In C code: int *p="lol"; 用C代码编写的示例: int *p="lol";

How to fix this? 如何解决这个问题? Is this an assembler's limitation? 这是组装商的限制吗?

It FASM syntax it should be: 它的FASM语法应为:

mov eax,my_string
my_string db "abcdlol$"

You can also use lea : 您也可以使用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. 是否使用ASCIIZ字符串(以0终止)或其他终止符,取决于您对字符串的处理方式。 It seems that you are using $ as string terminator, that is used by DOS print string function. 看来您正在使用$作为字符串终止符,DOS打印字符串函数使用了该终止符。 Check that $ is the right string terminator for the OS API functions you are going to use (if any). 检查$是否是您要使用的OS API函数的正确字符串终止符(如果有)。 For example printf requires zero-terminated (ASCIIZ) strings. 例如, printf需要零终止(ASCIIZ)字符串。

See FASM HelloWorld .exe program see an example of FASM syntax. 请参阅FASM HelloWorld .exe程序,请参阅FASM语法的示例。

dword ptr and the like are needed only when addressing the memory. 仅在寻址存储器时才需要dword ptr等。 mov eax,abcdlol is just a mov eax,immed32 . mov eax,abcdlol只是一个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. 处理器不必担心您要使用eax存储的值作为数字还是指针。

This should work: 这应该工作:

mystring  db  "abcdlol", 0
mov eax,mystring

Back to basics: 回归本源:

EAX can store only 4 bytes. EAX只能存储4个字节。 "abcdlol$" is 8 bytes. “ abcdlol $”是8个字节。 So instead of putting the value directly, you should put the address of it into EAX as suggested by other posters. 因此,与其直接输入值,不如按照其他发布者的建议,将其地址放入EAX。 But if you insist, use two registers: 但是如果您坚持要使用两个寄存器:

mov eax,"abcd" ;4 bytes
mov ebx,"lol$" ;4 bytes

or in 64-bit, 或64位

mov rax,"abcdlol$"

You should tell the difference between passing immediate values and passing addresses to the registers. 您应该告诉传递立即数和将地址传递给寄存器之间的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM