前言
现在我们来阅读邓志老师的《x86/x64体系探索及编程》,边阅读边将其代码放到bochs中运行,然后观察bochs的CPU是如何来模拟的。现在我们来详细分析ex3-2目录里面的内容。
boot.asm 代码解读
自己在工作中经常看汇编代码,但是写汇编代码真的很少写过,我们现在一边分析着这段boot汇编代码一边回顾其如何编写。
; Int 19h 加载 sector 0 (MBR) 进入 BOOT_SEG 段, BOOT_SEG 定义为 0x7c00
org BOOT_SEG
start:
cli
; enable a20 line
FAST_A20_ENABLE
sti
; set BOOT_SEG environment
mov ax, cs
mov ds, ax
mov ss, ax
mov es, ax
mov sp, BOOT_SEG ; 设 stack 底为 BOOT_SEG
call clear_screen
mov si, hello
call print_message
mov si, 20 ; setup 模块在第20号扇区里
mov di, SETUP_SEG - 2
call load_module ; 使用 load_module() 读多个扇区
mov si, SETUP_SEG
call print_message
mov si, word [load_message_table + eax * 2]
call print_message
next:
jmp $
org 解读
The
bin
format provides an additional directive to the list given in chapter 7:ORG
. The function of theORG
directive is to specify the origin address which NASM will assume the program begins at when it is loaded into memory.For example, the following code will generate the longword
0x00000104
:</org 0x100 dd label label: