Write the operating system to a floppy disk and open the operating system in a floppy disk boot. Reboot the computer, boot the existing operating system, and display and set the clock (the so-called operating system). The debug phase is completed under Vmware+msdos.
Experimental tips:
1, in order to facilitate our experiments under the virtual machine, I choose VMware;
2, for debugging convenience we install MS-DOS 7.10 (with Debug), download address: http://www.onlinedown.net/soft/2465.htm;
3, download and install masm6.11 (including MASM and link), download address: http://ishare.iask.sina.com.cn/f/11460493.html?from=like;
4, to the virtual host of the DOS file can choose between CD-ROM and floppy disk. Can be made with UltraISO. Download address: http://www.crsky.com/soft/1134.html;
5, in order to select the floppy boot we can allow the virtual machine delay into the operating system. Open MS-DOS.VMX, add bios.bootdelay = "10000"
Effect Chart:
Here's all the code:
Assume cs:code code segment installation program Start:mov AX,CS mov es,ax mov bx,offset SEC1 mov ah,3
MOV al,9 mov ch,0 mov cl,1 mov dl,0 mov dh,0 int 13h mov ax,4c00h
int 21h; First sector, reading second sector to 0:7e00h SEC1: mov ax,0, mov es,ax, mov bx,7e00h mov ax,1000h
MOV es,ax mov bx,7e00h mov ah,2 mov al,9 mov ch,0 mov-mov cl,2 mov dl,0 int 13h; jump to dh,0
; mov ax,0;p ush ax; mov ax,7e00h;p ush ax; RETF mov ax,1000h push ax
mov ax,7e00h push ax RETF db 512-($-SEC1)-2 dup (0) DW 0aa55h; second sector sec2:jmp Sec2start:
DB ' ***************************************************** ' db ' * * * Press 1 to restart system * * * DB ' * * * Press 2 to start current system * * * * * * * * * * * * Press 3 to start clock * * * db ' * * * Press 4 to Setting Clock * * db ' ***************************************************** ' err_not_support_op:db ' not
Support operation! ' opt:db 0; receive input variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
Newline,showstr,get_str use of the method see:;; ;;
http://blog.csdn.net/xiaodao1986/article/details/6724050;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; , wrapping (next line of current line) Newline:push AX push BX push CX push DX mov ah,03h mov bh,0 int 10h cmp dh,24 JB Incrow mov Ah , 06h mov al,1 mov bh,07h mov ch,0 mov cl,0 mov dh,24 mov dl,80 int 10h jmp Changerow incrow : inc DH Changerow:mov ah,2 mov bh,0 mov dl,0 int 10h nrtn:pop DX pop cx pop AX ret; display string in Current line (80*25 @param ds:si-variable address; @param CX-Variable length showstr:push AX push BX push CX push DX push es push di push si push CX mov ah,03h mov bh,0 int 10h pop CX mov ax,0b800h mov es,ax moval,160 mul DH mov di,ax mov bx,0 mov dl,0 s:mov al,ds:[si] cmp al,0 jne _if mov byte ptr es:[bx+di], ' jmp sho RT _endif _if:mov Byte PTR es:[bx+di],al inc DL _endif:inc si add bx,2 loop s mov ah,2 mov bh,0 int 10h PO P si pop di pop es pop dx pop cx pops bx pop AX ret; get user input; @param ds:si-variable address; @param CX-Variable length Get_str:push AX push BX push cx push DX push SI mov bx,si mov dx,0 push cx push si S1:mov byte ptr ds:[si],0 inc si Lo Op s1 pop si pop cx get:mov ah,0 int 16h cmp ah,1ch JE gtrn cmp ah,0eh JE delchar cmp dx,cx jnb get mov byt E PTR Ds:[si],al Inc si Inc DX JMP gshowstr delchar:cmp si,bx jna get Dec si Dec DX mov-ptr-ds:[si],0 jmp GS
Howstr gshowstr:push SI mov si,bx call showstr pops si jmp get gtrn:call newline pop si pop dx pop cx Pop AX ret; subroutine one: Restart computer Resetpc:mov AX,0FFFFH push AX mov ax,0 push ax RETF subroutine two: Boot existing system Startsys:mov ax,0 MOV Es,ax mov bx,7c00h mOV ah,2 mov al,1 mov ch,0 mov cl,1 mov dh,0 mov dl,80h int 13h mov ax,0 push ax mov ax,7c00h PU
SH ax RETF; subroutine three: Clock program; Clock program, press ESC to exit; @param cl-line; @param CH-column clock:jmp clockstart table:db 9,8,7,4,2,0 timestr: DB 0,0, '/', 0,0, '/', 0,0, ', 0,0, ': ', 0,0, ': ', 0,0 clockstart:push AX push BX push cx push DX push si push di push DS Push es call {1}3 ofst:pop ax; IP mov bx,ofst-table sub AX,BX mov si,ax mov/mov ax,cs mov ds,ax add
di,6 for_clock:push si push di push cx mov cl,4 mov ch,0 for_clock2:mov al,ds:[si] mov dx,70h out dx,al
In AL,71H mov ah,al shr ah,cl add ah,30h mov byte ptr ds:[di],ah inc di
and al,00001111b add al,30h mov byte ptr ds:[di],al add di,2 Inc SI Inc CH
CMP ch,6 JE show_time jmp for_clock2 show_time:pop cx pop di pop si Push Si push di
Push CX mov ax,0b800h mov es,ax mov si,di mov al,160 mul CL mov di,ax mov al,2 mul ch Add di,ax mov cx,17 for_getchr:mov al,ds:[si] mov ah,07h mov es:[di],ax inc si add di,2 loop for_getchr pop cx p Op di pop si check:in al,60h cmp al,01h JE clockrtn jmp for_clock es pop DS pop di pop si pop dx pop cx pops bx pop AX ret; subroutine IV: Setting Clock setclock:jmp scstart var_sc_time:db dup (0) sc_tip:db ' Set time with format $/$/$ $:$:$,eg.11/09/05 11:14:20 ' s C_TABLE:DB 9,8,7,4,2,0 Scstart:push ax push DS push bx push si push di push cx push dx; dynamic settings Ds,si,di call SC OFST scofst:pop ax; IP mov bx,scofst-var_sc_time sub ax,bx mov si,ax mov di,ax mov/mov ax,cs; show prompt string M OV Cx,sc_table-sc_tip Add si,sc_tip-var_sc_time call showstr call newline; get user input mov Si,di mov cx,sc_tip-va
R_sc_time Call Get_str
; Process user input add Si,sc_table-var_sc_time mov cx,6 For_sc:mov word ptr dx,ds:[di] mov al,ds:[si] Push CX Sub dl,30h MOV cl,4 SHL dl,cl Sub dh,30h or dh,dl out 70h,al mov al,dh out 71h,al pop CX inc si add di,3 loop for_sc pop DX pop cx pop di pop si pops bx pop ds pop AX ret; main program Sec2start:; mov ax,0 mov ax,1000 H mov ds,ax mov cx,53 mov si,7e00h + offset intro-offset SEC2 mov bl,6; show Instructions For_intro:call showstr cal L newline add si,53 Dec BL cmp bl,0 JE end_for_intro jmp for_intro end_for_intro:; get user input mov si,7e00h + O Ffset opt-offset SEC2 mov cx,1 call get_str = 1, restart computer cmp byte ptr ds:[si],31h je; = 2, boot existing system CMP b
Yte ptr ds:[si],32h JE startsys = 3, enter clock program cmp byte ptr ds:[si],33h JE, call_clock = 4, set the clock cmp byte ptr ds:[si],34h je call_setclock, do not support user input operation, display error message, and wait for user's next input mov si,7 e00h + offset Err_not_suPport_op-offset SEC2 mov cx,22 call showstr call newline jmp end_for_intro Call_clock:mov cl,8 mov ch,60 Call Clock jmp end_for_intro call_setclock:call setclock jmp The code End_for_intro end s Tart