王爽汇编语言课程设计2 个人学习笔记(附源码)

程序功能:

1)reset pc 重新启动计算机
2)start system 引导现有的操作系统
3)clock 进入时钟程序
4)set clock 设置时间

用户输入1后重新启动计算机
用户输入2后引导操作系统(考虑硬盘C的0道0面1扇区)
用户输入3后,执行动态显示当前日期、时间的程序(显示格式:年/月/日 时:分:秒 循环读取CMOS)进入此功能一直动态显示当前时间,在屏幕上按秒变化的效果

实验截图:

开机时,显示的功能选项
王爽汇编语言课程设计2 个人学习笔记(附源码)_第1张图片
输入3,显示当前时间(按下F1后,改变显示颜色;按下esc后返回主选单)
王爽汇编语言课程设计2 个人学习笔记(附源码)_第2张图片
王爽汇编语言课程设计2 个人学习笔记(附源码)_第3张图片
输入4后,更改当前的日期和时间
王爽汇编语言课程设计2 个人学习笔记(附源码)_第4张图片

实验思路:

编写启动代码则需要让执行代码放入软盘内让int19进行引导,根据BIOS的安装过程
,再有就是
1.软盘启动操作系统,int19h会控制0号软驱,读取软盘0道0面1扇区的内容到0:7c00;
2.CS:IP指向0:7c00
所以这里我们需要将引导代码和程序启动代码(安装代码:引导代码、程序启动代码)放到软盘内,并且引导代码作用是为了读取程序启动代码到引导引导结束后的CS:IP处

实验代码:

assume cs:code,es:date

date segment
因为每个扇区是512个字节,所以我在date段开辟了5个扇区大小的内存空间,用来存放程序代码,方便后来的软盘写入
s	    db 510 dup(0)
		dw 0aa55h
x		db 512 dup(0)
		db 512 dup(0)
		db 512 dup(0)
		db 512 dup(0)
date ends

code segment
start:     	mov ax,cs
			mov ds,ax
			mov ax,date
			mov es,ax

			mov si,offset A
			mov di,offset s
			mov cx,offset Aend-offset A
			cld
			rep movsb

			mov di,offset x
			mov si,offset B
			mov cx,offset Bend-offset B
			cld
			rep movsb
			
		 es:bx指向存放引导代码的位置
			mov ax,date              
			mov es,ax
			mov bx,offset s
		
		将引导代码写入0道0面1扇区
			mov dl,0					
			mov dh,0
			mov ch,0
			mov cl,1
			mov al,1
			mov ah,3
			int 13h
		
		es:bx指向存放执行代码的位置
			mov bx,offset x
		
		将执行代码写入0道0面2扇区(每个扇区的大小为512个字节)
			mov dl,0
			mov dh,0
			mov ch,0
			mov cl,2
			mov al,4
			mov ah,3
			int 13h

			mov ax,4c00h
			int 21h 
		
		A-Aend为引导代码	
A:		   mov ax,0
			mov es,ax
			mov bx,7e00h

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

			mov ax,0
			push ax
			mov ax,7e00h
			push ax
			retf
Aend:		nop	
		
		
		B-Bend为启动代码
			org 7e00h
B:		  	call menue
			call chose
			jmp B

func1		db '1) reset pc',0
func2		db '2) start system',0
func3		db '3) clock',0
func4		db '4) set clock',0
funip		dw func1
			dw func2
			dw func3
			dw func4

c			db 9,8,7,4,2,0
time		db '00/00/00 00:00:00',0
char		db'Please input number!',0
coloer		db 2
str			db 18 dup(0)

menue:		call cls
		
			mov bx,offset funip
			mov ax,cs
			mov ds,ax
			mov si,[bx]
			mov di,160*10+35*2
			mov dh,2
			mov cx,4
			
m1:			call showstr
			add di,160
			add bx,2
			mov si,[bx]
			loop m1
			ret
		
chose:		mov ax,0b800h
			mov es,ax
			mov ch,2

			mov ah,0
			int 16h	
			cmp al,'1'
			je fun1
			cmp al,'2'
			je fun2
			cmp al,'3'
			je fun3
			cmp al,'4'
			je fun4
			jmp chose
fun1:		mov di,160*9+40*2
			mov byte ptr es:[di],'1'
			mov es:[di+1],ch
			call rest
			
