Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .data
- ######################################################
- # strings & constants
- ######################################################
- # const string
- ######################################################
- string_0: .ascii "Unesite N: \0"
- string_len_0 = .-string_0
- string_1: .ascii "Unesite string: \0"
- string_len_1 = .-string_1
- string_2: .ascii "Greska u konverziji!\n\0"
- string_len_2 = .-string_2
- string_3: .ascii "Broj reci sa svim malim slovima: \0"
- string_len_3 = .-string_3
- string_4: .ascii "Uneli ste prazan string!\n\0"
- string_len_4 = .-string_4
- string_5: .ascii "Izlazni string: \0"
- string_len_5 = .-string_5
- string_6: .ascii "Broj reci sa svim malim slovima: \0"
- string_len_6 = .-string_6
- ######################################################
- # strings for input
- ######################################################
- max_sizeof_n = 50
- string_7: .fill max_sizeof_n,1,0 #N
- #string for change
- max_size = 80
- #input
- string_8: .fill max_size,1,0
- string_9: .fill max_sizeof_n,1,0
- ######################################################
- # variables
- ######################################################
- for_change_n: .long 0 # number of words to change
- number_of_words: .long 0
- input_string_len: .long 0
- n_size: .long 0
- .section .text
- ######################################################
- # actual code
- ######################################################
- .globl main
- main:
- print: #Unesite N:
- movl $4, %eax
- movl $1, %ebx
- leal string_0, %ecx
- movl $string_len_0, %edx
- int $0x80
- #actual input string
- movl $3, %eax
- movl $0, %ebx
- leal string_7, %ecx
- movl $max_sizeof_n, %edx
- int $0x80
- #check empty string
- cmpl $1, %eax #string contains only newline character
- jne not_empty_str
- #? string is empty print string_4
- movl $4, %eax
- movl $1, %ebx
- leal string_4, %ecx
- movl $string_len_4, %edx
- int $0x80
- jmp print #request another input
- not_empty_str:
- xorl %eax, %eax
- movl $10, %ebx
- xorl %ecx, %ecx
- xorl %edx, %edx
- movl $string_7, %esi
- #base is stored in ebx
- conversion:
- cmpb $10, (%esi)
- je end_of_conversion
- movb (%esi), %cl
- cmpb $'0', %cl
- jl conversion_error
- cmpb $'9', %cl
- jnbe conversion_error
- subb $'0', %cl
- mull %ebx
- cmpl $0 , %edx
- jne conversion_error
- addl %ecx, %eax
- jo conversion_error
- incl %esi
- jmp conversion
- conversion_error:
- #print conversion error string_2
- movl $4, %eax
- movl $1, %ebx
- leal string_2, %ecx
- movl $string_len_2, %edx
- int $0x80
- jmp print
- end_of_conversion:
- #save output
- movl %eax, for_change_n
- #enter to change string
- movl $4, %eax
- movl $1, %ebx
- leal string_1, %ecx
- movl $string_len_1, %edx
- int $0x80
- #real input
- movl $3, %eax
- movl $0, %ebx
- leal string_8, %ecx
- movl $max_size, %edx
- int $0x80
- #? is empty
- cmpl $1, %eax
- jne not_empty_Cstring
- #empty
- movl $4, %eax
- movl $1, %ebx
- leal string_4, %ecx
- movl $string_len_4, %edx
- int $0x80
- #request input again
- jmp not_empty_str
- not_empty_Cstring:
- movl %eax, input_string_len #save lenght
- xorl %eax, %eax #
- xorl %ebx, %ebx # was char (1) or not (0)
- xorl %edx, %edx # how many words we have changed
- leal string_8, %esi
- movl for_change_n, %ecx
- vip_loop:
- cmpb $10, (%esi)
- je end_of_vip_loop
- movb (%esi), %al
- cmpb $48, (%esi) # < 0
- jb dont_take_it
- cmpb $58, (%esi) # <= 9
- jb take_it
- cmpb $65, (%esi) # < A
- jb dont_take_it
- cmpb $91, (%esi) # <= Z
- jb take_it
- cmpb $95, (%esi) # underscore
- je take_it
- cmpb $97, (%esi) # < a
- jb dont_take_it
- cmpb $123, (%esi) # <= z
- jb take_it
- # (esi) > z than
- dont_take_it:
- xorl %ebx, %ebx
- jmp next
- take_it:
- # there was a special?
- cmpl $0, %ebx
- jne there_wasnt_a_special
- #there was special
- incl number_of_words # new word
- incl %edx
- movl $1, %ebx
- #check if edx is less than ecx
- cmpl %edx, %ecx
- jae change_first_char_to_upper
- #change to lowercase
- cmpb $58, (%esi)
- jb next
- cmpb $90, (%esi)
- ja next
- addb $32, (%esi)
- jmp next
- change_first_char_to_upper:
- cmpb $58, (%esi)
- jb next
- cmpb $91, (%esi)
- jb next
- subb $32, (%esi)
- jmp next
- there_wasnt_a_special:
- movl $1, %ebx
- cmpb $58, (%esi)
- jb next
- cmpb $96, (%esi)
- ja next
- addb $32, (%esi)
- next:
- incl %esi
- jmp vip_loop
- end_of_vip_loop:
- exit_print:
- # print "Izlazni string: "
- movl $4, %eax
- movl $1, %ebx
- leal string_5, %ecx
- movl $string_len_5, %edx
- int $0x80
- movl $4, %eax
- movl $1, %ebx
- leal string_8, %ecx
- movl input_string_len, %edx
- int $0x80
- #printf "Broj reci sa svim malim slovima: "
- movl $4, %eax
- movl $1, %ebx
- leal string_6, %ecx
- movl $string_len_6, %edx
- int $0x80
- movl number_of_words, %eax
- cmpl for_change_n, %eax
- ja okey
- not_okey:
- leal string_9, %esi
- movl $48, (%esi)
- incl %esi
- movl $10, (%esi)
- incl %esi
- movl $0, (%esi)
- movl $4, %eax
- movl $1, %ebx
- leal string_9, %ecx
- movl $3, %edx
- int $0x80
- jmp end
- okey:
- #convert to string
- subl for_change_n, %eax
- leal string_9, %edi
- movl $10, %ebx # base
- conv:
- xorl %edx, %edx
- divl %ebx
- addb $48, %dl
- movb %dl, (%edi)
- incl %edi
- incl n_size
- andl %eax, %eax
- jnz conv
- movb $10, (%edi)
- incl %edi
- movb $0, (%edi)
- decl %edi
- decl %edi
- leal string_9, %esi
- switch:
- cmpl %edi, %esi
- jae end_of_conv
- movb (%esi), %ah
- movb (%edi), %al
- movb %al, (%esi)
- movb %ah, (%edi)
- decl %edi
- incl %esi
- jmp switch
- end_of_conv:
- addl $2, n_size #for \n and \0
- movl $4, %eax
- movl $1, %ebx
- leal string_9, %ecx
- movl n_size, %edx
- int $0x80
- end:
- movl $1, %eax
- movl $0, %ebx
- int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement