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

汇编:输入一位十六进制数将其转化为2进制数

时间:12-01 来源:互联网 点击:
这是汇编考试的题目输入一位十六进制数并且将其转化为2进制数

data segment
tital1 db INPUt: ,$
tital2 db OUTPUT:,$
tital3 db The input is error,please input again : ,$
tital4 db Do you want to have a try again(yes:y,no:n) ,$
tital5 db Welcome to use this program ,It is made by WQ ,$
kongzi db 0dh,0ah,$
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 ax,0 ;初始化al
mov bx,0

mov ah,01h ;输入并回显
int 21h
mov bl,al
cmp bl,30h
jae n0 ;>=
jmp tishi
n0:cmp bl,39h
jbe n1 ;<=39
cmp bl,41h ;>=41
jae n2
jmp tishi
n2:cmp bl,46h ;
jbe n3
cmp bl,61h
jb tishi
cmp bl,66h
jbe n4
jmp tishi
n1: sub bl,30h ;转化为十进制数
jmp o

n3:sub bl,37h
jmp o
n4:sub bl,57h
o:
lea dx,kongzi ;换行回车
mov ah,09h
int 21h

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

mov ax,0
mov al,bl
mov dx,0;初始化
mov di,0;指针为0
mov bl,02h
quyu:
div bl ;默认 ax

mov yushu[di],ah
inc di
mov ah,0
cmp al,02h
jae quyu
mov yushu[di],al
inc di
mov cx,di
dec di
shuchu:
mov dl,yushu[di]
dec di
add dl,30h
mov ah,02h
int 21h
jmp jiedian
jiedian:
loop shuchu
jmp over
tishi:
lea dx,kongzi;控制换行回车
mov ah,09h
int 21h
lea dx,tital3;输出抬头3
mov ah,09h
int 21h
jmp retry

over:
lea dx,kongzi
mov ah,09h
int 21h

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

mov ah,01h
int 21h
cmp al,y
jz retry
lea dx,kongzi
mov ah,09h
int 21h
lea dx,tital5
mov ah,09h
int 21h
;结束
mov ah,4ch
int 21h
code ends
end start

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

网站地图

Top