Advertisement
plyp

Untitled

Jan 13th, 2020
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data segment
  2.         startingMessage  db 10,13,'Wpisz liczbe (0-65535): $'
  3.         emptyString db 10,13,'Podany ciag jest empty!$'
  4.         signNotNumber db 10,13,'Podany ciag nie jest liczba!$'
  5.         tooBig db 10,13,'Podana liczba jest za duza!$'
  6.         messageDec  db 'Liczba decymalnie: $'
  7.         messageBin  db 10,13,'Liczba binarnie: $'
  8.         messageHex  db 10,13,'Liczba heksadecymalnie: $'
  9.         hex  db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  10.         endOfText db 10,13,'$'
  11.         max  db 6
  12.         l  db ?
  13.         arr  db 7 dup('$')
  14.         sum dw 0
  15.         db '$'
  16. data ends
  17.  
  18. stack segment
  19.         dw    100h dup(0)
  20. top Label word
  21. stack ends
  22.  
  23. code segment
  24.         assume cs:code, ss:stack, ds:data
  25.         mov ax,data
  26.         mov ds,ax
  27.         mov ax,stack
  28.         mov ss,ax
  29.         mov sp,offset top
  30.         mov ah,09h                          /wyswietl lancuch tekstowy
  31.         lea dx,startingMessage  
  32.         int 21h  
  33.         mov ah,0Ah                          /buforowane wczytanie z klawiatury
  34.         lea dx,max    
  35.         int 21h        
  36.         mov ah,09h                          /wyswietl lancuch tekstowy
  37.         lea dx,endOfText
  38.         int 21h
  39.      
  40.         xor ax,ax
  41.         xor bx,bx
  42.         xor cx,cx
  43.         xor dx,dx
  44.         mov cl,l      
  45. checkl:
  46.         cmp l,0
  47.         je empty    
  48.         jmp checkIfNumber
  49.  
  50. empty:
  51.         mov ah,09h                          /wyswietl lancuch tekstowy
  52.         lea dx,emptyString
  53.         int 21h
  54.         mov ax,4c03h                        /zakoncz program i zwroc kod powrotu, czekaj na data z urzadzenia pomocniczego
  55.         int 21h      
  56.  
  57. checkIfNumber:
  58.         mov dl,arr[bx]    
  59.         cmp dl,'0'          
  60.         jl wrongNumber        
  61.         cmp dl,'9'
  62.         jg wrongNumber  
  63.         inc bx      
  64.         loop checkIfNumber
  65.         xor bx,bx  
  66.         mov cl,l  
  67.         jmp checkRange
  68.  
  69. wrongNumber:
  70.         mov ah,09h
  71.         lea dx,signNotNumber
  72.         int 21h
  73.         mov ax,4c02h
  74.         int 21h
  75.  
  76. checkRange:
  77.         mov dx,10
  78.         mov ax,sum
  79.         mul dx  
  80.         jc tooMuch      
  81.         mov dh,0        
  82.         mov dl,arr[bx]
  83.         sub dx,'0'      
  84.         add ax,dx        
  85.         jc tooMuch      
  86.         mov sum,ax        
  87.         inc bx        
  88.         loop checkRange        
  89.         jmp showDec
  90.  
  91. tooMuch:
  92.         mov ah,09h
  93.         lea dx,tooBig
  94.         int 21h
  95.         mov ax,4c03h
  96.         int 21h
  97.  
  98. showDec:
  99.         mov ah,09h
  100.         lea dx,messageDec
  101.         int 21h
  102.         lea dx,arr
  103.         int 21h      
  104.  
  105.         lea dx,messageBin
  106.         int 21h    
  107.         mov ah,02h  
  108.         mov cx,16    
  109.         mov bx,sum
  110.  
  111.        
  112. swapBin:
  113.         rol bx,1      
  114.         push bx    
  115.         and bx,1      
  116.         add bx,'0'          
  117.         mov dl,bl        
  118.         int 21h      
  119.         pop bx          
  120.  
  121.         loop swapBin
  122.  
  123.         mov ah,09h
  124.         lea dx,messageHex
  125.         int 21h
  126.  
  127.         mov ah,02h
  128.         mov cx,4  
  129.         mov bx,sum
  130. swapHex:
  131.         rol bx,4        
  132.         push bx    
  133.         and bx,15    
  134.         mov dl,hex[bx]    
  135.         int 21h        
  136.         pop bx    
  137.         loop swapHex
  138. mov ax,4c00h    
  139.         int 21h
  140.  
  141. code ends
  142.  
  143.  
  144.  
  145.  
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement