现在的位置: 首页 > 综合 > 正文

(2011.11.04)汇编_王爽_第14章_学习小结

2013年12月11日 ⁄ 综合 ⁄ 共 4515字 ⁄ 字号 评论关闭

  

(2011.11.04)汇编_王爽_第14章_学习小结

本章内容:

1. 端口的读写

2.CMOS RAM芯片的访问读写

3. shl,shr位移指令

 

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

 

; 程序名称:1404_CMOS_RAM中存储的时间信息.asm
; 程序功能:在屏幕中间显示当前的月份

; 程序开始
;-----------------------------------------------------------------------------------------------------------------------------------------------
assume cs:code
code segment
start:

; 第一步:从CMOS中提取(月份)数据
;-----------------------------------------------------------------------------------------------------------------------------------------------
; CMOS RAM 芯片内部有两个端口地址用于读写CMOS RAM
;  70h —— 地址端口,存放要访问的 CMOS RAM 单元的地址。
;  71h —— 数据端口,存放从选定的 CMOS RAM 单元中读取的数据,或,写入到其中的数据。
; 端口的读写指令只有两条:in 从端口读取数据 out从端口写入数据(in out 对象只能是ax或者是al)
; CMOS RAM中存放单元:秒(0),分(2),时(4), 日(7),月(8),年(9)
	mov al, 8
	out 70h, al			; al的数值为8,使用out指令,将要访问的CMOS单元地址写入到70h中
						; 以上,指明,CPU通过地址线跟CMOS RAM端口说,CPU将从8号单元中读出数据
	in al, 71h				; 将71h 中读入一个字节到al 中
	
	mov ah, al			; al中为从CMOS RAM的8号单元中读出的数据
	mov cl, 4				
	shr ah, cl				; ah中为月份的十位数码值
						; shl指令,将目标操作数的二进制数值左移N位,
						; shr指令,将目标操作数的二进制数值右移N位.
						; 空位补零,最后移出位是0还是1写入到标志寄存器中的CF
	and al, 00001111b		; al 中为月份的个位数码值

; 第二步:将数据转换为ASCII码
;-----------------------------------------------------------------------------------------------------------------------------------------------
; 将BCD码转化成十进制相对应的ASCII码
; BCD码值 = 十进制数码值
; BCD码值 + 30h = 十进制数对应的ASCII码
	add ah, 30h
	add al, 30h

; 第三步:将提取出的月份在显示缓冲区中显示
;-----------------------------------------------------------------------------------------------------------------------------------------------
	mov bx, 0b800h
	mov es, bx
	mov byte ptr es:[160*12 +40*2], ah	; 显示月份的十位数码
	mov byte ptr es:[160*12+40*2+2], al	; 接着月份的个位数码

;-----------------------------------------------------------------------------------------------------------------------------------------------
; 程序返回
	mov ax, 4c00h
	int 21h

; 程序结束:
;-----------------------------------------------------------------------------------------------------------------------------------------------
code ends
end start

;-----------------------------------------------------------------------------------------------------------------------------------------------

 

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

 

; 程序名称:实验14_访问CMOS_RAM.asm
; 程序功能:以“年/月/日 时:分:秒"的格式,显示当前的日期,时间。

; ------------------------------------------------------------------------------------------------ the whole programma start---
assume cs:code, ds:timeds, ss:tempa

;  -------------------------------------------------------------------------------------------statment start ---
; 段名:ds:timed
; 功能: 用于存放时间的数据
; 大小:共占用了12个节字
; 数据:存放的数据依次是年月日时分秒
; ---------statment end------------------------

timeds segment
	db 12 dup('0')
timeds ends

;-------------------------------------------------------------------------------------------- programma end---

;  -------------------------------------------------------------------------------------------statment start ---
; 段名:ss:tempa
; 功能: 用于存放调用程序地址的数据
; 大小:共占用了六个字
; ---------statment end------------------------

tempa segment
	dw 6 dup('0')			
tempa ends

;-------------------------------------------------------------------------------------------- programma end---
code segment
start:
	mov ax, tempa	 	; 设置堆栈地址为程序设定的堆栈内存地址
	mov ss, ax
	mov ax, 12
	mov sp, ax
	
	mov bx, 0			; 依次访问并放入数据进数据段
	mov al,	9		; 年
	call raptd
	mov al, 8			; 月
	call raptd
	mov al, 7			; 日
	call raptd
	mov al, 4			; 时
	call raptd
	mov al, 2			; 分
	call raptd
	mov al, 0			; 秒
	call raptd
	
	mov ax, 0B800h
	mov bx, 0
	mov es, ax
	mov ax, timeds
	mov ds, ax
	mov ax, 0
	mov di, ax

	mov cx, 12		; 循环显示于显示缓冲区中
  lst:
	mov ax, ds:[di]		; 装入数据
	mov es:[bx], ax
	inc bx
	mov ax, 01110001B	 ; 显示的属性:白底蓝字
	mov es:[bx], ax
	inc bx
	inc di
	loop lst	

	mov ax, 4c00h
	int 21h
	
;  -------------------------------------------------------------------------------------------statment start ---
; 子程序名称:raptd -- read and push data
; 子程序功能:将CMOS RAM中的数据提取出来并且放入timesds内存单元中
; 子程序需要的参数: al:需要从外部调入(提取RAM的地址)
; ---------statment end------------------------

raptd:			; read and push data
	push ax
	mov ax, timeds	; 设置存放数据的地址
	mov es, ax
	
	pop ax
	mov ah, 0
	out 70h, al
	in al, 71h			; 先提取出需要的数据

	mov es:[bx], al		; 将数据存入指定地址中

	call exchange
	ret
;-------------------------------------------------------------------------------------------- programma end---

;  -------------------------------------------------------------------------------------------statment start ---
; 子程序名称:exchange
; 子程序功能:将timesds内存单元中的数据从BCD码转换为ASCII码存放
; 子程序需要的参数:bx:每存放一次增加数位2
;                                      al:需要从外部调入(提取RAM的地址)
; ---------statment end------------------------
exchange:
	mov al, es:[bx]
	mov ah, al
	mov cl, 4
	shr ah, cl				; 十位
	and al, 00001111b		; 个位
	add ah, 30h
	add al, 30h
	mov es:[bx], ah
	inc bx
	mov es:[bx], al
	inc bx

	inc bx
	ret
;-------------------------------------------------------------------------------------------- programma end---
code ends
end start

; ------------------------------------------------------------------------------------------------ the whole programma end---

 

抱歉!评论已关闭.