簡體   English   中英

匯編ORG指令如何計算偏移量?

[英]How does assembly ORG instruction calculate offset?

我正在嘗試創建一個簡單的 BIOS 引導扇區,為此我使用了 x86 匯編語言。 我發現整個引導過程中的內存布局看起來像本文下面的圖片。 我的想法是使用ORG匯編指令來通知匯編程序設置一個相對內存地址(在本例中為 0x7c00) 這樣我就不必為當場計算內存地址而煩惱。 匯編代碼如下所示:

[org 0x7C00]
    mov ah, 0x0e
    mov al, [0x09]    ;this is the offset of 'the_secret'
    int 0x10

the_secret:
    db "X"

    times 510 - ($-$$) db 0
    dw 0xaa55

問題是,當我將這段代碼匯編成二進制文件並啟動引導過程時,終端中沒有出現“X”。 我在這里犯的錯誤是什么?

在此處輸入圖像描述

最好讓匯編程序為您計算偏移量。

[org 0x7C00]
    xor ax,ax
    mov ds,ax


    mov ah, 0x0e
    mov al, [the_secret]  ;load the ascii code for 'X' into AL
    int 0x10

    JMP $    ;halt

the_secret:
    db "X"
    
    times 510 - ($-$$) db 0
    dw 0xaa55

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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