我需要使用汇编语言绘制(打印)堆栈和队列。任何人都可以使用VGA图形向我推荐代码吗?
我试图修改绘制(打印)矩形的代码。这就是我所做的:
DATA SEGMENT
H DW 150
W DW 30
K DW 150
TEMP DW 0000
TEMP2 DW 0000
TEMP3 DW 0000
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START :MOV AX,DATA
MOV DS,AX
START1:
MOV AH,00H
INT 16H
CMP AL,61H ;press a to close
JZ END1
CALL RECT
RECT PROC
MOV AH,0
MOV AL,12H
INT 10H
MOV CX,W
MOV DX,H
MOV TEMP2,CX
MOV BX,CX
ADD BX,DX
MOV TEMP,BX
MOV AX,0C02H
BACK: INT 10H
INC CX
CMP CX,TEMP ;---top
JNZ BACK
MOV AX,0C30H
BACK1:INT 10H
INC DX
CMP DX,CX ;--ver right
JNZ BACK1
MOV AX,0C02H
BACK2:INT 10H
DEC CX
CMP CX,TEMP2 ;--bottom
JNZ BACK2
MOV AX,0C02H
BACK3:INT 10H
DEC DX
CMP DX,CX ;--left
JNZ BACK3
MOV AH,07H
INT 21H
RET
RECT ENDP
END1:MOV AH,4CH
INT 21H
CODE ENDS
END START
我已编码的堆栈程序是:
data segment
str1 db 0Ah, 0Dh,"CHOOSE OPERATION", 0Ah, 0Dh, '$'
str2 db 0Ah, 0Dh,"P FOR PUSH",0ah,0dh,'$'
str3 db 0A, 0Dh,"R FOR POP",0ah,0dh,'$'
str8 db 0Ah, 0Dh,"D FOR DISPLAY",0ah,0dh,'$'
str9 db 0Ah, 0Dh,"Any key for exit",0ah,0dh,'$'
str4 db 0Ah, 0Dh,"Enter value to be pushed",0ah,0dh,'$'
str5 db 0Ah, 0Dh,"Overflow",0ah,0dh,'$'
str6 db 0Ah, 0Dh,"Do you want to continue? (y/n)",0ah,0dh,'$'
str7 db 0Ah, 0Dh,"Empty stack",0ah,0dh,'$'
str10 db 0Ah, 0Dh,"Popping..$"
choose db 1 dup(0)
top db 1 dup(0)
temp db 1 dup(0)
t db 1 dup(0)
array db 100 dup(0)
maxsize db 1 dup(0)
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
mov ds,ax
mov top,00
mov temp,00
mov maxsize,10
lea si, array
lea di, array
menu:
mov dx, offset str1
mov ah,09h
int 21h
mov dx, offset str2
mov ah,09h
int 21h
mov dx, offset str3
mov ah,09h
int 21h
mov dx, offset str8
mov ah,09h
int 21h
mov dx, offset str9
mov ah,09h
int 21h
mov ah,01
int 21h
cmp al, 'p'
je p
cmp al, 'r'
je r
cmp al, 'd'
je d
jmp e
p: cmp top,10
jne x
mov dx, offset str5
mov ah,09h
int 21h
jmp menu
x: mov dx, offset str4
mov ah,09h
int 21h
mov ah,01
int 21h
mov [si],al
inc si
inc top
mov dx, offset str6
mov ah,09h
int 21h
mov ah,01
int 21h
cmp al, 'y'
je p
jmp menu
r: cmp top,00
jne y
mov dx, offset str7
mov ah,09h
int 21h
jmp menu
y: mov dx, offset str10
mov ah,09h
int 21h
dec si
dec top
mov dl,[si]
mov ah,02
int 21h
mov dx, offset str6
mov ah,09h
int 21h
mov ah,01
int 21h
cmp al, 'y'
je r
jmp menu
d: cmp top,00
jne zz
mov dx, offset str7
mov ah,09h
int 21h
jmp menu
zz: mov bl,top
mov t,bl
mov bx,si
z: dec si
mov dl,[si]
mov ah,02
int 21h
mov dl, 32
mov ah,02
int 21h
dec t
cmp t,00
jne z
mov si,bx
jmp menu
e: int 3
code ends
end start
end