Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .data
  2. ######################################################
  3. #   strings & constants
  4. ######################################################
  5. #   const string
  6. ######################################################
  7. string_0: .ascii "Unesite N: \0"
  8. string_len_0 = .-string_0
  9.  
  10. string_1: .ascii "Unesite string: \0"
  11. string_len_1 = .-string_1
  12.  
  13. string_2: .ascii "Greska u konverziji!\n\0"
  14. string_len_2 = .-string_2
  15.  
  16. string_3: .ascii "Broj reci sa svim malim slovima: \0"
  17. string_len_3 = .-string_3
  18.  
  19. string_4: .ascii "Uneli ste prazan string!\n\0"
  20. string_len_4 = .-string_4
  21.  
  22. string_5: .ascii "Izlazni string: \0"
  23. string_len_5 = .-string_5
  24.  
  25. string_6: .ascii "Broj reci sa svim malim slovima: \0"
  26. string_len_6 = .-string_6
  27. ######################################################
  28. #   strings for input
  29. ######################################################
  30.  
  31. max_sizeof_n = 50
  32. string_7: .fill max_sizeof_n,1,0 #N
  33.  
  34. #string for change
  35. max_size = 80
  36. #input
  37. string_8: .fill max_size,1,0
  38.  
  39. string_9: .fill max_sizeof_n,1,0
  40.  
  41.  
  42. ######################################################
  43. #   variables
  44. ######################################################
  45. for_change_n: .long 0 # number of words to change
  46.  
  47. number_of_words: .long 0
  48.  
  49. input_string_len: .long 0
  50.  
  51. n_size: .long 0
  52. .section .text
  53.  
  54. ######################################################
  55. #   actual code
  56. ######################################################
  57. .globl main
  58.  
  59. main:
  60.     print: #Unesite N:
  61.     movl $4, %eax
  62.     movl $1, %ebx
  63.     leal string_0, %ecx
  64.     movl $string_len_0, %edx
  65.     int $0x80
  66.  
  67.     #actual input string
  68.     movl $3, %eax
  69.     movl $0, %ebx
  70.     leal string_7, %ecx
  71.     movl $max_sizeof_n, %edx
  72.     int $0x80
  73.    
  74.     #check empty string
  75.     cmpl $1, %eax #string contains only newline character
  76.     jne not_empty_str
  77.    
  78.     #? string is empty print string_4
  79.     movl $4, %eax
  80.     movl $1, %ebx
  81.     leal string_4, %ecx
  82.     movl $string_len_4, %edx
  83.     int $0x80
  84.     jmp print #request another input
  85.  
  86.     not_empty_str:
  87.     xorl %eax, %eax
  88.     movl $10, %ebx
  89.     xorl %ecx, %ecx
  90.     xorl %edx, %edx
  91.     movl $string_7, %esi
  92.     #base is stored in ebx
  93.    
  94.     conversion:
  95.     cmpb $10, (%esi)             
  96.     je end_of_conversion
  97.     movb (%esi), %cl
  98.     cmpb $'0', %cl
  99.     jl   conversion_error
  100.     cmpb $'9', %cl
  101.     jnbe conversion_error
  102.     subb $'0', %cl                 
  103.     mull %ebx                      
  104.     cmpl $0  , %edx
  105.     jne  conversion_error
  106.     addl %ecx, %eax                
  107.     jo   conversion_error            
  108.     incl %esi                        
  109.     jmp  conversion
  110.     conversion_error:
  111.  
  112.     #print conversion error string_2
  113.     movl $4, %eax
  114.     movl $1, %ebx
  115.     leal string_2, %ecx
  116.     movl $string_len_2, %edx
  117.     int $0x80
  118.     jmp print  
  119.    
  120.     end_of_conversion:
  121.     #save output
  122.     movl %eax, for_change_n
  123.  
  124.     #enter to change string
  125.     movl $4, %eax
  126.     movl $1, %ebx
  127.     leal string_1, %ecx
  128.     movl $string_len_1, %edx
  129.     int $0x80
  130.  
  131.     #real input
  132.     movl $3, %eax
  133.     movl $0, %ebx
  134.     leal string_8, %ecx
  135.     movl $max_size, %edx
  136.     int $0x80
  137.  
  138.     #? is empty
  139.     cmpl $1, %eax
  140.     jne not_empty_Cstring
  141.  
  142.     #empty
  143.     movl $4, %eax
  144.     movl $1, %ebx
  145.     leal string_4, %ecx
  146.     movl $string_len_4, %edx
  147.     int $0x80
  148.  
  149.     #request input again
  150.     jmp not_empty_str
  151.     not_empty_Cstring:
  152.     movl %eax, input_string_len #save lenght
  153.  
  154.     xorl %eax, %eax #
  155.     xorl %ebx, %ebx # was char (1) or not (0)
  156.     xorl %edx, %edx # how many words we have changed
  157.     leal string_8, %esi
  158.     movl for_change_n, %ecx
  159.     vip_loop:
  160.     cmpb $10, (%esi)
  161.     je end_of_vip_loop
  162.    
  163.     movb (%esi), %al
  164.     cmpb $48, (%esi) # < 0
  165.     jb dont_take_it
  166.    
  167.     cmpb $58, (%esi) # <= 9
  168.     jb take_it
  169.  
  170.     cmpb $65, (%esi) # < A
  171.     jb dont_take_it
  172.    
  173.     cmpb $91, (%esi) # <= Z
  174.     jb take_it
  175.  
  176.     cmpb $95, (%esi) # underscore
  177.     je take_it
  178.  
  179.     cmpb $97, (%esi) # < a
  180.     jb dont_take_it
  181.    
  182.     cmpb $123, (%esi) # <= z
  183.     jb take_it
  184.     # (esi) > z than
  185.    dont_take_it:           
  186.     xorl %ebx, %ebx
  187.     jmp next
  188.    take_it:
  189.     # there was a special?
  190.     cmpl $0, %ebx
  191.     jne there_wasnt_a_special  
  192.     #there was special
  193.     incl number_of_words # new word
  194.     incl %edx
  195.     movl $1, %ebx
  196.     #check if edx is less than ecx
  197.     cmpl %edx, %ecx
  198.     jae change_first_char_to_upper
  199.     #change to lowercase
  200.         cmpb $58, (%esi)
  201.     jb next
  202.     cmpb $90, (%esi)
  203.     ja next
  204.     addb $32, (%esi)
  205.     jmp next
  206.     change_first_char_to_upper:
  207.     cmpb $58, (%esi)
  208.     jb next
  209.     cmpb $91, (%esi)
  210.     jb next
  211.     subb $32, (%esi)
  212.     jmp next
  213.     there_wasnt_a_special:
  214.     movl $1, %ebx  
  215.     cmpb $58, (%esi)
  216.     jb next
  217.     cmpb $96, (%esi)
  218.     ja next
  219.     addb $32, (%esi)
  220.     next:
  221.     incl %esi
  222.     jmp vip_loop
  223.     end_of_vip_loop:
  224.  
  225.     exit_print:
  226.     # print "Izlazni string: "
  227.     movl $4, %eax
  228.     movl $1, %ebx
  229.     leal string_5, %ecx
  230.     movl $string_len_5, %edx
  231.     int $0x80
  232.    
  233.     movl $4, %eax
  234.     movl $1, %ebx
  235.     leal string_8, %ecx
  236.     movl input_string_len, %edx
  237.     int $0x80
  238.  
  239.     #printf "Broj reci sa svim malim slovima: "
  240.     movl $4, %eax
  241.     movl $1, %ebx  
  242.     leal string_6, %ecx
  243.     movl $string_len_6, %edx
  244.     int $0x80  
  245.    
  246.     movl number_of_words, %eax
  247.     cmpl for_change_n, %eax
  248.     ja okey
  249.    not_okey:
  250.     leal string_9, %esi
  251.     movl $48, (%esi)
  252.     incl %esi
  253.     movl $10, (%esi)
  254.     incl %esi
  255.     movl $0, (%esi)
  256.    
  257.     movl $4, %eax
  258.     movl $1, %ebx
  259.     leal string_9, %ecx
  260.     movl $3, %edx
  261.     int $0x80
  262.     jmp end
  263.    okey:
  264.     #convert to string
  265.     subl for_change_n, %eax
  266.     leal string_9, %edi
  267.     movl $10, %ebx # base  
  268.    conv:
  269.     xorl %edx, %edx
  270.     divl %ebx
  271.     addb $48, %dl
  272.     movb %dl, (%edi)
  273.     incl %edi
  274.     incl n_size
  275.     andl %eax, %eax
  276.     jnz conv
  277.    
  278.     movb $10, (%edi)
  279.     incl %edi
  280.     movb $0, (%edi)
  281.     decl %edi
  282.     decl %edi
  283.     leal string_9, %esi
  284.    switch:
  285.     cmpl %edi, %esi
  286.     jae end_of_conv
  287.     movb (%esi), %ah
  288.     movb (%edi), %al
  289.     movb %al, (%esi)
  290.     movb %ah, (%edi)
  291.     decl %edi
  292.     incl %esi
  293.     jmp switch
  294.    end_of_conv:
  295.  
  296.     addl $2, n_size #for \n and \0
  297.  
  298.     movl $4, %eax
  299.     movl $1, %ebx
  300.     leal string_9, %ecx
  301.     movl n_size, %edx
  302.     int $0x80
  303.  
  304. end:
  305.     movl $1, %eax
  306.     movl $0, %ebx
  307.     int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement