王爽《汇编语言》17.3 字符串的输入程序简易版

assume cs:code,ss:stack,ds:data
stack segment
 dw 128 dup (0)
stack ends
data segment
 db 126 dup (0)
data ends
code segment
start:  
        mov ax,stack
	mov ss,ax
	mov sp,128

        call clear_screen

	mov bx,data
        mov ds,bx
        mov bx,0
;---------------------------get string and put it in data segment,then call show sub
get_str:
        cmp bx,126
        je clear_datastr
        mov ah,0
        int 16h 
	cmp al,20h
	jb nochar
	call charin
	call showstr
	jmp get_str

nochar: cmp ah,0eh
        je backspace
	jmp get_str

charin:
        mov ds:[bx],al
	inc bx
	ret

backspace:
        cmp bx,0
	je get_str
	dec bx
        mov byte ptr ds:[bx],' '
	call showstr
	jmp get_str

clear_datastr:
        mov cx,126
clear_datastrs:
	dec bx
        mov byte ptr ds:[bx],' '
	loop clear_datastrs
	call showstr
	jmp get_str

;----------------------------------------show string
showstr:
        push cx
	push bx
	push es
	push si
	push di

        mov bx,0b800h
	mov es,bx
	mov di,0
	mov si,0
showstrs:
        mov cx,0
	mov cl,ds:[si]
	jcxz showret
	mov es:[di],cl
	add di,2
	inc si
	jmp showstrs
showret:
        pop di
	pop si
	pop es
	pop bx
	pop cx
	ret
 ;-------------------------clear_screen
 clear_screen:
        push bx
	push es
	push cx
	mov bx,0b800h
	mov es,bx
	mov bx,0
	mov cx,2000
clear_screens:
        mov byte ptr es:[bx],' '
	add bx,2
	loop clear_screens
        pop cx
	pop es
	pop bx
	ret
;-----------------------------------
       mov ax,4c00h
       int 21h

code ends
end start

猜你喜欢

转载自blog.csdn.net/weixin_41944412/article/details/80754061
今日推荐