微型计算机原理与接口技术-实验三

实验三

ASCII码打表

通过查表的方法实现十六进制数转换为 ASCII 码。**

XLAT : DS:[BX+AL]为地址,提取存储器中的一个字节再送入AL

data segment
	table db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h
	hex db 9Ah
	ascl db 0
	asch db 0
data ends

code segment
main proc far
	assume cs:code,ds:data
start:
	mov ax,data
	mov ds,ax
	mov al,hex
	and al,0Fh
	xlat
	mov ascl,al
	mov al,hex
	shr al,4
	and al,0Fh
	xlat
	mov asch,al
	mov ax,4c00h
	int 21h
	ret
main endp
code ends
end start

输出十六进制

在实验(1) 的基础上设计2个函数 HEX2ACSII 与DISPLAY
分别实现16进制到ACSII码的转换 以及打印转换后的ACSII码的功能,并利用上述函数将100-120的16进制数据进行打印

data segment
	table db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h
	hex db 9Ah
	ascl db 0
	asch db 0
data ends   
stack segment stack
    dw 50 dup()
    top label word
stack ends    
code segment
main proc far                                     	
    assume cs:code,ds:data,ss:stack
start:     
    mov ax,stack
    mov ss,ax
    mov sp,offset top
    push ds
    push 0
	mov ax,data
	mov ds,ax
	mov cl,100    
point:	   
	mov hex,cl
	call HEX2ACSII
	call DISPLAY  
	inc cl
	cmp cl,120   
	jbe point
	mov ax,4c00h
	int 21h
main endp
HEX2ACSII proc near  
	mov bh,hex
	and bh,0fh
	mov ascl,bh 
	mov bh,hex
	shr bh,4
	and bh,0fh
	mov asch,bh
	ret
HEX2ACSII endp
DISPLAY proc near
	mov bx,0
	mov al,asch
	xlat
	mov dl,al  
	mov ah,02h
	int 21h
	mov al,ascl
	xlat
	mov dl,al  
	mov ah,02h
	int 21h
	mov dl,32   
	mov ah,02h
	int 21h
	ret
DISPLAY endp
code ends
end start

求最大值和最小值

求无符号字节序列中的最大值和最小值

设有一字节序列, 存放在数据段BUF, 长度为 08h。利用子程序的方法编程求出该序列中的最大值和最小值

data segment
    save db 42, 97, 102, 9, 37, 75, 18, 49
    len equ $-save
    maxn db 0
    minn db 0
data ends      
stack segment stack
    dw 50 dup()
    top label word
stack ends
code segment   
main proc far
    assume cs:code,ds:code,ss:stack
start:  
    mov ax,stack
    mov ss,ax
    mov sp,offset top
    push ds
    push 0         
    mov ax,data
    mov ds,ax        
    call Find_Max
    call Find_Min   
    ret
main endp
Find_Max proc near   
    mov al,save[0]   
    mov cx,len  
    mov bx,0
Loop1:
    cmp al, save[bx]
    jae next1  
    mov al,save[bx]
next1:            
    inc bx
    loop Loop1     
    mov maxn,al 
    ret        
Find_Max endp
Find_Min proc near   
    mov al,save[0]   
    mov cx,len  
    mov bx,0
Loop2:
    cmp al, save[bx]
    jbe next2  
    mov al,save[bx]
next2:            
    inc bx
    loop Loop2     
    mov minn,al 
    ret      
Find_Min endp
code ends
end start

展示最值十六进制

调用实验(2)中的HEX2ACSII 与DISPLAY函数将最大和最小值分别显示出来。

data segment
    save db 42, 97, 102, 9, 37, 75, 18, 49  
    len equ $-save
    table db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h
    maxn db 0
    minn db 0  
    hex db 0 
    ascl db 0
    asch db 0
data ends      
stack segment stack
    dw 50 dup()  
    top label word
stack ends

code segment   
main proc far
    assume cs:code,ds:data,ss:stack
start:  
    mov ax,stack
    mov ss,ax  
    mov sp, offset top
    push ds
    push 0        
    mov ax,data
    mov ds,ax              
    call Find_Max
    call Find_Min 
    mov al,maxn  
    mov hex,al 
    call HEX2ACSII   
    call DISPLAY  
    mov al,minn  
    mov hex,al 
    call HEX2ACSII   
    call DISPLAY
    ret
main endp
Find_Max proc near   
    mov al,save[0]   
    mov cx,len  
    mov bx,0
Loop1:
    cmp al, save[bx]
    jae next1  
    mov al,save[bx]
next1:            
    inc bx
    loop Loop1     
    mov maxn,al 
    ret        
Find_Max endp
Find_Min proc near   
    mov al,save[0]   
    mov cx,len  
    mov bx,0
Loop2:
    cmp al, save[bx]
    jbe next2  
    mov al,save[bx]
next2:            
    inc bx
    loop Loop2     
    mov minn,al 
    ret      
Find_Min endp
HEX2ACSII proc near  
	mov bh,hex
	and bh,0fh
	mov ascl,bh 
	mov bh,hex
	shr bh,4
	and bh,0fh
	mov asch,bh
	ret
HEX2ACSII endp
DISPLAY proc near
	lea bx,table
	mov al,asch 
	xlat
	mov dl,al  
	mov ah,02h
	int 21h
	mov al,ascl
	xlat
	mov dl,al  
	mov ah,02h
	int 21h
	mov dl,32   
	mov ah,02h
	int 21h
	ret
DISPLAY endp
code ends
end start

By-Round Moon

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Round moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值