【发布时间】:2024-01-04 02:40:01
【问题描述】:
我正在使用 nasm 在裸机 16 位实模式程序集上编写程序。我想休眠(暂停执行)x 毫秒,但我还没有找到方法。
编辑:这是我的代码。我想在每个字符输入到屏幕之间添加大约 0.3 秒的延迟。
[bits 16] ; use 16 bits
[org 0x7c00] ; sets the start address
init:
mov si, msg ; loads the address of "msg" into SI register
mov ah, 0x0e ; sets AH to 0xe (function teletype)
print_char:
lodsb ; loads the current byte from SI into AL and increments the address in SI
cmp al, 0 ; compares AL to zero
je done ; if AL == 0, jump to "done"
int 0x10 ; print to screen using function 0xe of interrupt 0x10
jmp print_char ; repeat with next byte
done:
hlt ; stop execution
msg: db "The quick brown fox jumps over the lazy dog.", 0 ; we need to explicitely put the zero byte here
times 510-($-$$) db 0 ; fill the output file with zeroes until 510 bytes are full
dw 0xaa55 ; magic number that tells the BIOS this is bootable
【问题讨论】:
-
有How to set 1 second time delay at assembly language 8086,但大多数答案都不是毫秒级的。或者您的意思是甚至不使用 BIOS 服务?您是在谈论具有(模拟)传统计时器芯片的 IBM-PC 兼容硬件吗? (或者复古系统上的真正芯片?)如果你想在现代 x86 上使用延迟循环,并启用中断,你应该像这个问答一样在 RDTSC 上旋转:How to calculate time for an asm delay loop on x86 linux?
-
系统是否有可编程间隔定时器?
-
既然您有可用的 BIOS(您已经在使用
int 0x10)并且您的延迟时间远远超过一毫秒,int 0x15/ah = 0x86应该完全符合要求,请参阅 @987654323 @在彼得的链接上。它也比现代系统或模拟器上的忙碌等待更有礼貌和省电; BIOS 可以停止 CPU,仿真器可以放弃时间片。