專注電子技術(shù)學習與研究
當前位置:單片機教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

匯編:輸入一位十六進制數(shù)將其轉(zhuǎn)化為2進制數(shù)

作者:佚名   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2013年12月01日   【字體:

這是匯編考試的題目輸入一位十六進制數(shù)并且將其轉(zhuǎn)化為2進制數(shù)

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   ;轉(zhuǎn)化為十進制數(shù)
   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
                 ;結(jié)束
    mov ah,4ch
    int 21h
    code ends
end start

關(guān)閉窗口

相關(guān)文章