【发布时间】:2015-08-01 02:12:26
【问题描述】:
我是 NASM 汇编程序的新手,并尝试编写自己的汇编代码。编译时,我没有收到任何错误,但在运行时,代码崩溃了。调试时,代码似乎在 push 或 _printf 调用时崩溃。
我已对我的代码进行了注释以使其更具可读性。
global _main
extern _printf
section .text
_main:
jp _loop ;jump to loop
_loop:
mov ebx, [a] ;move double word 'a' into register ebx
inc ebx ;increment register ebx
mov [a], ebx ;move contents of ebx into double word 'a'
add ebx, '0' ;add char 0 (0x30)
push ebx ;push ascii character on to stack
push format ;push format string on to stack
call _printf ;call print function
cmp dword [a], 10 ;compare if value of a is equal to 10
jne _loop ;loop if not equal to 10
ret ;return if equal to 10
a:
dd 0 ;initialize dword as 0
format:
db "%i", 0 ;format string for printf
提前致谢!我希望这不是太无聊。
【问题讨论】: