如何仅使用 Intel-8088 中提供的指令打印数字数组(或表格)?我正在使用 VonSim 来模拟整个过程。
要使用仅打印字符的中断 7 打印单个数字,我有这样的东西:
D_ZERO EQU 48 ; ASCII code for 0
org 1000H
char db ?
number db 4
org 2000h
mov ah, number
add ah, D_ZERO
mov char, ah
mov al, 1
mov bx, offset char
int 7
int 0
end
但是我需要一个循环或允许我打印的东西,例如:
table1 db 1, 2, 3
:
D_ZERO EQU 48 ; ASCII code for 0
org 1000H
char db ?
table1 db 1, 2, 3
size 3
org 3000h
print_table:
<CODE TO PRINT THE TABLE>
.
.
.
int 7
jnz print_table
ret
org 2000h
mov ah, table1
call print_table
int 0
end
我想我找到了自己问题的答案。
org 1000H
table1 db 1, 2, 3
end_t1 db "F"; The value is not important here. We need the address instead.
aux db ?; An auxiliary variable to store the converted ASCII value.
org 3000h
; Prints any table that has been moved to register bx.
print_table:
mov dx, bx; Using dx as auxiliar register
mov ah, [bx]
add ah, 48; Converts to ASCII by adding 48 (30h - zero value in ASCII)
mov aux, ah
mov al, 1
mov bx, offset aux
int 7; Prints the character in screen
mov bx, dx; Restores bx to the original value
inc bx
cmp bx, offset end_t1; Checks if we have reached the end of the table
jnz print_table; Loops back if not to print the next character in the table
ret
org 2000H
mov bx, offset table1
call print_table
int 0
end
这里的技巧是使用DX寄存器来临时存储BX的初始值。 我面临的问题是 BX 在稍后执行代码时被
aux
变量更改。这个用于存储ascii值加零的结果,这样我们就可以得到数字的ascii值。
如果没有 DX 且仅使用 BX,则可以正确打印表格的第一个字符,但不能正确打印另一个字符,因为我们已经知道 BX 已被其他值修改。