十六进制转十进制(汇编masn)
十六进制转十进制(汇编masn).txt看一个人的的心术,要看他的眼神;看一个人的身价,要看他的对手;看一个人的底牌,要看他的朋友。明天是世上增值最快的一块土地,因它充满了希望。;十六-十进制转换
;程序设计的要求:通过键盘给一个四位的16进制数,程序把它转换成10进制数,并显示出来。
;
;把输入的4位16进制数以10十进制的值存放到变量num中,注意num可能会有5位数。所以下面
;就通过÷,%(10000,1000,100,10)来得到每一位数,即十进制数.
CSEG SEGMENT
assume cs:CSEG, ds:DSEG, ss:SSEG
MAIN PROC FAR ;主程序入口
mov num, 0
mov cx, 4 ;输入4位16进制数(这里没有处理少于或多于4位的情况)
L1: mov ah, 01h
int 21h
push cx
mov cl, 4
shl num, cl ;输入的数以10进制的形式存到num中
pop cx
cmp al, 3ah
jb s1
sub al, 07h
s1: sub al, 30h
mov ah, 0
add num, ax
mov bx, num
loop L1
;******************************************************************************;输入空格以结束。
mov ah, 01h
int 21h
mov ah, 02h
mov dl, '('
int 21h
mov dl, '1'
int 21h
mov dl, '6'
int 21h
mov dl, ')'
int 21h
mov dl, ' '
int 21h0
;******************************************************************************;
call fun ;调用主函数
;******************************************************************************;
mov ah, 02h
mov dl, '('
int 21h
mov dl, '1'
int 21h
mov dl, '0'
int 21h
mov dl, ')'
int 21h
call change
;******************************************************************************;
call exit ;退出
;******************************************************************************;
MAIN ENDP
fun proc
mov cx, 10000d ;把除数存放到cx中
call dec_div
mov cx, 1000d
call dec_div
mov cx, 100d
call dec_div
mov cx, 10d
call dec_div
mov cx, 1d
call dec_div
ret
fun endp
dec_div proc ;除法实现,除数为cx的值
mov ax, bx
mov dx, 0
div cx
mov bx, dx
mov dl, al
add dl, 30h
mov ah, 02h
int 21h
ret
dec_div endp
;*************************************************************************************************
;下面代码仅供测试使用
printb proc
push ax
mov dl, al
mov ah, 02h
int 21h
pop ax
ret
printb endp
printw proc
push ax
push bx
push cx
MOV cx,4
a7: mov di, bx
PUSH cx
MOV cl,4
ROL di,cl
mov bx, di
MOV dl,bl
AND dl,0fh
ADD dl,30h
CMP dl,3ah
JB a8
ADD dl,7
a8: MOV ah,2
INT 21h
POP cx
LOOP a7
pop cx
pop bx
pop ax
ret
printw endp
;*************************************************************************************************
;*************************************************************************************************
;回车换行
change proc
push ax
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl,
0dh
int 21h
pop ax
ret
change endp
;*************************************************************************************************
;*************************************************************************************************
;退出
exit proc
;按任意键退出
mov ah,1
int 21h
mov ax, 4c00h ;程序结束,返回到操作系统
int 21h
exit endp
;*************************************************************************************************
CSEG ENDS
SSEG SEGMENT PARA STACK 'stack'
dw 100h dup(0) ;初始化堆栈大小为100
SSEG ENDS
DSEG SEGMENT
;数据段:在此处添加程序所需的数据
num dw ?
arr dw 10 dup(?)
DSEG ENDS
END MAIN