Linux 程序集中的循环不';为什么不工作?
我有问题。我尝试在汇编中构建一个循环(nasm、linux)。循环应该“cout”编号为0-10,但它不工作,我不知道为什么。下面是一个代码:Linux 程序集中的循环不';为什么不工作?,linux,assembly,nasm,Linux,Assembly,Nasm,我有问题。我尝试在汇编中构建一个循环(nasm、linux)。循环应该“cout”编号为0-10,但它不工作,我不知道为什么。下面是一个代码: section .text global _start _start: xor esi,esi _ccout: cmp esi,10 jnl _end inc esi mov eax,4 mov ebx,1 mov ecx,esi mov edx,2 int 80
section .text
global _start
_start:
xor esi,esi
_ccout:
cmp esi,10
jnl _end
inc esi
mov eax,4
mov ebx,1
mov ecx,esi
mov edx,2
int 80h
jmp _ccout
_end:
mov eax,1
int 80h
section .data
嗯,循环正在工作,但是您没有正确使用系统调用。这里涉及到一些神奇的数字,让我们先把它弄清楚:
- 4是
write
- 1是标准输出的文件描述符
mov eax,4 ; write syscall
mov ebx,1 ; stdout
mov ecx,somewhere_in_memory ; buffer
mov edx,1 ; one byte at a time
将其与您的代码进行比较:
mov eax,4
mov ebx,1
mov ecx,esi ; <-- particularly here
mov edx,2
int 80h
输出
123456789:
可能不是您想要的,但您应该能够从这里获得它。为读者做练习等等。什么特别不起作用?程序有故障吗?它永远不会结束吗?它是否输出0-10以外的数字?没有输出,屏幕是空的,我不知道为什么…您在ecx
中输入的值需要是要打印的字符序列的地址。你在ecx中输入的只是一个0-9范围内的整数。你能告诉我该在这个程序中修改什么才能开始工作吗?你能帮我完成下面的程序吗??谢谢:D
section .data
text db 0 ; text is a byte in memory
section .text
global _start
_start:
xor esi,esi
_ccout:
cmp esi,10
jnl _end
inc esi
lea eax,['0'+esi] ; print '0' + esi. lea == load effective address
mov [text],al ; is useful here even though we're not really working on addresses
mov eax,4 ; write
mov ebx,1 ; to fd 1 (stdout)
mov ecx,text ; from address text
mov edx,1 ; 1 byte
int 80h
jmp _ccout
_end:
mov [text],byte 10 ; 10 == newline
mov eax,4 ; write that
mov ebx,1 ; like before.
mov ecx,text
mov edx,1
int 80h
mov eax,1
mov ebx,0
int 80h