zy8818 发表于 2018-4-5 19:34:39

键盘输入显示字符串问题

下面的代码编译运行之后,按任意键退出,我都怀疑虚拟8086能不能运行这个程序了


;最基本的字符串输入程序,需要具备下面的功能
;1.在输入的同时需要显示这个字符串
;2.一般输入回车符后,字符串输入结束
;3.能够删除已经输入的字符

;子程序参数
;dh 显示位置_行
;dl 显示位置_列
;ds:si 指向字符串的首地址,字符串以0结尾


assume cs:code

code segment
start:
        call getstr

       

return:
        mov ax,4c00h
        int 21h

getstr:
        push ax

getstrs:
        mov ah,0
        int 16h
       

        cmp al,20h
        jb nochar
        mov ah,0
        call charstack
        mov ah,2
        call charstack
        jmp getstrs

nochar:
        cmp ah,0eh
        je backspace
        cmp ah,1ch
        je enter1
        jmp getstrs

backspace:
        mov ah,1
        call charstack
        mov ah,2
        call charstack
        jmp getstrs
enter1:
        mov al,0
        mov ah,0       
        call charstack
        mov ah,2
        call charstack

        pop ax
        ret

       




charstack:
        jmp charstart
        table dw charpush,charpop,charshow
        top dw 0
charstart:
        push bx
        push dx
        push di
        push es

        cmp ah,2        ;ah功能号大于2退出
        ja sret
        mov bl,ah
        mov bh,0
        add bx,bx
        jmp word ptr table        ;功能号跳转

charpush:
        mov bx,top
        mov ,al
        inc top
        jmp sret


charpop:
        cmp top,0
        je sret
        dec top
        mov bx,top
        mov al,
        jmp sret

charshow:
        mov bx,0b800h
        mov es,bx
        mov al,160
        mov ah,0
        mul dh
        mov di,ax
        add di,dx
        mov bx,0

charshows:
        cmp bx,top
        jne noempty
        mov byte ptr es:,' '
        jmp sret

noempty:
        mov al,
        mov es:,al
        mov byte ptr es:,' '
        inc bx
        add di,2
        jmp charshows

sret:        ret

code ends
end start

casanava 发表于 2018-4-23 07:11:32

运行进入死循环
页: [1]
查看完整版本: 键盘输入显示字符串问题