进制转换3例的详细介绍
1、 键盘输入N个十六进制数据,每次一位(0~F),将其累加,和存放到SUM单元中;若输入非十六进制数则结束;再将SUM单元的值用十六进制数据换行输出。
data segment
num db ?
adtab dw addr1, addr2, addr4, addr8
tb1 db 'I am student2$'
tb2 db 'You are students3$'
tb4 db 'You are students5$'
tb8 db 'You are students9$'
next db 0dh,0ah,'$'
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds, ax
mov ah, 01h
int 21h
sub al, 30h
mov num,al
lea dx, next
mov ah, 09h
int 21h
mov al, num
lea bx, adtab
lop: shr ax, 1
jnc nxt
jmp word ptr [bx]
nxt: add bx, type adtab
jmp lop
addr1: lea dx,tb1
mov ah,09h
int 21h
jmp exit
addr2: lea dx,tb2
mov ah,09h
int 21h
jmp exit
addr4: lea dx,tb4
mov ah,09h
int 21h
jmp exit
addr8: lea dx,tb8
mov ah,09h
int 21h
exit: mov ah,4ch
int 21h
code ends
end start
2、 键盘输入N个十六进制数据,每次一位(0~F),将其累加,和存放到SUM单元中;若输入非十六进制数则结束;再将SUM单元的值用二进制数据换行输出。
data segment
num db ?
table db?,?,?,?
next db 0dh,0ah,'$'
count dw 0
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds, ax
lop: mov ah, 01h
int 21h
cmp al, 0dh
jz outpush0
cmp al, '0'
jb other
cmp al, '9'
ja other
sub al, 30h
neg al
add al, 30h
mov si, count
mov table[si], al
mov cx, count
add cx, 1
mov count, cx
jmp lop
other:
mov si, count
mov table[si], al
mov cx, count
add cx, 1
mov count, cx
jmp lop
outpush0:
lea dx, next
mov ah, 9
int 21h
mov cx, 0
mov count, cx
mov bx, 4
outpush:
cmp bx, count
jz exit
mov si, count
mov dl, table[si]
mov ah, 2
int 21h
mov cx, count
add cx, 1
mov count, cx
jmp outpush
exit: mov ah,4ch
int 21h
code ends
end start
3、 键盘输入4个十六进制数据,将其对应的二进制数输出。
number0 db ?
number1 db ?
tb1 db 0dh,0ah,'jan',0dh,0ah,'$'
tb2 db 0dh,0ah,'fab',0dh,0ah,'$'
tb3 db 0dh,0ah,'mar',0dh,0ah,'$'
tb4 db 0dh,0ah,'apr',0dh,0ah,'$'
tb5 db 0dh,0ah,'may',0dh,0ah,'$'
tb6 db 0dh,0ah,'jun',0dh,0ah,'$'
tb7 db 0dh,0ah,'jly',0dh,0ah,'$'
tb8 db 0dh,0ah,'aug',0dh,0ah,'$'
tb9 db 0dh,0ah,'sep',0dh,0ah,'$'
tb10 db 0dh,0ah,'oct',0dh,0ah,'$'
tb11 db 0dh,0ah,'nov',0dh,0ah,'$'
tb12 db 0dh,0ah,'dec',0dh,0ah,'$'
next db 0dh,0ah,'$'
msgdb'Input a function number(1~12),end with "ENTER":','$'
ErrMsgdb0dh,0ah,'Invalid function number.', 0dh, 0ah,'$'
AddrTbl dw Func0,Func1,Func2,Func3,Func4,Func5,Func6,Func7,Func8,Func9,Func10,Func11
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
mov ds,ax
lea dx, msg
mov ah, 9
int 21h
mov ah, 1
int 21h
mov number0, al
mov ah, 1
int 21h
mov number1, al
mov al, number1
cmp al, 0dh
jz equ1
add al, 10
jmp equal
equ1:
mov al, number0
equal:
cmp al, '0'
jc Error
cmp al, '<'
ja Error
sub al, 30h
mov ah, 0
mov bx, ax
shl ax, 1
mov bx, ax
jmp AddrTbl[bx]
Func0:
lea dx, tb1
jmp Output
Func1:
lea dx, tb2
jmp Output
Func2:
lea dx, tb3
jmp Output
Func3:
lea dx, tb4
jmp Output
Func4:
lea dx, tb5
jmp Output
Func5:
lea dx, tb6
jmp Output
Func6:
lea dx, tb7
jmp Output
Func7:
lea dx, tb8
jmp Output
Func8:
lea dx, tb9
jmp Output
Func9:
lea dx, tb10
jmp Output
Func10:
lea dx, tb11
jmp Output
Func11:
lea dx, tb12
jmp Output
Error:
lea dx, ErrMsg
jmp Output
Output:
mov ah, 9
int 21h
mov ah,4ch
int 21h
code ends
end start
本文地址:http://www.45fan.com/a/question/69758.html