微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 汇编:将四位十进制数转化为十六进制数

汇编:将四位十进制数转化为十六进制数

时间:12-01 来源:互联网 点击:
这是一个把四位十进制数转化为十六进制数的汇编语言程序


data segment
tital1 db Please input shi jin zi shu (example 1234): ,$
tital2 db It is transpranted into shi liu jin zi shu :,$
tital3 db Do you want to have a try again (yes "y",no "n"): ,$
tital4 db Welcome to use this program It is made by WQ 2012/5/17,$
kongzi db 0dh,0ah,$
jichun dw 0000h
yushu db 5 dup(00)
duandian db jianche dian,0dh,0ah,$
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax

retry:
lea dx,kongzi ;换行回车
mov ah,09h
int 21h

lea dx,tital1 ;输出抬头1please input 1234
mov ah,09h
int 21h

mov al,0 ;初始化al

mov ah,01h ;输入并回显
int 21h

mov bh,al ;千位放在bh中保存

mov ah,01h
int 21h
mov bl,al ;百位放在bl中

mov ah,01h
int 21h
mov ch,al ;十位放在ch中

mov ah,01h
int 21h
mov cl,al ;个位放在cl中
;bh,bl,ch,cl 都没问题

lea dx,kongzi ;换行回车
mov ah,09h
int 21h

lea dx,tital2 ;输出抬头2
mov ah,09h
int 21h

mov ax,0 ;初始化ax

sub bh,30h ;把ascII码转化为十进制数
mov al,bh ;输入的第一个数(千位数)
;over

mov si,0ah ;10权值
mul si ;ax被乘1000 over
mul si
mul si
mov jichun,ax ;over


mov ax,0
sub bl,30h
mov al,bl ;ax被乘100
mul si
mul si
add jichun,ax

mov ax,0
sub ch,30h
mov al,ch
mul si ;ax乘10
add jichun,ax
mov ax,0
sub cl,30h
mov al,cl
add jichun,ax ;彻底转化为十进制数

mov ax,jichun ; ax中为9999转化为16进制数270f
;over;;;;;;;;;;;;;;;;;;;;;;;;

mov dx,0;初始化
mov di,0;指针为0
mov bx,0010h
quyu:
div bx ;默认 ax

mov yushu[di],dl
inc di
mov dx,0
cmp ax,10h
jae quyu
mov yushu[di],al
inc di
mov cx,di
dec di
shuchu:
mov dl,yushu[di]
dec di
cmp dl,0ah
jnae l2
add dl,37h
mov ah,02h
int 21h
jmp jiedian
l2: add dl,30h
mov ah,02h
int 21h
jiedian:
loop shuchu
tishi:
lea dx,kongzi;控制换行回车
mov ah,09h
int 21h
lea dx,tital3;输出抬头3
mov ah,09h
int 21h
mov ah,01h ;判断是否继续
int 21h
cmp al,y
je retry

lea dx,kongzi;控制换行回车
mov ah,09h
int 21h

lea dx,tital4
mov ah,09h
int 21h

over: ;结束
mov ah,4ch
int 21h
code ends
end start

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top