【发布时间】:2011-12-08 03:03:04
【问题描述】:
我正在使用 NASM 和 x86 Intel 汇编语法在 Linux 操作系统上开发一个程序 - 它应该很简单。
我遇到的问题是我无法为我的程序创建一个工作循环:
section .data
hello: db 'Loop started.', 0Ah ;string tells the user of start
sLength: equ $-hello ;length of string
notDone: db 'Loop not finished.', 0Ah ;string to tell user of continue
nDLength: equ $-notDone ;length of string
done: db 'The loop has finished', 0Ah ;string tells user of end
dLength: equ $-done ;length of string
section .text
global _start:
_start:
jmp welcome ;jump to label "welcome"
mov ecx, 0 ;number used for loop index
jmp loop ;jump to label "loop"
jmp theend ;jump to the last label
welcome:
mov eax, 4
mov ebx, 1
mov ecx, hello
mov edx, sLength
int 80 ;prints out the string in "hello"
loop:
push ecx ;put ecx on the stack so its value isn't lost
mov eax, 4
mov ebx, 1
mov ecx, notDone
mov edx, nDLength
int 80 ;prints out that the loop isn't finished
pop ecx ;restore value
add ecx, 1 ;add one to ecx's value
cmp ecx, 10
jl loop ;if the value is not ten or more, repeat
theend:
;loop for printing out the "done" string
我正在打印第一个字符串,一个“未完成”和最后一个字符串;我又错过了九个“未完成”!有谁知道为什么我失去了 ecx 寄存器的价值?
谢谢。
【问题讨论】:
-
int 80是int 0x50。你想要int 0x80。 (可能的规范副本:Assembler sysTime giving error on executing)