简体   繁体   中英

How to take input 8 bit binary and convert into ASCII in emu8086 Assembly Language

I want to take input from user and print co-responding Ascii value. This might be similar to this However i am looking for specific code on emu8086.
Input: 01000001
Output A
Input: 00110000
Output 0

This might help you

include 'emu8086.inc' 
.model small
.stack 100h

.data
n_line db 0ah,0dh,"$"  ;for new line
msg1 db "input : $" 
msg2 db 0ah,0dh,"Outpur : $"
msg3 db 0ah,0dh,"invalid input given. $"  
i db ?

.code
main proc
    mov ax,@data
    mov ds,ax

@infinite:  
    mov i,0d           ;for infinite process i=0 at initialization
         
    lea dx,msg1   
    mov ah,09
    int 21h 

                       ;clear bx register
    xor bx,bx          ;XOR operation with self will always produce 0    
        
    
    mov ah,1
    @input:            
        int 21h        
        
        cmp al,50      ;check for input only 0 and 1
        jge @invalid
        cmp al,48
        jl @invalid
                       ;65d = 01000001 
        and al,0Fh     ;0Fh = 00001111
                       ;AND = 01000001
        shl bx,1
        or bl,al       ;store al data at LSB of BL register 
                 
        inc i
        cmp i,8d
        jl @input
        jge @next_step
    
    @next_step:   
        lea dx,msg2   
        mov ah,9
        int 21h
         
        mov dl,bl       ;print Ascii value
        mov ah,2
        int 21h  
        
        lea dx,n_line   ;for new line
        mov ah,9
        int 21h  
        
        jmp @infinite
            
         
@stop:       
    mov ah,4ch
    int 21h
    main endp
@invalid:
    lea dx,msg3
    mov ah,9
    int 21h
    jmp @stop
end main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM