我正在使用MASM compilor和DOSBOX。我在输入过程中取2个十六进制数字,它工作正常,现在我想在输出过程中打印这些数字我如何使用push和pop这样做推送数字在输入过程中,将它们弹出输出过程。请让我知道如何使用推送和弹出
.model small
.stack 100h
.data
B DB 30 DUP(?)
.code
MAIN PROC
mov si, offset B
CALL Take_Hex_Input
mov DL,AL
CALL PRINT_HEX_Output
mov ah,4ch
int 21h
Main endp
TAKE_HEX_INPUT PROC NEAR
xor bx,bx
mov cl, 2
mov ah, 1
int 21h
cmp al,'f'
JG terminate
cmp al,39h
JG letter
cmp al,'a'
JL newcheck
cmp al,30h
JL letter
AND al,0Fh
JMP shift
letter:
sub al,37h
shift:
shl bl,cl
OR bl,al
int 21h
Ret
newcheck:
cmp al,'0'
JL terminate
cmp al,30h
JL letter
cmp al,'9'
JG terminate
cmp al,30h
JG letter
Terminate:
mov ah,4ch
int 21h
TAKE_HEX_INPUT endp
PRINT_HEX_Output PROC NEAR
mov ah,2
MOV dl,al
int 21h
PRINT_HEX_Output endp
End Main
答案 0 :(得分:0)
如果要在输入proc 中将值存储在堆栈中并从输出proc 中的堆栈中获取它,可以使用寄存器BP
来访问堆栈。这是下一个例子的作用:
push ax
)以存储按下的两个键。input
读取两个密钥,并使用BP
将它们存储在堆栈中保留的两个字节中。output
,其中BP
用于访问堆栈并提取密钥。pop ax
)。现在示例代码:
.model small
.stack 100h
.code
main proc
push ax ;◄■■ RESERVE MEMORY IN STACK FOR TWO KEYS.
call input
call output
pop ax ;◄■■ RELEASE MEMORY FROM STACK.
terminate:
mov ah,4ch
int 21h
main endp
INPUT PROC NEAR
;▼ CAPTURE TWO KEYS.
mov ah, 1 ;◄■■ READ FIRST KEY.
int 21h
mov bl, al ;◄■■ SAVE FIRST KEY IN BL.
mov ah, 1 ;◄■■ READ SECOND KEY.
int 21h
mov bh, al ;◄■■ SAVE SECOND KEY IN BH.
;▼ STORE BOTH KEYS IN STACK.
mov bp, sp ;◄■■ ACCESS THE STACK.
mov [bp+2], bx ;◄■■ SAVE KEYS IN STACK.
ret
input endp
OUTPUT PROC NEAR
mov bp, sp ;◄■■ ACCESS THE STACK.
mov cx, [bp+2] ;◄■■ GET BOTH KEYS FROM STACK.
;▼ OUTPUT FIRST KEY.
mov dl,cl ;◄■■ FIRST KEY FROM CL.
mov ah,2
int 21h
;▼ OUTPUT SECOND KEY.
mov dl,ch ;◄■■ SECOND KEY FROM CH.
mov ah,2
int 21h
ret
output endp
end main