【发布时间】:2017-09-26 12:41:50
【问题描述】:
我是使用 Assembly(所有类型)的新手,所以我正在关注来自 tutorialspoint.com 的教程 特别是,我在 https://www.tutorialspoint.com/assembly_programming/assembly_addressing_modes.htm 页面上,该页面是关于程序集寻址的。一切正常,直到给出代码的最后一个示例(取名为 Zara Ali 并将其更改为 Nuha Ali):
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
;writing the name 'Zara Ali'
mov edx,9 ;message length
mov ecx, name ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov [name], dword 'Nuha' ; Changed the name to Nuha Ali
;writing the name 'Nuha Ali'
mov edx,8 ;message length
mov ecx,name ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
name db 'Zara Ali', 0xa
这段代码当然可以,但是,在稍微修改它时,我遇到了问题。在第 13 行,我将 'Nuha' 更改为 'Nuhas' 只是为了看看它是否会出现 'NuhasAli' (因为我假设该行只是用 Nuhas 替换任何位并保留其余部分(Ali) )。
当我尝试这个并运行命令“nasm -f elf helloasm.asm”(helloasm.asm 是文件名)时,它给了我这两条消息:
helloasm.asm:13: warning: character constant too long
helloasm.asm:13: warning: dword data exceeds bounds
我找不到任何关于第一个问题的见解,因为当我查找它时,它给我的只是关于 C 和 C++ 的结果。但是,至于第二个警告,我试图通过简单地将其设置为 qword 而不是 dword 来使 dword 数据停止超出范围
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
;writing the name 'Zara Ali'
mov edx,9 ;message length
mov ecx, name ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov [name], qword 'Nuhas' ; Changed the name to Nuha Ali
;writing the name 'Nuha Ali'
mov edx,10 ;message length
mov ecx,name ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
name dw 'Zara Ali', 0xa
helloasm.asm:13: warning: character constant too long
helloasm.asm:13: error: operation size not specified
此时,我被难住了。 谁能提供任何关于为什么会发生这种情况以及我应该如何解决它的见解?我的基础错了吗?在此先感谢您的帮助
【问题讨论】: