;;; Bootsector to erase MBR ;;; Compile with: as86 -b erase-mbr.o -s erase-mbr.sym erase-mbr.s ;;; Copyright (c) 2009, Arnaud Giersch use16 .org 0x7c00 start: xor ax, ax mov ds, ax mov es, ax mov bp, #str_message call puts ;; clear 512 bytes xor ax, ax mov di, #(endflag + 2) mov cx, #256 cld rep stosw ;; erase MBR mov ax, #0x0301 mov dx, #0x0080 mov cx, #0x0001 mov bx, #(endflag + 2) int 0x13 jc error mov bp, #str_done call puts jmp clrkb error: mov bx, ax shr ax, #12 shr bx, #8 and bx, #0x000f cld mov di, #error_code mov si, #hex_digits add si, ax movsb mov si, #hex_digits add si, bx movsb mov bp, #str_error call puts clrkb: ;; clear keyboard buffer mov ah, #0x01 int 0x16 jz clrkb_end mov ah, #0x00 int 0x16 jmp clrkb clrkb_end: ;; wait for any key mov bp, #str_reboot call puts mov ah, #0x00 int 0x16 ;; reboot mov ax, #0x0040 mov es, ax mov di, #0x0072 mov ax, #0x0000 stosw jmp 0xffff:0000 ;;; INPUT ;;; es:bp asciz string address ;;; OUTPUT ;;; string is printed on screen ;;; MODIFIED ;;; ax, bx, cx, dx, di puts: ;; current screen page -> bh mov ah, #0x0f int 0x10 ;; cursor position -> dh:dl mov ah, #0x03 int 0x10 ;; compute string length mov di, bp mov al, #0 mov cx, #0xffff cld repne scasb neg cx add cx, #0xfffe ;; print string mov bl, #0x07 mov ax, #0x1301 int 0x10 ret ;;; DATA hex_digits: .ascii "0123456789ABCDEF" str_message: .asciz "Erasing partition table..." str_done: .asciz " done.\n\r" str_error: .ascii " ERROR " error_code: .ascii "??" .asciz ".\n\r" str_reboot: .asciz "Press any key to reboot.\n\r" padding: .space (512 - 2) - (padding - start) endflag: dw 0xaa55