王爽汇编语言学习课程设计2

assume cs:code
code segment
start:
;////////////////////////////////////
;安装到软盘
	mov ax,cs
	mov es,ax

	mov bx,offset softset
	mov al,1
	mov ch,0
	mov cl,1
	mov dl,0
	mov dh,0
	mov ah,3
	int 13h

	mov bx,offset subs     ;//
        	mov al,2
	mov ch,0
	mov cl,2
	mov dl,0
	mov dh,0
	mov ah,3
	int 13h	


	mov ax,4c00h
	int 21h

;//////////////////////////////
;显示菜单主页面
softset:	jmp short intstart
	db "1) reset pc    0"
	db "2) start system0"
	db "3) clock       0"
	db "4) set clock   0"
                db 0,0,0    ;读取2-3扇区        安装9号中断           f1
intstart:	call clearscreen
	mov byte ptr cs:[7c44h],0
	mov ax,cs
	mov ds,ax
        	mov bx,2h+7c00h
	mov cx,4
	mov dh,11
        	mov dl,30 
           lp:	push cx
        	call showstring
	inc dh
	inc bx
	pop cx
	loop lp

          	mov bx,7c42h
        	mov al,cs:[bx]
	cmp al,0
	jne setint9h

	mov ax,0            ;将002软盘扇区读到0:7e00h处
        	mov es,ax
        	mov bx,7e00h
        	mov al,2
        	mov ch,0
                mov cl,2
        	mov dl,0
        	mov dh,0
        	mov ah,2
        	int 13h
	mov bx,7c42h       
        	mov byte ptr cs:[bx],1
	
setint9h:	mov bx,7e0bh
	mov al,cs:[bx]
	cmp al,0
	jne stop

	call inspect
	
  stop:  	mov ax,4c00h
	jmp short stop
	
clearscreen:push bx       ;清屏
	push cx
	push es
	push ax
	mov bx,0b800h
	mov es,bx
	mov bx,0
	mov cx,2000
	mov al,' '
	mov ah,00000111b
           s1: mov es:[bx],ax
	add bx,2
	loop s1
	pop ax
	pop es
	pop cx
	pop bx
	ret
showstring:push ax              ;显示菜单字符串
	push dx
	push bp
	push es

	mov ax,0b800h
	mov es,ax
	mov al,0a0h
	mul dh
	add dl,dl
	mov dh,0
	add ax,dx
	mov bp,ax
     column:          
        	mov al,ds:[bx]
        	cmp al,'0'
        	je showret 
	mov ah,05
	mov es:[bp],ax
	inc bx
	add bp,2
	jmp short column	
    showret:
	pop es
	pop bp
	pop dx
	pop ax
	ret
;///////////////////////////////////
;键盘中断
inspect:   
	push ax
	push es
	push cx
	
	push cs
	pop ds

	mov ax,0
 	mov es,ax

        	mov si,offset int9-offset softset+7c00h
	mov di,204h
	mov cx,offset int9end-offset int9
	cld
	rep movsb

	push es:[9*4]
	pop es:[200h]
	push es:[9*4+2]
	pop es:[202h]

	cli
	mov word ptr es:[9*4],204h
	mov word ptr es:[9*4+2],0
	sti
	pop cx
	pop es
	pop ax
        	ret
;////////////////////////////////
;九号中断安装及判断
int9:	push bp
	push bx
	push cx
        push ax
	in al,60h
	pushf
	call dword ptr cs:[200h]

	cmp al,1h
        	je isesc
	mov bx,7c43h
	mov cl,cs:[bx]
	cmp cl,0
	jne f1
     num:	cmp al,5h
	ja f1
	mov bx,7e00h
	mov bp,sp
        mov ss:[bp+8],bx
        f1:	mov bx,7c44h
	mov cl,cs:[bx]
	cmp cl,0
	je f2
	cmp al,3bh
	jne f2
	mov bx,7e0ah
	add byte ptr cs:[bx],1
        pop ax
        jmp short ret1
        f2:	cmp al,3ch
	jne int9ret
	push cs:[200h]
     	pop cs:[9*4]
         	push cs:[202h]
	pop cs:[9*4+2]
	jmp short int9ret
      isesc:  mov bx,7e0bh
	mov byte ptr cs:[bx],1
	mov bx,7c43h
	mov byte ptr cs:[bx],0
	mov bp,sp
	mov bx,7c00h
        mov ss:[bp+8],bx
