概述
实验三
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
最后
以上就是激昂导师为你收集整理的微型计算机原理与接口技术-实验三实验三By-Round Moon的全部内容,希望文章能够帮你解决微型计算机原理与接口技术-实验三实验三By-Round Moon所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复