WEB开发网
开发学院软件开发汇编语言 自己编程实现多引导 阅读

自己编程实现多引导

 2009-10-12 09:36:44 来源:WEB开发网   
核心提示:模块一被写入到硬盘的第一个扇区中,在系统引导之前获得执行权,自己编程实现多引导(3),从而实现多引导,因为这是个扇区程序,从EXE文件中提取的方法来实现的,源程序如下:;多引导程序(SYSGUIDE.DAT),需要从以下源程序(模块一)产生的程序文件中提取CODE SEGMENTASSUME CS:CODE,DS:CO

模块一被写入到硬盘的第一个扇区中,在系统引导之前获得执行权,从而实现多引导。因为这是个扇区程序,有别于一般的程序文件,其格式类似于COM文件,在此我是采用DEBUG程序,从EXE文件中提取的方法来实现的,源程序如下:

;多引导程序(SYSGUIDE.DAT),需要从以下源程序(模块一)产生的程序文件中提取

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE
  ;这一段是将整个硬盘锁从0000:7c00移至0000:0600,以免被后来读入的代码覆盖
START:
db 256 dup (00h)
PUSHDS
PUSHES
MOVCX,0100h
MOVDI,0600h
MOVAX,0000h
MOVDS,AX
MOVES,AX
MOVSI,7C00h
REPNZ MOVSW
mov ax,0686h
JMPax ;长跳转至移动后的代码,也就是从screen处开始执行
words db 'Please choose the partition for guide.'
db 10 dup (20h)
db '(1)partition 1;(2)partition 2;(3)partition 3;(4)partition 4;',00h
screen:
MOVAX,0600h
MOVBH,0F0h
MOVCX,0000h
MOVDX,184Fh
INT10h ;初始化屏幕(前景为黑色,背景为灰白,字符闪烁)
MOVDL,1Ah
MOVSI,0619h ;从0619H处显示字符(因为程序将被读入了0000:0600处,
;实际显示的也就是现在的words处开始的字符串)
DISPLAY:
MOV AH,02H
MOV DH,10H
MOV BH,00H
INT 10H
MOV AL,[SI]
CMP AL,00H
JE readMBS
MOV AH,09H
MOV CX,01H
MOV BH,00H
MOV BL,70H
INT 10H
INC DL
INC SI
JMP DISPLAY
readMBS:
MOVAX,0201h
MOVCX,0001h
MOVDX,0080h
MOVBX,1000h
INT13h ;将主引导区(即本SYSGUIDE.DAT)读出到0000:1000H处
MOV ax,0201h
MOV cx,0006h ;读0 0 6扇,(即原来的MBS)
MOV dx,0080h
MOV bX,07C00h
int 013h
readkey:
MOV AH,00H
INT 16H
CMP AL,'1' ;是1么?
JE number1
CMP AL,'2'
JE number2
CMP AL,'3'
JE number3
CMP AL,'4'
JE number4
jmp readkey
number1:
db 0a0h,0c2h,11h ;相当于mov al,[011c2h],因为用mov al,[011c2h]不能编译
cmp al,00h
je error1
cmp al,05h
je error1
cmp al,0fh
je error1
mov ah,080h
db 88h,26h,0beh,11h ;相当于mov [011beh],ah
mov ah,00h
db 88h,26h,0ceh,11h ;mov [11ceh],ah
db 88h,26h,0deh,11h ;mov [11deh],ah
db 88h,26h,0eeh,11h ;mov [11eeh],ah
jmp ok
number2:
db 0a0h,0d2h,11h ;mov al,[11d2h]
cmp al,00h
je error1
cmp al,05h
je error1
cmp al,0fh
je error1
mov ah,80h
db 88h,26h,0ceh,11h ;mov [11ceh],ah
mov ah,00h
db 88h,26h,0beh,11h ;mov [11beh],ah
db 88h,26h,0deh,11h ;mov [11deh],ah
db 88h,26h,0eeh,11h ;mov [11eeh],ah
jmp ok
  error1:
jmp readkey
  number3:
db 0a0h,0e2h,11h ;mov al,[11e2h]
cmp al,00h
je error1
cmp al,05h
je error1
cmp al,0fh
je error1
mov ah,80h
db 88h,26h,0deh,11h ;mov [11deh],ah
mov ah,00h
db 88h,26h,0beh,11h ;mov [11beh],ah
db 88h,26h,0ceh,11h ;mov [11ceh],ah
db 88h,26h,0eeh,11h ;mov [11eeh],ah
jmp ok
number4:
db 0a0h,0f2h,11h ;mov al,[11f2h]
cmp al,00h
je error1
cmp al,05h
je error1
cmp al,0fh
je error1
mov ah,80h
db 88h,26h,0eeh,11h ;mov [11eeh],ah
mov ah,00h
db 88h,26h,0ceh,11h ;mov [11ceh],ah
db 88h,26h,0deh,11h ;mov [11deh],ah
db 88h,26h,0beh,11h ;mov [11beh],ah
jmp ok
ok:
mov ax,0301h
mov cx,0001h
mov dx,0080h
mov bx,1000h
int 13h ; 将改变了引导标示的分区表,写回0 0 1扇
MOVCX,040h
MOVDI,7dbeh
MOVSI,11beh
REPNZ MOVSW
MOV ax,0301h
MOV cx,0006h ;将改变了引导标示的分区表,写回0 0 6扇
MOV dx,0080h
MOV bX,07C00h
int 013h
MOV bx,7c00h ;交执行权给0000:7C00处
JMP bx ;长跳转至原MBR代码处执行
  CODE ENDS
END START

上一页  1 2 3 4  下一页

Tags:自己 编程 实现

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接