int9ret:pop cx 
ret1:   pop cx
	pop bx
	pop bp
	iret
int9end:nop
    
;////////////////////////////////////
;功能子程序   
subs:	jmp short subsstart
        dw offset sub1-offset subs+7e00h,offset sub2-offset subs+7e00h,offset sub3-offset subs+7e00h,offset sub4-offset subs+7e00h
        db 1,0        ;颜色属性      判断九号中断是否要重装
subsstart: call clearscreen1
        	mov bx,0
        	mov ds,bx
	mov bl,al
	sub bl,2h
	add bl,bl
	mov bh,0
	add bx,7e02h
    blank:	mov ah,01h         ;清除缓冲区
	int 16h
	pushf
	pop cx
	and cx,0000000001000000b
	cmp cx,0
	jne execute
	mov ah,0
	int 16h
        	jmp short blank
   execute:	call word ptr ds:[bx]
	
clearscreen1:push bx       ;清屏
	push cx
	push es
	push ax
	mov bx,0b800h
	mov es,bx
	mov bx,0
	mov cx,2000
	mov al,' '
	mov ah,00000111b
           s2: mov es:[bx],ax
	add bx,2
	loop s2
	pop ax
	pop es
	pop cx
	pop bx
	ret
;功能子程序1
;/////////////////////////////////	
sub1:   	jmp short sub1start
        	dw 0,0
sub1start: mov ax,cs
        	mov ds,ax
                mov ax,0
                mov bx,offset sub1-offset subs+7e00h
                mov ds:[bx+2h],ax
                mov ax,0ffffh
                mov ds:[bx+4h],ax
                jmp dword ptr ds:[bx+2]
;功能子程序2
;//////////////////////////////
sub2:jmp short sub2start
	dw 0,0
sub2start:   
        	mov ax,0
        	mov es,ax
        	mov bx,7c00h

        	mov al,1
        	mov ch,0
        	mov cl,1
        	mov dl,80h
        	mov dh,0
        	mov ah,2
        	int 13h

        	mov ax,cs
        	mov ds,ax
	mov bx,offset sub2-offset subs+7e00h
        	mov ax,7c00h
        	mov ds:[bx+2h],ax
	mov ax,0
                mov ds:[bx+4h],ax
        	jmp dword ptr ds:[bx+2h]
;功能子程序3
;/////////////////////////////////////
sub3:	jmp short sub3start
	db 9,'/',8,'/',7,' ',4,':',2,':',0
sub3start: 
	mov bx,7c44h
	mov byte ptr cs:[bx],1
	mov bx,7c43h
	mov byte ptr cs:[bx],1
	mov dh,10
	mov dl,20
	mov bx,7c22h
	mov ax,offset showstring-offset softset+7c00h
	call ax

	mov al,0
        out 70h,al
       	in al,71h
	cmp al,ah
	jne one
	jmp short sub3start
        one: call clock
	mov ah,al
	jmp short sub3start
        	ret

clock:	push ax
	push bx
	push cx
	push si
	push es
	push bp
	push dx
	mov dh,14
	mov dl,30
	call getaddress
	mov si,bx
	mov bx,0b800h
         	mov es,bx
	mov bx,offset sub3-offset subs+7e00h
	add bx,1
	mov bp,7e0ah;
      	mov cx,11
clockshow:push cx
        	inc bx
	mov al,cs:[bx]
	cmp al,10
	jb showtime
	mov ah,cs:[bp]
	mov  es:[si],ax
	add si,2
timereturn:pop cx
        	loop clockshow
	pop dx
	pop bp
	pop es
	pop si
	pop cx
	pop bx
	pop ax
	ret

showtime:
	call deal
        	mov cl,ah
        	mov ah,cs:[bp]
        	mov es:[si+2],ax
        	mov al,cl
        	mov es:[si],ax    
	add si,4
	jmp short timereturn
deal:
	push cx  
        	out 70h,al
       	in al,71h  
       	mov ah,al
        	mov cl,4
        	shr ah,cl
        	and al,00001111b
        	add ah,30h
        	add al,30h
        	pop cx
       	ret

getaddress:push ax
	push dx
	mov al,0a0h
	mul dh
	mov bl,dl
	add bl,bl
	mov bh,0
	add bx,ax
	pop dx
	pop ax
	ret

sub4:	jmp short sub4start
	db 'y','m','d','h','m','s'
	db 0,2,4,7,8,9
sub4start:push dx
	push bx
        	push ax
	push es

	mov dh,10
	mov dl,20
	mov bx,7c32h
	mov ax,offset showstring-offset softset+7c00h
	call ax

	push cs:[200h]  ;还原九号中断例程
     	pop cs:[9*4]
         	push cs:[202h]
	pop cs:[9*4+2]

	mov dh,15
	mov dl,30
	call getaddress
	sub bx,2
	mov bp,bx
	mov ax,0b800h
	mov es,ax
        	mov bx,offset sub4-offset subs+7e02h
	mov cx,6
 setshow:	mov al,cs:[bx]
	mov ah,00001100b
	mov es:[bp],ax
	inc bx
	add bp,6
	loop setshow
	sub bp,4

    set:	mov ah,2
	mov bh,0
	int 10h
	    
	mov ah,0        ;0~9判断及处理
	int 16h
		    
judge1:	cmp al,30h
	jb judge2
	cmp al,39h
	ja judge2
	cmp dl,30
	jb set
	cmp dl,46
	ja set
	mov ah,9
	mov bl,00000111b
	mov bh,0
	mov cx,1
	int 10h
          nu:	inc dl
	call isinput
	jcxz set
	jmp short nu

judge2:	cmp ah,4bh
	je con1
	cmp ah,4dh
	je con2
	cmp ah,0eh
	je con3
	cmp ah,1ch
	je reserve
	jmp short set
    con1:	dec dl
	call isinput
	jcxz set
	jmp short con1
    con2:	inc dl
	call isinput
	jcxz set
	jmp short con2
    con3:	dec dl
	call isinput
	jcxz delete
	jmp short con3
   delete:	mov ah,2
	mov bh,0
	int 10h
	mov ah,9
	mov al,' '
	mov bl,00000111b
	mov bh,0
	mov cx,1
	int 10h
	jmp short set
reserve:        mov bx,offset sub4-offset subs+7e08h
	mov cx,6
alter:	push cx
	mov dh,es:[bp]
	mov dl,es:[bp+2]
	sub dx,3030h
	mov cl,4
	shl dh,cl
	add dh,dl
	mov al,cs:[bx]
	out 70h,al
	mov al,dh
	out 71h,al
	sub bp,6
	inc bx
	pop cx
        	loop alter

	mov bp,sp
        	mov ss:[bp+08h],7c00h
        	mov bx,7e0bh
        	mov byte ptr cs:[bx],0
	pop es
	pop ax
	pop bx
	pop dx
	ret
isinput:	push ax
	push dx
	push bx
	push es
	mov ax,0b800h
	mov es,ax
	mov al,0a0h
	mul dh
	mov bl,dl
	add bl,bl
	mov bh,0
	add bx,ax
	mov al,es:[bx+1]
	cmp al,00001100b
	jne no
	mov cx,1
	jmp short isret	
        no:	mov cx,0
isret:	pop es
	pop bx
	pop dx
	pop ax
	ret

code ends
end start

你可能感兴趣的:(王爽汇编语言学习课程设计2)