;----------------------------------------------------------------------;Program: 字符栈的入栈、出栈和显示;ah为功能号 0表示入栈 1出栈 2显示字符;对于2号功能 dh 为显示行数 dl为显示列数 ;----------------------------------------------------------------------assume cs:codesgcodesg segmentmain: call getstr mov ax,4c00H int 21Hgetstr: push axgetstr_start: mov ah,0 ;获取键入码 int 16h cmp al,20h ;ascii码小于20H 表明不是字母 调用功能处理过程 jb nochar mov ah,0 call charstack ;调用入栈 mov ah,2 call charstack ;显示字幕 jmp getstr_start ;循环调用 等待输入nochar: cmp ah,0eh ;处理非字母的路口 主要用于判断是enter 还是backspace je backspace cmp ah,1ch je putenter jmp getstr_startbackspace: mov ah,1 ;出栈 call charstack mov ah,2 ;显示 call charstack jmp getstr_startputenter: mov ax,0 call charstack mov ah,2 call charstack pop ax ;enter键 当前输入结束 retcharstack: jmp short charstarttable dw charpush,charpop,charpreparetop dw 0charstart: push bx push dx push di push es cmp ah,2 ja sret mov bl,ah mov bh,0 add bx,bx jmp word ptr table[bx] ;根据"hash"表寻址 我是这样理解的charpush: mov bx,top mov [si+bx],al inc top jmp sret charpop: cmp top,0 ;top是否指向栈底 je sret dec top mov bx,top mov al,[si+bx] jmp sretcharprepare: mov ax,0b800H ;为显示字母做准备 确定行数列数 mov es,ax mov al,160 mov ah,0 mul dh mov di,ax add dl,dl mov dh,0 add di,dx mov bx,0charshow: cmp bx,top ;比较是否为空 jne notempty ;为空就输出当前字母 mov byte ptr es:[di],' ' ;最后结尾输出一个空格 jmp sretnotempty: mov al,[si+bx] mov es:[di],al mov byte ptr es:[di+1],02h inc bx add di,2 jmp charshowsret: pop es pop di pop dx pop bx retcodesg endsend main 学了数据结构的栈 再看这个似乎更容易些