[英]How does popa and pusha actually works?
我試圖從 scrath 編寫一個簡單的操作系統,但我遇到了一個問題。 我編寫了一個簡單的程序,它運行一個字符串並將其打印在屏幕上。
print_string:
pusha
cmp byte[bx], 0
je exit
mov ah, 0x0e
mov al, [bx]
int 0x10
inc bx
jmp print_string
exit:
mov ah, 0x0e
mov al, 13
int 0x10
mov al, 10
int 0x10
popa
ret
我將它包含在主文件中。
[org 0x7c00]
mov bx, hello
call print_string
mov bx, hi
call print_string
jmp $
%include "print_string.s"
hello:
db "Hello, World!",0
hi:
db "This is a test.",0
times 510-($-$$) db 0
dw 0xaa55
但出於某種原因,而不是打印Hello, World. This is a test.
Hello, World. This is a test.
它只是打印Hello World!
當我從 print_string.s 中刪除pusha
和popa
並將其放在主文件中時,如下所示:
[org 0x7c00]
mov bx, hello
pusha
call print_string
popa
mov bx, hi
pusha
call print_string
popa
jmp $
%include "print_string.s"
hello:
db "Hello, World!",0
hi:
db "This is a test.",0
times 510-($-$$) db 0
dw 0xaa55
它工作得很好。 為什么?
print_string
在循環中被調用,每次迭代都是pusha
。 但是對於多個pusha
只有一個popa
指令。 一個修復:
print_string:
pusha
next_char:
mov al, [bx]
or al, al
je exit
mov ah, 0x0e
int 0x10
inc bx
jmp next_char
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.