简体   繁体   English

如何在Assembly中使用for循环?

[英]How to use for loop in Assembly?

I was tasked to do a code that would output the equal amount of 'Text Here' depending on the user input. 我的任务是根据用户输入执行输出等量“Text Here”的代码。 However, I seem to get bewildered by my cmp function. 但是,我似乎对我的cmp功能感到困惑。

;Get keyboard input
mov ah, 01h 
int 21h

;Save to bl for later use
mov bl, al
jmp isa

isa:
mov ah, 09h 
mov dx, offset text 
int 21h

cmp bl, bl
jne isa
je exit

What I get with this code is only one output of 'Text' no matter what number I input. 无论我输入什么数字,我得到的代码只是'Text'的一个输出。

EDIT: I tried this but now my output is infinite :( 编辑:我试过这个,但现在我的输出是无限的:(

isa:
inc bl
mov ah, 09h 
mov dx, offset ulit 
int 21h


cmp bl, 30h
jne isa
je exit

First of all, make sure that you initialize the BX register to zero before you start your loop: 首先,确保在开始循环之前将BX寄存器初始化为零:

...
xor bx,bx
isa:
...

To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me): 为避免DOS中断覆盖(使用过的)BX寄存器的内容,请将其保护在堆栈中(不确定DOS中断的调用约定,对我来说太久了):

...
push bx
int 21h
pop bx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM