.model small
org 100h
.data
msg1 db "Enter a letter: $"
word db "BABA$"
word_length db 4 ; length of word
input1 db 10,?,10 dup('$') ; buffer for input
letter_pos db 0 ; counter for letter position
.code
main proc
mov ah, 09h
lea dx, msg1
int 21h
mov ah, 0ah
lea dx, input1
int 21h
mov ah, 02h ; setting initial cursor position
mov dh, 1
mov dl, 0
int 10h
; main code
lea si, input1[2]
lea di, word
mov cl, word_length
compare:
cmp cl, 0
je exit
mov bl, [si]
mov bh, [di]
cmp bl, bh
je correct_letter
inc letter_pos
inc di
dec cl
jmp compare
correct_letter:
; set cursor position
mov ah, 02h
mov dh, 1
mov dl, letter_pos
int 10h
mov ah, 09h
lea dx, input1+2
int 21h
inc letter_pos
mov al, letter_pos
dec cl
jmp compare
exit:
MOV ah, 4ch
int 21h
main endp
end main
我似乎无法弄清楚为什么这不起作用。我已经将其设置为循环的每次迭代,letter_pos 都会递增,这意味着它将进入下一列,或者在本例中到达单词的下一个位置。我在这里错过了什么吗?
我对汇编语言非常陌生,所以请原谅我乱七八糟的代码,我正在尝试为学校项目学习这个。我们将不胜感激您的帮助!
我期待它是这样的:
输入字母:A 啊啊
或
输入字母:B 乙乙
我尝试了一些方法来尝试解决这个问题,包括将 0rg 100g 更改为 .stack 100h (我不知道这有多重要)以及其他一些事情,我还是个新手,所以不知道如何完全调试它。
1. 您应该正确设置
data segment
。所以 main proc
的第一个指令应该是:
mov ax, @data
mov ds, ax
现在我在屏幕上看不到随机字符,程序执行后安全返回到系统。
2.
word
是保留关键字。将其更改为其他内容。
3. 函数
02h
、int 10h
采用 dh
、dl
和 bh
中的值 - 活动页数,应为 0
。
在
bh
中,您有 word
字母之一。
我在这里使用了
push bx / pop bx
和mov bx, 0
。现在光标正确改变位置。
correct_letter:
; set cursor position
push bx ; save current state of bx
mov bx, 0 ; active page = 0
mov ah, 02h
mov dh, 1
mov dl, letter_pos
int 10h
pop bx ; restore bx