王爽汇编语言课设二,简单实现

简单说明:

1、引导程序装入0:7c00h

2、主程序装入0:7e00h

 

 

assume	cs:code
code segment
start1:
	mov ax,cs
	mov es,ax
	mov bx,offset start

	mov al,17
	mov ch,0
	mov cl,2
	mov dh,0
	mov dl,0

	mov ah,3
	int 13h

	mov bx,offset guide

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

	mov ax,4c00h
	int 21h

start:
s:	call clean
	call showfun
	call chose
	jmp short s

;display the function list

showfun:

jmp short showfun1

fun0 db 'Please input a number to chose functions!','$'
fun1 db '1) reset pc    ','$'
fun2 db '2) start system','$'
fun3 db '3) clock       ','$'
fun4 db '4) set clock   ','$'

showfun1:
	push ax
	push cx
	push es
	push si
	push bp
	push di

	mov ax,0b800h
    mov es,ax
	mov di,160*11+36*2
	mov bp,0
	mov cx,4
    mov si,offset fun1-offset start+7e00h

showfun2:
	mov al,cs:[si]
	cmp al,'$'
	je showfun3
	mov es:[di].[bp],al
	add bp,2
	inc si
	jmp short showfun2
showfun3:
	mov bp,0
	inc si
	add di,160
	loop showfun2

    mov si,offset fun0-offset start+7e00h
	mov di,9*160+26*2
	mov bp,0

showfun4:
	mov al,cs:[si]
	cmp al,'$'
	je showret
	mov es:[di].[bp],al
	mov byte ptr es:[di].[bp].1,02
	add bp,2
	inc si
	jmp showfun4
		
showret:
	pop di
	pop bp
	pop si
	pop es
	pop cx
	pop ax
	ret

;clean screen

clean:
	push ax
	push es
	push bx
	push cx
	push dx

	mov ax,0b800h
	mov es,ax
	mov bx,0
	mov cx,2000
	mov dx,0700h
cleans:
	mov es:[bx],dx
	add bx,2
	loop cleans

	pop dx
	pop cx
	pop bx
	pop es
	pop ax
	ret

;chose function and call

chose:
	push ax
chose_s:
	    mov ah,0
        int 16h

        cmp al,'1'
        jne chose1
        call funs1
        jmp choseok
chose1:
        cmp  al,'2'
        jne chose2
        call funs2
        jmp choseok
chose2:
        cmp al,'3'
        jne chose3
        call funs3
        jmp short choseok
chose3:
        cmp al,'4'
        jne chose_s
        call funs4
        jmp short choseok

 choseok:
	pop ax
	ret

;subprogram 1:	restart system

funs1:
	mov ax,0ffffh
	push ax
	mov ax,0
	push ax
	retf

;subprogram 2:	start existing system

funs2:
	mov ax,0
	mov es,ax
    mov bx,7c00h

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

	mov ax,0
	push ax
	mov ax,7c00h
	push ax
	retf

;subprogram 3:	display clock circularly
;input F1 to change the clock' colar
;input ESC to back the function list

funs3:
	push es
	push si
	push di
	push ax
	push bx
	push cx
	push dx

	mov dl,1

jmp short funs3s0

timer db '  ::::::: ','$'
s0	db 9,8,7,4,2,0

funs3s0:

	mov si,offset timer-offset start+7e00h
	mov di,offset s0-offset start+7e00h

	mov ax,0
	mov bx,0
	mov cx,6

funs3s1:	
	push cx
    mov bl,cs:[di]

	cmp bl,4
	jne funs3s2
	inc si

funs3s2:	
	mov al,bl
	out 70h,al
	in al,71h
	
	mov ah,al
	mov cl,4
	shr ah,cl
	and al,00001111b

	add ah,30h
	add al,30h

	mov cs:[si],ah
	inc si
	mov cs:[si],al
	add si,2

	inc di
	pop cx
	loop funs3s1

	mov ax,0b800h
	mov es,ax
	mov bx,20*160+30*2
    mov di,offset timer-offset start+7e00h

funs3s5:	
	mov al,cs:[di]
	cmp al,'$'
	je funs3ok
	mov es:[bx],al
	mov es:[bx].1,dl
	add bx,2
	inc di
	jmp short funs3s5

funs3ok:
	mov ah,1
	int 16h

	call delete

	cmp ah,3bh
	je funs3s6
    cmp al,1bh
	je funs3s7
	call delete
	jmp  funs3s0

funs3s6:
	inc dl
	jmp funs3s0

funs3s7:
	pop dx
	pop cx
	pop bx
	pop ax
	pop di
	pop si
	pop es
	ret

;subprogram 4:	set the clock and 

funs4:
	push ax
	push dx

	call funs4s1
	mov dh,19
	mov dl,35
	call getstr
	call setclock
	call funs4s2
	
funs444:
mov ax,0
	mov ah,0
	int 16h

	cmp ah,01h
	je funs44
	jmp short funs444

funs44:
	pop dx
	pop ax
	ret

;subprogram :	reset the keyboard buffer

delete:
	push ax
	push es
	push bx

	mov ax,0040h
	mov es,ax
	mov bx,1ah
	mov byte ptr es:[bx],1eh
	mov byte ptr es:[bx].1,0
	mov byte ptr es:[bx].2,1eh
	mov byte ptr es:[bx].3,0

	pop bx
	pop es
	pop ax
	ret

;push,pop and display the characters
;(ah)=functions number,0 is push,1 is pop,2 is display
;ds:si=space of characters' stack
;for functions 0---(al)=the character to push
;for functions 1---(al)=the return character
;for functions 2---(dh)、(dl)=the row and column locations of displaing characters
;push two '$' after input Enter as the end of buffer

