|
1鱼币
完整程序如下,
不明白的地方是:
dl,dh置光标怎么实现?
以及top用于字符进出,top初始值应该是一个偏移地址
- assume cs:code,ds:data
- data segment
- dw 128 dup (0)
- data ends
-
- code segment
- start:
- mov ax,data
- mov ds,ax
- mov si,0
- mov dl,0 ;设置行
- mov dh,0 ;设置列
- call getstr
- 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 charenter
-
- jmp getstrs
- backspace:
- mov ah,1
- call charstack
-
- mov ah,2
- call charstack
-
- jmp getstrs
- charenter:
- mov al,0
- mov ah,0
- call charstack
-
- mov ah,2
- call charstack
- pop ax
- ret
- charstack:
- jmp short charstart
- table dw charpush,charpop,charshow
- top dw 0
- charstart:
- 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]
- charpush:
- mov bx,top ;这句中的top不理解怎么用。
- mov [si][bx],al
- inc top
- jmp sret
- charpop:
- cmp top,0
- je sret
- dec top
- mov bx,top
- mov al,[si][bx]
- jmp sret
- charshow:
- mov bx,0b800h
- mov es,bx
-
- mov al,160;感觉从这4句没有什么用吧?似乎可以注释掉啊
- mov ah,0
- mul dh
- mov di,ax
- add dl,dl
- mov dh,0
- add di,dx
- mov bx,0
- charshows:
- cmp bx,top
- jne noempty
- mov byte ptr es:[di],' '
- jmp sret
- noempty:
- mov al,[si][bx]
- mov es:[di],al
- mov byte ptr es:[di+2],' '
- inc bx
- add di,2
- jmp charshows
- sret:
- pop es
- pop di
- pop dx
- pop bx
- ret
- code ends
- end start
复制代码 |
最佳答案
查看完整内容
dh中存放行号,dl中存放列号,用dh*160+dl*2来定位显示位置,top中存放的是字符栈中字符的个数。
|