fun2:		mov di,160*9+40*2
			mov byte ptr es:[di],'2'
			mov es:[di+1],ch
			call startsystem
				
fun3:		mov di,160*9+40*2
			mov byte ptr es:[di],'3'
			mov es:[di+1],ch
			call clock
esc1:			jmp near ptr B

fun4:		mov di,160*9+40*2
			mov byte ptr es:[di],'4'
			mov es:[di+1],ch
			call setclock
			jmp near ptr B

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

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

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

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


			
setclock:	call cls
			mov ax,cs
			mov ds,ax
			mov di,13*160+35*2
			mov si,offset char
			mov dh,2
			mov ch,35
			call showstr			
			mov di,12*160+35*2
			mov si,offset time
			call showstr
			call getstr
			ret

getstr:		mov si,offset time
getstr1:	call int10_2
			call getnumber
			ret
			

int10_2:	push ax
			push bx
			push dx
			push cx
			mov ah,2
			mov bh,0
			mov dh,12
			mov dl,ch
			int 10h		
			pop cx
			pop dx
			pop bx
			pop ax
			ret

getnumber:	mov ax,cs
			mov ds,ax
			mov ax,0
			int 16h
					
			cmp ah,4bh
			je left
			cmp ah,4dh
			je right
			cmp al,'0'
			jb nonumber
			cmp al,'9'
			ja nonumber
			mov [si],al
			push si
			mov si,offset time
			call showstr
			pop si
			jmp getstr1
				
nonumber:	cmp ah,1ch
			je ent
			jmp getnumber

left:		cmp ch,35
			jna getstr1
			dec ch
			dec si
			jmp near ptr getstr1
right:		cmp ch,51
			jnb getstr1
			inc ch
			inc si
			jmp near ptr getstr1

			
ent:		mov cx,6
		mov di,offset c
			mov si,offset time
ent1:			mov ah,[si]
			inc si
			mov al,[si]
			mov bl,30h
			sub ah,bl
			sub al,bl
			shl ah,1
			shl ah,1
			shl ah,1
			shl ah,1
			or ah,al
			mov al,[di]
			out 70h,al
			mov al,ah
			out 71h,al
			inc di
			add si,2
			loop ent1
			
			ret



	
clock:		call setint9
cmos:		mov cx,6
			mov di,0
			mov si,0
cmos1:		push cx
			mov al,cs:c[si]
			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:time[di],ah
			mov cs:time[di+1],al
			inc si
			add di,3
			pop cx
			loop cmos1

			mov si,offset time
			mov di,160*17+50*2
			mov dh,cs:coloer
			mov ax,cs
			mov ds,ax

			call showstr
			jmp near ptr cmos

int9:		push ax
			push bx
			push es
			push si
			in al,60h
			pushf
			call dword ptr cs:[200h]
			
			cmp al,3bh
			je f1
			cmp al,01h
			je esc0
			jmp int9ret

int9ret:	pop si
			pop es
			pop bx
			pop ax
			iret

			
f1:			inc cs:coloer
			jmp int9ret

setint9:	push ax
			push es
			mov ax,0
			mov es,ax

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

			cli
			mov word ptr es:[4*9],offset int9
			mov word ptr es:[9*4+2],cs
			sti
			pop es
			pop ax
			ret

esc0:		pop si
			pop es
			pop bx
			pop ax
			add sp,4
			popf
			mov ax,0
			mov es,ax
			cli
			push es:[200h]
			pop es:[4*9]
			push es:[202h]
			pop es:[4*9+2]
			sti
			jmp near ptr esc1
		
 
cls:  		push ax
			push es
			push cx
			push si

			mov ax,0b800h
			mov es,ax
			mov cx,2000
			mov ah,7
			mov si,0
p:			mov byte ptr es:[si],' '
			mov es:[si+1],ah
			add si,2
			loop p

			pop si
			pop cx
			pop es
			pop ax
			ret

showstr:	push es
			push ax
			push si
			push di
			mov ax,0b800h
			mov es,ax
show1:		mov al,[si]
			cmp al,0
			je show2
			mov es:[di],al
			mov es:[di+1],dh
			add di,2
			inc si
			jmp show1

show2:		pop di
			pop si
			pop ax
			pop es
			ret

Bend:		nop


code ends
end start



	

	






你可能感兴趣的:(汇编笔记)