這個是一個把兩位十進(jìn)制數(shù)轉(zhuǎn)化為十六進(jìn)制數(shù)的的匯編語言程序 考試題目
data segment
tital1 db 'Please input shi jin zi shu (example 13): ','$'
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,'$'
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 ;輸出抬頭1
mov ah,09h
int 21h
mov al,0 ;初始化al
mov ah,01h ;輸入并回顯
int 21h
mov bh,al ;放在bx中保存
mov ah,01h
int 21h
mov bl,al
lea dx,kongzi ;換行回車
mov ah,09h
int 21h
lea dx,tital2 ;輸出抬頭2
mov ah,09h
int 21h
mov ax,0 ;初始化ax
sub bh,30h ;把a(bǔ)scII碼轉(zhuǎn)化為十進(jìn)制數(shù)
mov al,bh ;輸入的第一個數(shù)(十位數(shù))
mov cl,0ah
mul cl ;al被乘十
sub bl,30h
add al,bl ;徹底轉(zhuǎn)化為十進(jìn)制數(shù)
mov dl,al ;dl 中為十進(jìn)制數(shù)
mov bl,10h ;16
mov cl,al
mov dl,0
l1:cmp cl,bl ;和十六比較看看是否比十六大
jnae l2
inc dl ;看該數(shù)里面有幾個十六
sub cl,bl
jmp l1
l2: add dl,30h ;比十六小的話第一位數(shù)應(yīng)該為0,
;因?yàn)?9化成十六進(jìn)制數(shù)為63h第二位不會大于六
mov ah,02h
int 21h
cmp cl,0ah ;cl和十進(jìn)行比較
jae l3
mov dl,cl
add dl,30h ;十以內(nèi)的數(shù)加30
mov ah,02h
int 21h
jmp tishi
l3: mov dl,cl ;比十大的要變成字母
add dl,37h ;十進(jìn)制二位數(shù)和十六進(jìn)制abcdef差37h
mov ah,02h
int 21h
tishi:
lea dx,kongzi;控制換行回車
mov ah,09h
int 21h
lea dx,tital3;輸出抬頭3
mov ah,09h
int 21h
mov ah,01h ;判斷是否繼續(xù)
int 21h
cmp al,'y'
je retry
lea dx,kongzi;控制換行回車
mov ah,09h
int 21h
lea dx,tital4
mov ah,09h
int 21h
over: ;結(jié)束
mov ah,4ch
int 21h
code ends
end start