[英]Assembly loop doesn't print values
我从组装开始,正在尝试创建一个简单的循环来打印eax值,但是它不起作用,而且我不确定我在这里做什么。
global _main ; make visible for linker
extern _printf ; link with printf
; -------------------------------
section .const
hello db `Hello world! %d \n\0`; 0 on stringi lõpp.
arv dw 5 ; %d võimaldab stringis arvu näidata.
otsitav dw 10 ;10 on reavahetus
vastus dw 0 ;dw läheb arvule
section .text
; -------------------------------
_main:
mov eax, otsitav ; Annan eax-le kasutaja sisestatud väärtuse.
mov ebx, 1 ; Annab ebx-le väärtuse 1 - sealt alustab for tsükliga.
.loop1:
dec eax ; võtab eax-ilt ühe ära.
push eax
call _printf
add esp, 4 ; tasakaalustab.
cmp eax, 0 ; eax ? 0
je .loop1 ; kui ? asemele saab = panna siis hüppa .loop1 juurde
ret
我听不懂您的评论,所以我真的不知道发生了什么,但是我使用bss节为您制作了一个示例程序来存储您的计数器;
global _main
extern _printf
[section] .bss
storage resd 1 ; reserve 1 dword
[section] .data
fmt db "output = %s %d", 0dh,0ah,0 ; newline in formate now
hello db "hello world",0 ; the string
count equ 10 ; output ten times
[section] .text
_main:
push ebp
mov ebp, esp ; stack related
mov eax, count
mov dword[storage], eax ; store eax's current value
nLoop:
push eax
push hello
push fmt
call _printf
add esp, 12 ; clean 3 args (4 * 3)
mov eax, dword[storage] ; grab current count
sub eax, 1
mov dword[storage], eax ; store new value for later
jnz nLoop ; test if value is zero
leave ; also stack related
ret
输出;
output = hello world 10
output = hello world 9
output = hello world 8
output = hello world 7
output = hello world 6
output = hello world 5
output = hello world 4
output = hello world 3
output = hello world 2
output = hello world 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.