Advertisement
Andziev

stringTransformation assembly

Nov 14th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; multi-segment executable file template.
  2.  
  3. data segment
  4.     ; add your data here!
  5.     str1 db 50 dup(?)
  6.     str2 db 50 dup(?)
  7.     length db 0      
  8.     transformations db 0
  9.     porakaIsti db "Isti se $"
  10.     porakaRazlicni db "Ne se isti $"
  11.     inputString db "Vnesi string: $"
  12. ends
  13.  
  14. stack segment
  15.     dw   128  dup(0)
  16. ends
  17.  
  18. code segment      
  19. transform proc
  20.     pop bx
  21.     pop si
  22.     mov cx, 0
  23.    
  24.     workProcess:
  25.         cmp [si], 36d
  26.         je submitAndExit
  27.        
  28.         cmp [si], 65d
  29.         jge toBeSure        
  30.        
  31.         jmp workProcess
  32.     toBeSure:
  33.         cmp [si], 90d
  34.         jg continueWithSearch
  35.        
  36.         add [si], 32d
  37.         inc cx
  38.        
  39.         jmp continueWithSearch        
  40.     continueWithSearch:
  41.         inc si
  42.        
  43.         jmp workProcess        
  44.     submitAndExit:
  45.         push cx        
  46.         push bx
  47.        
  48.         ret    
  49. transform endp  
  50. start:
  51. ; set segment registers:
  52.     mov ax, data
  53.     mov ds, ax
  54.     mov es, ax
  55.          
  56.     lea di, str1
  57.     lea dx, inputString
  58.     mov ah, 09h
  59.     int 21h              
  60.     readFirstString:  
  61.         mov ah, 01h  
  62.         int 21h        
  63.         stosb
  64.        
  65.         inc length
  66.        
  67.         cmp al, 36d
  68.         je setFirstString
  69.                  
  70.         jmp readFirstString
  71.    
  72.     setFirstString:
  73.         lea si, str1
  74.         push si
  75.         call transform  
  76.         pop cx
  77.         add transformations, cl        
  78.        
  79.     lea di, str2
  80.     mov dl, 13d
  81.     mov ah, 02h
  82.     int 21h  
  83.        
  84.     mov dl, 10d
  85.     mov ah, 02h
  86.     int 21h
  87.    
  88.     lea dx, inputString
  89.     mov ah, 09h
  90.     int 21h                
  91.     readSecondString:  
  92.         mov ah, 01h  
  93.         int 21h        
  94.         stosb
  95.        
  96.         dec length  
  97.            
  98.         cmp al, 36d
  99.         je setSecondString
  100.                  
  101.         jmp readSecondString
  102.    
  103.     setSecondString:
  104.         lea si, str2
  105.         push si
  106.         call transform  
  107.         pop cx
  108.         add transformations, cl
  109.        
  110.        
  111.     lea si, str1
  112.     lea di, str2
  113.    
  114.     cmp length, 0
  115.     jne notEqual
  116.    
  117.     compare:
  118.         cmp [si], 36d
  119.         je equal
  120.        
  121.         mov dl, [di]
  122.         cmp [si], dl
  123.         jne notEqual
  124.        
  125.         inc si
  126.         inc di          
  127.     equal:
  128.         mov dl, 13d
  129.         mov ah, 02h
  130.         int 21h  
  131.        
  132.         mov dl, 10d
  133.         mov ah, 02h
  134.         int 21h      
  135.    
  136.         lea dx, porakaIsti
  137.         mov ah, 09h
  138.         int 21h
  139.        
  140.         jmp return              
  141.     notEqual:
  142.         mov dl, 13d
  143.         mov ah, 02h
  144.         int 21h  
  145.        
  146.         mov dl, 10d
  147.         mov ah, 02h
  148.         int 21h    
  149.    
  150.         lea dx, porakaRazlicni
  151.         mov ah, 09h
  152.         int 21h    
  153.     return:    
  154.         mov dl, transformations
  155.         add dl, 48d
  156.         mov ah, 02h
  157.         int 21h
  158.    
  159.     mov ax, 4c00h ; exit to operating system.
  160.     int 21h    
  161. ends
  162.  
  163. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement