簡體   English   中英

popa 和 pusha 實際上是如何工作的?

[英]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 中刪除pushapopa並將其放在主文件中時,如下所示:

[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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM