2位16进制显示disphb
disphb 显示2位十六进制数据 入口:AL=8位数据
include io.inc
.model small
.stack
.data
.code
.startup
;disphb 显示2位十六进制数据 入口:AL=8位数据
mov ax,1234h
call disphb
.exit
end
实现disphb
.model small
.stack
.data
.code
.startup
;disphb 显示2位十六进制数据 入口:AL=8位数据
mov ax,123Ah
call disphb
.exit
disphb proc
push ax
push cx
push dx
mov cx,2
again:rol al,1
rol al,1
rol al,1
rol al,1
push ax
and al,0fh
cmp al,10
jb L1
add al,7
L1: add al,30h
mov dl,al
mov ah,02h
int 21h
pop ax
loop again
pop dx
pop cx
pop ax
ret
disphb endp
end
2位16进制输入readhb
readhb 输入2位十六进制数据 出口:AL=8位数据
include io.inc
.model small
.stack
.data
.code
.startup
;readhb 输入2位十六进制数据 出口:AL=8位数据
call readhb
.exit
end
实现readhb
.model small
.stack
.data
.code
.startup
;readhb 输入2位十六进制数据 出口:AL=8位数据
call readhb
int 3 ; debug调试用
.exit
readhb proc
push bx
push cx
rdhb1:xor bx,bx
mov cx,2
rdhb2:mov ah,1
int 21h
cmp al,'0'
jb rderr
cmp al,'9'
jbe rdhb3
cmp al,'A'
jb rderr
cmp al,'F'
jbe rdhb4
cmp al,'a'
jb rderr
cmp al,'f'
ja rderr
sub al,20h
rdhb4:sub al,7
rdhb3:sub al,30h
shl bl,1
shl bl,1
shl bl,1
shl bl,1
add bl,al
loop rdhb2
mov al,bl
pop cx
pop bx
ret
rderr:push ds
mov ax,cs
mov ds,ax
lea dx,errmsg
mov ah,9
int 21h
pop ds
jmp rdhb1
errmsg db 0dh,0ah,'Input error, enter again: $'
readhb endp
end
4位16进制显示
disphw 显示4位十六进制数据 入口:AX=16位数据
include io.inc
.model small
.stack
.data
.code
.startup
;disphw 显示4位十六进制数据 入口:AX=16位数据
mov ax 23AdH
call disphw
.exit
end
实现disphw
.model small
.stack
.data
.code
.startup
;disphb 显示2位十六进制数据 入口:AL=8位数据
mov ax,123Ah
call disphw
.exit
disphw proc
push ax
push cx
push dx
mov cx,4
again:rol ax,1
rol ax,1
rol ax,1
rol ax,1
push ax
and al,0fh
cmp al,10
jb L1
add al,7
L1: add al,30h
mov dl,al
mov ah,02h
int 21h
pop ax
loop again
pop dx
pop cx
pop ax
ret
disphw endp
end
4位16进制输入readhw
readhw 输入4位十六进制数据 出口:AX=16位数据
include io.inc
.model small
.stack
.data
.code
.startup
;readhw 输入4位十六进制数据 出口:AX=16位数据
call readhw
int 3 ; debug调试用
.exit
end
实现readhw
.model small
.stack
.data
.code
.startup
;readhw 输入4位十六进制数据 出口:AX=16位数据
call readhw
int 3 ; debug调试用
.exit
readhw proc
push bx
push cx
rdhb1:xor bx,bx
mov cx,4
rdhb2:mov ah,1
int 21h
cmp al,'0'
jb rderr
cmp al,'9'
jbe rdhb3
cmp al,'A'
jb rderr
cmp al,'F'
jbe rdhb4
cmp al,'a'
jb rderr
cmp al,'f'
ja rderr
sub al,20h
rdhb4:sub al,7
rdhb3:sub al,30h
shl bx,1
shl bx,1
shl bx,1
shl bx,1
add bl,al
loop rdhb2
mov ax,bx
pop cx
pop bx
ret
rderr:push ds
mov ax,cs
mov ds,ax
lea dx,errmsg
mov ah,9
int 21h
pop ds
jmp rdhb1
errmsg db 0dh,0ah,'Input error, enter again: $'
readhw endp
end