- Assembly code
datarea segment tips db 'Please input a string:',13,10,'$' errstr db 'length is too long!',13,10,'$' exitstr db 'exit','$'datarea endsprognam segment main proc far assume cs: prognam,ds:datarea,es:datareastart: push ds sub ax,ax push ax mov ax,datarea mov ds,ax mov ax,datarea mov es,ax ;+++++++++++++++++++++++++++++++++++++ lea dx,tips mov ah,9 int 21h mov bx,0 mov cx,0 mov dx,0 mov di,0AGAIN: mov ax,0 mov ax,bx add ax,cx add ax,dx add ax,di cmp ax,1eh ;如果ax的值大于30就跳转到ERR打印错误信息 ja ERR mov ax,0 mov ah,01h int 21h cmp ah,'$' je EXIT cmp ah,'0' jb L1 cmp ah,'9' jbe L2 cmp ah,'A' jb L1 cmp ah,'Z' jbe L3 cmp ah,'a' jb L1 cmp ah,'z' jbe L4 inc bx jmp AGAIN ERR: lea dx,errstr mov ah,9h int 21h jmp EXITL1: inc bx jmp GOBL2: inc cx jmp GOB L3: inc dx jmp GOBL4: inc di jmp GOBGOB: cmp ah,'$' jnz AGAINEXIT: lea dx,exitstr mov ah,9 int 21h ;++++++++++++++++++++++++++++++ main endpprognam ends end start
代码总是有错,我用的是01A功能,单个字符输入功能调用,但是没有成功,代码怎么改,请大家指教
------解决方案--------------------------------------------------------
首先,ah=1 的读入字符功能调用,输入的字符是在 AL 而非 AH 里;其次,程序最后缺少了“结束程序返回DOS”的功能调用。其它基本上是对的吧,要看结果就是 debug 该程序,在最后设断点运行到那里看各相关寄存器的值。
------解决方案--------------------------------------------------------