首先,你必须有一个软盘,当然也可以虚拟一个。我就是用一个名称为 WinVF.exe的软件虚拟了一个。还要准备一个虚拟机,比如VMware,当然也可用其它的,但一定要能支持软盘。
下面是我搜到的并自已改了一下的一段代码:
org 0x7c00 ; This is where BIOS loads the bootloader
; Execution begins here
entry:
jmp short begin ; jump over the DOS boot record data
; ----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM name & DOS version (8 chars)
brBPS DW 512 ; 000Bh - Bytes/sector
brSPC DB 1 ; 000Dh - Sectors/cluster
brResCount DW 1 ; 000Eh - Reserved (boot) sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSPH DW 18 ; 0018h - Sectors per track
brHPC DW 2 ; 001Ah - Number of Heads
brHidden DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig
brSerialNum DD 404418EAH ; 0027h - Volume serial number (random)
brLabel DB 'Joels disk ' ; 002Bh - Volume label (11 chars)
brFSID DB 'FAT12 ' ; 0036h - File System ID (8 chars)
;------------------------------------------------------------------------
; --------------------------------------------
; Boot program code begins here
; --------------------------------------------
; boot code begins at 0x003E
begin:
xor ax, ax ; zero out ax
mov ds, ax ; set data segment to base of RAM
mov ah,0x0
mov BX,0x03
int 0x16
call putstr ; print the message
hang:
jmp hang ; just loop forever.
; --------------------------------------------
; data for our program
; ---------------------------------------------
; Print a null-terminated string on the screen
; ---------------------------------------------
putstr:
or al, al ; Set zero flag if al=0
jz putstrd ; jump to putstrd if zero flag is set
mov ah, 0x0e ; video function 0Eh (print char)
mov bx, 0x0003 ; color
int 0x10
mov ah,0x0
mov BX,0x03
int 0x16
mov ah,0x02
ADD DL,1
CMP DL,20
JE mmx
JNE mmxx
mmx: ADD DH,1
mmxx :
int 0x10
jmp putstr
putstrd:
retn
;---------------------------------------------
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
times (512 - size - 2) db 0
db 0x55, 0xAA ;2 byte boot signature
把它拷到notepad中,以.asm格式命名,然后用Nasmw编绎一下,生成一.bin格式的文件,将这个文件写到你的虚拟软盘中(用DOS下的debug来写),然后在虚拟机中创建一个dos操作系统,插入虚拟软盘,运行之,你将看到结果。(结果很诡异,哈哈,被我实验的)
具体用到的命令如下:
打开命令窗口
nasmw -o h.bin h.asm
debug
-->n h.bin
-->L 0(将上面的文件加载到内存偏移地址0处)
-->d 0(查看上面的操作有没有成功)
->w 0 0 0 1(写到软盘的第一个扇区)
下面是我搜到的并自已改了一下的一段代码:
org 0x7c00 ; This is where BIOS loads the bootloader
; Execution begins here
entry:
jmp short begin ; jump over the DOS boot record data
; ----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM name & DOS version (8 chars)
brBPS DW 512 ; 000Bh - Bytes/sector
brSPC DB 1 ; 000Dh - Sectors/cluster
brResCount DW 1 ; 000Eh - Reserved (boot) sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSPH DW 18 ; 0018h - Sectors per track
brHPC DW 2 ; 001Ah - Number of Heads
brHidden DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig
brSerialNum DD 404418EAH ; 0027h - Volume serial number (random)
brLabel DB 'Joels disk ' ; 002Bh - Volume label (11 chars)
brFSID DB 'FAT12 ' ; 0036h - File System ID (8 chars)
;------------------------------------------------------------------------
; --------------------------------------------
; Boot program code begins here
; --------------------------------------------
; boot code begins at 0x003E
begin:
xor ax, ax ; zero out ax
mov ds, ax ; set data segment to base of RAM
mov ah,0x0
mov BX,0x03
int 0x16
call putstr ; print the message
hang:
jmp hang ; just loop forever.
; --------------------------------------------
; data for our program
; ---------------------------------------------
; Print a null-terminated string on the screen
; ---------------------------------------------
putstr:
or al, al ; Set zero flag if al=0
jz putstrd ; jump to putstrd if zero flag is set
mov ah, 0x0e ; video function 0Eh (print char)
mov bx, 0x0003 ; color
int 0x10
mov ah,0x0
mov BX,0x03
int 0x16
mov ah,0x02
ADD DL,1
CMP DL,20
JE mmx
JNE mmxx
mmx: ADD DH,1
mmxx :
int 0x10
jmp putstr
putstrd:
retn
;---------------------------------------------
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
times (512 - size - 2) db 0
db 0x55, 0xAA ;2 byte boot signature
把它拷到notepad中,以.asm格式命名,然后用Nasmw编绎一下,生成一.bin格式的文件,将这个文件写到你的虚拟软盘中(用DOS下的debug来写),然后在虚拟机中创建一个dos操作系统,插入虚拟软盘,运行之,你将看到结果。(结果很诡异,哈哈,被我实验的)
具体用到的命令如下:
打开命令窗口
nasmw -o h.bin h.asm
debug
-->n h.bin
-->L 0(将上面的文件加载到内存偏移地址0处)
-->d 0(查看上面的操作有没有成功)
->w 0 0 0 1(写到软盘的第一个扇区)