很奇怪当年写代码怎么就可以潇洒到一句注释都不写?查了一下手册才记起来,当年为了能在C盘和D盘的两个操作系统间自由切换引导才写了这东东,用途是启动系统时按住右CTRL键自动切换为第二主分区引导系统,按住SHIFT键则直接跳过硬盘引导。
code segment
assume cs:code
org 100h
start:
push cs
pop ds
push cs
pop es
mov ax, 201h
mov cx, 1
mov dx, 80h
mov bx, offset buffer
int 13h
jc err
xor ax, ax
mov cx, 0e0h
mov di, offset buffer
rep stosw
mov si, offset MbrBegin
mov di, offset buffer
mov cx, (MbrEnd - MbrBegin + 1) shr 1
rep movsw
mov ax, 301h
mov cx, 1
mov dx, 80h
mov bx, offset buffer
int 13h
err:
mov ax, 4c00h
int 21h
buffer db 200h dup (0)
org 600h
MbrBegin:
xor cx, cx
mov ss, cx
mov sp, 7c00h
sti
mov ds, cx
mov es, cx
cld
mov si, 7c1ah
mov di, 061ah
push cx
push di
mov cl, 0f3h
rep movsw
retf
mov ax, ds:[417h]
test ax, 00001000b
jnz extboot
test ax, 00000011b
jnz mbret
test ax, 00000100b
jz mainboot
mov bp, 07ceh
mov byte ptr [bp], 80h
jmp check
extboot:
mov ax, 202h
mov cx, 2
mov dx, 80h
mov bx, 7c00h
jmp callint
mainboot:
xor ax, ax
mov si, 07beh
mov cl, 4
loopfind:
cmp [si], ch
jz $ + 5
mov bp, si
inc ax
add si, 10h
loop loopfind
dec ax
jz check
jnl error1
mbret:
int 18h
check:
mov dx, [bp]
cmp dl, 80h
jnz error1
diskread:
mov ah, 41h
mov bx, 55aah
int 13h
cmp bx, 0aa55h
mov bx, 7c00h
jnz diskread2
shr cl, 1
jnc diskread2
xor ax, ax
push ax ;+e
push ax ;+c
push word ptr [bp + 0ah] ;+a
push word ptr [bp + 8] ;+8
push ax ;+6
push bx ;+4
inc ax
push ax ;+2
mov al, 10h
push ax ;+0
mov si, sp
mov ah, 42h
jmp callint
error1:
mov si, offset msg1
jmp $ + 5
error2:
mov si, offset msg2
jmp $ + 5
error3:
mov si, offset msg3
call print
jmp $
diskread2:
mov ax, 201h
mov cx, [bp + 2]
callint:
int 13h
jc error2
cmp word ptr ds:[7dfeh], 0aa55h
jnz error3
db 0eah, 00h, 7ch, 00h, 00h ;jmp 0000:7c00
loopprint:
mov ah, 0eh
mov bx, 0007h
int 10h
print:
lodsb
test al, al
jnz loopprint
ret
msg1 db "Invalid partition table", 0
msg2 db "Error loading operating system", 0
msg3 db "Missing operating system", 0, 0
MbrEnd:
code ends
end start