我一直在做一个检查回文单词的程序。
#make_COM#
include emu8-86.inc
org 100h
mov ax, 1000
mov ds, ax
call pthis
db "This program inputs a string and check for the palindromic words." ,0
putc 0dh
putc 0ah
begin:
mov ax, 7000h
mov ds, ax
mov di, 0000
call pthis
db "Enter a string: ",0
mov dx, 10
call GET_STRING
mov cx, dx
putc 0dh
putc 0ah
back:
mov bl, [di]
cmp bl, 00h
jle stop
cmp bl, 41h
jl Not_A_Letter
cmp bl, 5Ah
jle Check_for_length
cmp bl, 61h
jl Not_A_Letter
cmp bl, 7Ah
jle Check_for_length
Not_A_Letter:
putc 0dh
putc 0ah
call pthis
db "You did not enter a valid string", 0
Check_for_length:
ret我只是想知道如何检查输入字符串的长度。
发布于 2016-11-24 18:36:12
GET_STRING正在以dx中最大大小的ds:di返回以零结尾的字符串.
你的:
cmp bl, 00h
jle stop将捕获该字符(以及任何具有0x80-0xFF值的字符)。但是,您可能更愿意只在到达字符串结束时使用je跳转吗?
因此,在stop:标签上,di包含字符串的长度(如果遇到0x80-0xFF字符,则可能会缩短)。我没有在您的代码中看到stop:标签。
顺便问一下,为什么使用7000:0000作为字符串缓冲区?这是某个人推荐的片段,还是你只是在黑暗中拍摄,希望能有好运?
您可以使用60+ (取决于所使用的命令行的长度)在0x0100之前的字节,或者您可以在代码的末尾保留空间。如果您希望保持偏移量0,我将选择命令行空间:
mov ax,cs
add ax,(100h-32)/16
mov ds,ax ; ds:0000 points 32 bytes ahead of first instruction of code.或者实际上,如果您想成为硬核,可以在代码的那一点执行add ax,16,覆盖代码的开头(因为它已经执行了,而字符串"This program inputs ..."为覆盖提供了大量的字节储备)。:)
(但要确保你明白我对你的建议,这样如果有人问你,你就可以解释原因)。
https://stackoverflow.com/questions/40790817
复制相似问题