assume cs:codesg,ds:datasg datasg segment mystack db 1024 dup(0);自定义堆栈 top dw 0h;栈顶 x db 10;列号 y db 10;行号 datasg ends stacksg segment db 128 dup(0) stacksg ends codesg segment ;-------------------------------模拟输入 ic:mov ah,0
- assume cs:codesg,ds:datasg
- datasg segment
- mystack db 1024 dup(0);自定义堆栈
- top dw 0h;栈顶
- x db 10;列号
- y db 10;行号
- datasg ends
- stacksg segment
- db 128 dup(0)
- stacksg ends
- codesg segment
- ;-------------------------------模拟输入
- ic:mov ah,0
- int 16h
- cmp ah,0eh
- jne ic_enter;退格
- call ic_pop
- call ic_show
- jmp loops
- ic_enter:cmp ah,1ch;回车键
- jne ic_p
- jmp ic_over
- ic_p:mov ah,0
- push ax
- call ic_push
- call ic_show
- loops:jmp ic
- ic_over:ret
- ;-------------------------------字符进栈
- ic_push:push bp
- mov bp,sp
- push ax
- push bx
- mov ax,ss:4h[bp]
- mov bx,top
- mov mystack[bx],al
- inc top
- pop bx
- pop ax
- pop bp
- ret 2h
- ;-------------------------------字符出栈
- ic_pop:cmp top,0
- je ic_not_char_p
- dec top
- ic_not_char_p:ret
- ;-------------------------------字符显示
- ic_show:push ax
- push bx
- push si
- push es
- mov ax,0b800h
- mov es,ax
- mov al,y
- mov bl,160
- mul bl
- push ax;列数
- mov al,x
- mov bl,2
- mul bl
- pop si
- add si,ax;显示位置
- cmp top,0
- jne show_start;空列表
- mov byte ptr es:[si],'_'
- mov byte ptr es:[si+2],' '
- show_start:mov bx,0
- ic_show_loop:cmp bx,top
- jnb ic_not_char_s;读尽则跳
- mov al,mystack[bx]
- mov es:[si],al
- mov byte ptr es:[si+1],12;字体颜色
- mov byte ptr es:[si+2],'_'
- mov byte ptr es:[si+3],8
- mov byte ptr es:[si+4],' '
- inc bx
- add si,2
- loop ic_show_loop
- ic_not_char_s:pop es
- pop si
- pop bx
- pop ax
- ret
- main_start:mov ax,datasg
- mov ds,ax
- mov ax,stacksg
- mov ss,ax
- mov sp,128
- call ic;调用
- mov ax,4c00h
- int 21h
- codesg ends
- end main_start