daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Dec 11th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack 100h
  3.  
  4. .data
  5.     input_prompt    db  'Iveskite sesioliktaini skaiciu: $'    
  6.     help_text       db  'Programa konvertuoja ivesta sesioliktaini skaiciu i dvejetaini.$'
  7.     invalid_input   db  'Neteisinga ivestis!$'
  8.     new_line        db  13,10,'$'
  9.     result          db  'Dvejetainis atitikmuo: $'
  10.     input           db  100, 0, dup(0)
  11.  
  12. .code
  13. program:    
  14.  
  15. ;load ds              
  16. mov ax,@data
  17. mov ds,ax
  18.  
  19. ;check if help text needs to be printed
  20. mov bx,81h
  21. argv:
  22.     mov ax,es:[bx]
  23.     inc bx
  24.     cmp al,13
  25.     je print_input_prompt
  26.     cmp al,' '
  27.     je argv
  28.     cmp ax,'?/'
  29.     jne argv
  30.     mov ax,es:[bx]
  31.     cmp ah,13            
  32.     je help
  33.     cmp al,' '
  34.     je help        
  35.     jmp print_input_prompt
  36.      
  37. ;print help text        
  38. help:
  39.     mov ah,9h
  40.     mov dx,offset help_text
  41.     int 21h
  42.     jmp finish
  43. ;print input prompt    
  44. print_input_prompt:            
  45.     mov dx,offset input_prompt
  46.     mov ah,9h
  47.     int 21h
  48.            
  49. ;ask user for input    
  50. collect_input:
  51.     mov ah,0Ah
  52.     mov dx,offset input
  53.     int 21h
  54.     ;move carret to a new line
  55.     mov ah,9h
  56.     mov dx,offset new_line
  57.     int 21h
  58.              
  59. ;validates input and prints error if input is invalid
  60. mov bx,offset input
  61. add bx,2
  62. validate_input:
  63.     mov ax,ds:[bx]
  64.     inc bx
  65.     ;if not end of input
  66.     cmp al,13
  67.     je print_result_msg
  68.     ;if number
  69.     cmp al,30h
  70.     jb error
  71.     cmp al,39h
  72.     jbe validate_input
  73.     ;if letter
  74.     cmp al,41h
  75.     jb error
  76.     cmp al,46h
  77.     jbe validate_input
  78.     jmp error    
  79.        
  80. ;print error msg
  81. error:
  82.     mov dx,offset invalid_input
  83.     mov ah,9h
  84.     int 21h
  85.     jmp finish
  86.    
  87. ;print result msg
  88. print_result_msg:
  89.     mov dx,offset result
  90.     mov ah,9h
  91.     int 21h
  92.    
  93. ;convert hex to bin
  94. mov bx,offset input
  95. add bx,2h    
  96. convert:
  97.     mov ax,ds:[bx]
  98.     inc bx
  99.     cmp al,13
  100.     je finish  
  101.     cmp al,39h
  102.     jbe convert_number
  103.     jmp convert_letter
  104.    
  105. ;convert number character in al to number    
  106. convert_number:
  107.     sub al,30h  
  108.     jmp print_binary      
  109.    
  110. ;convert letter to number
  111. convert_letter:        
  112.     sub al,55d
  113.     jmp print_binary
  114.    
  115. print_binary:
  116.     mov ch,4;how many chars will be shown
  117.     mov cl,3;how many rotates will be made
  118.  
  119. process:
  120.     push ax
  121.     ;convert bit to char
  122.     mov dl,al
  123.     ror dl,cl
  124.     and dl,01
  125.     add dl,30h
  126.     ;print 0 or 1
  127.     mov ah, 02h
  128.     int 21h    
  129.     ;proceed if ch
  130.     pop ax
  131.     dec cl
  132.     dec ch            
  133.     jnz process
  134.     ;space after every 4 bits
  135.     mov dl,' '
  136.     mov ah,2h
  137.     int 21h  
  138.     jmp convert
  139.  
  140. ;finish program
  141. finish:
  142.     mov ax,4c00h
  143.     int 21h
  144.    
  145. end program
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top