charstack:
	jmp short charstart

top dw 0			;top of stack

charstart:
	push bx
	push dx
	push di
	push es
	push cx

	cmp ah,2
	ja sret
	cmp ah,0
	jne char1
	jmp charpush
char1:
	cmp ah,1
	jne char2
	jmp charpop
char2:
	jmp charshow
charpush:
    mov bx,offset top-offset start+7e00h
	mov cx,cs:[bx]
	mov bx,cx
	mov [si][bx],al
	mov bx,offset top-offset start+7e00h
	inc cx
	mov cs:[bx],cx
	jmp sret

charpop:
	mov bx,offset top-offset start+7e00h
	mov cx,cs:[bx]
	cmp cx,0
	je sret
	dec cx
	mov cs:[bx],cx
	jmp sret

charshow:
	mov bx,0b800h
	mov es,bx
	mov al,160
	mov ah,0
	mul dh
	mov di,ax
	add dl,dl
	mov dh,0
	add di,dx
	mov bx,0
charshows:
	push bx
    mov bx,offset top-offset start+7e00h
	mov cx,cs:[bx]
	pop bx
	cmp bx,cx
	jne noempty
	mov byte ptr es:[di],' '
	jmp sret
noempty:
	mov al,[si][bx]
	mov es:[di],al
	mov byte ptr es:[di+2],' '
	inc bx
	add di,2
	jmp charshows

sret:
	pop cx
	pop es
	pop di
	pop dx
	pop bx
	ret

getstr:
	push ax
	push cx
    push ds
    push si

    push bx
    mov bx,offset top -offset start+7e00h
    mov word ptr cs:[bx],0
    pop bx

    call clbuff
	mov cx,0
	mov ax,0
	mov ds,ax
	mov ax,200h
	mov si,ax
getstrs:
    mov ax,0
	mov ah,0
	int 16h

    call delete        ;reset keyboard buffer

	cmp cx,12
    jnb nochar

    cmp al,'0' 
	jb nochar
    cmp al,'9'
    ja nochar          ;ASCII code must be between 0 and 9

	inc cx
	mov ah,0		;char push
	call charstack
	mov ah,2		;display the characters on stack
	call charstack
	jmp getstrs

nochar:
    cmp ah,0eh              ;scanning code for backspace key
	je backspace
	cmp ah,1ch		;scanning code for Enter key
	je enter
	jmp getstrs

backspace:
    cmp cx,0
    je getstrs
	dec cx
	mov ah,1		;character pop
	call charstack
	mov ah,2		;display the characters on stack
	call charstack
	jmp getstrs

enter:
	mov al,'$'
	mov ah,0
	call charstack	;push the $
    mov al,'$'
    mov ah,0
    call charstack

    pop si
    pop ds
    pop cx
	pop ax
	ret

funs4s1:
	jmp short funs4s3
funs4s0 db 'input as "190604151717",press Enter to return, Esc to back','$'

funs4s3:
	push es
	push ax
	push bx
	push si
	push di

	mov ax,0b800h
	mov es,ax
	mov ax,18*160+10*2
	mov di,ax
	mov bx,0
    mov si,funs4s0-offset start+7e00h

funs4s4:
	mov al,cs:[si].[bx]
	cmp al,'$'
	je funs4s5
	mov es:[di],al
	mov byte ptr es:[di].1,04
	add di,2
	inc bx
	jmp short funs4s4

funs4s5:
	pop di
	pop si
	pop bx
	pop ax
	pop es
	ret

funs4s2:
		jmp short funs4s6

funs4ss0 db 'You have changed the time!!!','$'

funs4s6:
	push es
	push ax
	push bx
	push si
	push di

	mov ax,0b800h
	mov es,ax
	mov ax,21*160+25*2
	mov di,ax
	mov bx,0
    mov si,funs4ss0-offset start+7e00h

funs4s8:
	mov al,cs:[si].[bx]
	cmp al,'$'
	je funs4s7
	mov es:[di],al
	mov byte ptr es:[di].1,04
	add di,2
	inc bx
	jmp short funs4s8

funs4s7:
	pop di
	pop si
	pop bx
	pop ax
	pop es
	ret

setclock:

	jmp short set0

clockrow db 9,8,7,4,2,0 

set0:
	push es
	push si
	push ax
	push bx
	push di
        push cx
        mov ax,0
        mov es,ax
        mov ax,200h
        mov si,ax      ;es:[si]---0:200h 
	mov di,offset clockrow-offset start+7e00h
	mov ax,0
	mov bx,0
        mov cx,4
        
set1:
	mov ah,es:[si]
        mov al,es:[si].1
        cmp ah,'$'
        je set2
        cmp al,'$'
        jne set3
        mov al,30h
set3:
	sub ah,30h
    sub al,30h
        shl ah,cl
	add ah,al
	mov al,cs:[di].[bx]
	out 70h,al
	mov al,ah
	out 71h,al

	inc bx
        add si,2
        jmp short set1

set2:
       pop cx
	pop di
	pop bx
	pop ax
	pop si
	pop es
	ret
clbuff:
        push es
        push ax
        push si

        push cx

        mov ax,0
        mov es,ax
        mov ax,200h
        mov si,ax
        mov cx,20h
clbuff1:
        mov byte ptr es:[si],' '
        inc si
        loop clbuff1
       
	   pop cx
        pop si
        pop ax
        pop es
        ret

guide:
	mov ax,0
	mov es,ax
	mov bx,7e00h

	mov al,17
	mov ch,0
	mov cl,2
	mov dh,0
	mov dl,0

	mov ah,2
	int 13h

	mov ax,0
	push ax
	mov ax,7e00h
	push ax
	retf

code ends
end start1

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值