恼火的很 先放下
程序代码:
%define bootseg 0100h %define buffseg 09000h %define buffoffset 0200h %define fatseg 08000h org 0100h jmp short LABEL_START ; Start to boot. nop ; 这个 nop 不可少 ; 下面是 FAT12 磁盘的头 BS_OEMName DB 'ForrestY' ; OEM String, 必须 8 个字节 BPB_BytsPerSec DW 512 ; 每扇区字节数 BPB_SecPerClus DB 1 ; 每簇多少扇区 BPB_RsvdSecCnt DW 1 ; Boot 记录占用多少扇区 BPB_NumFATs DB 2 ; 共有多少 FAT 表 BPB_RootEntCnt DW 224 ; 根目录文件数最大值 BPB_TotSec16 DW 2880 ; 逻辑扇区总数 BPB_Media DB 0xF0 ; 媒体描述符 BPB_FATSz16 DW 9 ; 每FAT扇区数 BPB_SecPerTrk DW 18 ; 每磁道扇区数 BPB_NumHeads DW 2 ; 磁头数(面数) BPB_HiddSec DD 0 ; 隐藏扇区数 BPB_TotSec32 DD 0 ; 如果 wTotalSectorCount 是 0 由这个值记录扇区数 BS_DrvNum DB 0 ; 中断 13 的驱动器号 BS_Reserved1 DB 0 ; 未使用 BS_BootSig DB 29h ; 扩展引导标记 (29h) BS_VolID DD 0 ; 卷序列号 BS_VolLab DB 'Tinix0.01 '; 卷标, 必须 11 个字节 BS_FileSysType DB 'FAT12 ' ; 文件系统类型, 必须 8个字节 root_dir_sector equ 19 dir_sector_num equ 14 LABEL_START: mov ax,cs mov ss,ax mov ds,ax mov sp,buffoffset mov bp,buffoffset push 1 push buffseg push 0 push root_dir_sector read: call read_disk call cmpstr cmp ax,1 je load add byte[bp-8],1 cmp byte[bp-2],dir_sector_num jae notfindfile jmp read load: add sp,8 add di,15 sub sp,8 push word[es:di] push 0203h push 014h push 0 mov ah,0 mov bl,0 int 13h mov ax,[bp-4] mov cx,[bp-6] mov dh,[bp-8] mov bx,buffoffset int 13h mov ax,[bp-2] mov ax,[bp-2] add sp,6 zzyy: mov bx,12 mul bx mov bx,8 div bx add ax,buffoffset mov si,ax mov ax,[es:si] cmp dx,0 jne xxxz mov bx,0fh and bx,ax shr bx,8 shl ax,8 or ax,bx jmp mmm xxxz: mov bx,0f000h and bx,ax shl bx,12 and ax,0ffh shr ax,4 or ax,bx mmm: cmp ax,0ff8h jae endo cmp ax,0ff7h je huaikuai push ax jmp zzyy endo: mov si,bp mov dx,buffoffset xx23: sub si,2 push si mov ax,[es:si] cmp cx,sp je jmpbin push bp mov bp,sp push 1 push buffseg push dx call read_disk pop dx add sp,4 pop bp add dx,512 pop si jmp xx23 jmpbin: jmp [es:buffoffset] notfindfile: mov ax,cs mov es,ax mov cx,strlen2 mov dh,0 mov ax, BootMessage2 mov bp, ax ; CX = 串长度 mov ax, 01301h ; AH = 13, AL = 01h mov bx, 000ch ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮) mov dl, 0 int 10h pop bp ; 10h 号中断 huaikuai: jmp $ read_disk: mov ah,0 mov bl,0 int 13h mov ax,[bp-8] xor dx,dx mov bx,[BPB_SecPerTrk] div bx add dx,1 mov cl,dl push ax shl ax,1 mov ch,al pop ax and al,1 mov dh,al mov dl,0 mov ax,[bp-4] mov es,ax mov bx,[bp-6] xxx: mov al,[bp-2] mov ah,02h int 13 jc xxx ret cmpstr: mov di,buffoffset hhh: push di mov si,[search_str] mov cx,search_strlen cld REPE cmpsb jcxz find pop di add di,32 cmp di,512+buffoffset jae cmpend jmp hhh find: mov ax,1 jmp findend cmpend: mov ax,0 findend: ret BootMessage2 db "not find mode32.bin" strlen2 equ $-BootMessage2 BootMessage1 db "LOADING mode32.bin" strlen1 equ $-BootMessage1 search_str: db "MODE32 BIN",0 search_strlen equ $-search_str times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节 dw 0xaa55