我正在学习汇编程序(16 位 DOS 上的 TASM)并尝试使用 0Ah DOS 服务将文本直接读入堆栈。它在 emu8086 中运行良好,而当我使用实际的 TASM 运行它时 - 它不提供任何用户输入(根本没有输入,似乎根本就跳过INT 21h
)。
这是我使用它的方式:
PROC _readNum USES BP AX BX CX DX SI
PUSH BP
MOV BP, SP
SUB SP, 7
MOV AH, 0Ah ;Buffered input
MOV [BP-7], 5 ;Max number of characters to read (4 + 1 for enter)
LEA DX, [BP-7]
INT 21h ;This interrupt seems to be doing nothing at all
...
可能是什么问题?我是否以错误的方式引用堆栈?提前致谢。
这是完整的代码以防万一:
ascii_offset EQU 30h
.model small
.stack 100h
.data
; add your data here!
outStrA DB "Input A: $"
outStrB DB "Input B: $"
resultStr DB "Result of $"
plusStr DB "+$"
equalsStr DB " is $"
eol DB 13, 10, "$"
cnt DB 10
rcnt DB 0
buf DB 11 dup("$")
PRINT MACRO op1
MOV AH, 09h
LEA DX, op1
INT 21h
ENDM
PRINTLN MACRO op1
PRINT op1
PRINT eol
ENDM
PRINTEOL MACRO
PRINT eol
ENDM
.code
PROC _printNum USES BP AX BX DX SI
PUSH BP
MOV BP, SP
SUB SP, 6 ;Max number to print is 5 + $ sign
MOV AX, [BP+2]
MOV DX, 0h ;Is required to divide a double pair
MOV BH, 0h
MOV BL, 10 ;Divisor
LEA SI, [BP-1] ;Our string stored in memory (from end)
MOV byte ptr [SI], "$" ;End of str
_printNum_loop:
DIV BX ;Result is in AX:DX
ADD DL, ascii_offset ;Convert to ASCII
DEC SI
MOV [SI], DL
MOV DX, 0h ;Reset DX to divide again
CMP AX, 0h ;If AX is 0
JNE _printNum_loop
PRINT [SI]
MOV SP, BP
POP BP
RET 2
ENDP
PROC _readNum USES BP AX BX CX DX SI
PUSH BP
MOV BP, SP
SUB SP, 7
MOV AH, 0Ah ;Output to screen
MOV [BP-7], 5 ;Max number of characters to read (4 + 1 for enter)
LEA DX, [BP-7]
INT 21h
MOV AX, 0h ;Result
MOV BX, 0h ;Temporary result
MOV CX, 0h ;Loop counter
MOV CL, [BP-6] ;Loop counter
LEA SI, [BP-5] ;Starting position to read number
_readNum_strloop:
MOV DX, 10 ; ;Will multiply AX by DX
MUL DX ; AX = AX * DX
MOV BL, [SI]
SUB BL, 30h
ADD AX, BX
INC SI
LOOP _readNum_strloop
MOV SP, BP
POP BP
RET 0
ENDP
start:
; set segment registers:
MOV AX, @data
MOV DS, AX
MOV ES, AX
PUSH 0ABCDh
JMP _printNum
MOV AX, 4c00h ; exit to operating system.
INT 21h
END start ; set entry point and stop the assembler.