Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- fin: .asciiz "pizda.c" # filename for input
- input: .space 4096
- output: .space 8192
- firstMsg: .asciiz "\nWczytany string:\n"
- secondMsg: .asciiz "\nPo obrobce\n"
- aux: .asciiz "\nhelp print:\n"
- hexdigits: .ascii "0123456789ABCDEFabcdef"
- octdigits: .ascii "01234567"
- .text
- ################################################ fileRead:
- # Open file for reading
- main:
- li $v0, 13 # system call for open file
- la $a0, fin # input file name
- li $a1, 0 # flag for reading
- li $a2, 0 # mode is ignored
- syscall # open a file
- move $s0, $v0 # save the file descriptor
- # reading from file just opened
- li $v0, 14 # system call for reading from file
- move $a0, $s0 # file descriptor
- la $a1, input # address of buffer from which to read
- li $a2, 4096 # hardcoded buffer length
- syscall # read from file
- # Close the file
- li $v0, 16 # system call for close file
- move $a0, $s0 # file descriptor to close
- syscall # close file
- la $a0, firstMsg #calling opening prompt
- li $v0, 4
- syscall
- la $a0, input #calling opening prompt
- li $v0, 4
- syscall
- xor $t0, $t0, $t0
- la $t9, output #output
- xor $s1, $s1, $s1 #whole string counter
- xor $s2, $s1, $s1 #word counter
- prep:
- li $t3, 0
- li $t4, 0
- iterate_word:
- lb $t1, input($t0) #word iterate, looking for white space
- beq $t1, ' ', word_end
- beq $t1, '\n', word_end
- beq $t1, '\0', word_end
- addiu $t0, $t0, 1
- addiu $s1, $s1, 1
- addiu $s2, $s2, 1
- j iterate_word
- word_end:
- move $t2, $t0
- subiu $t2, $t2, 1
- lb $t3, input($t2)
- #beq $t3, 'h', hexDetected
- #beq $t3, 'q', octDetected
- subu $t4, $s1, $s2
- normalWord:
- bgt $t4, $s1, endNormalWord
- lb $t3, input($t4)
- sb $t3, ($t9)
- la $a0, aux #calling opening prompt
- li $v0, 4
- syscall
- la $a0, output #calling opening prompt
- li $v0, 4
- syscall
- addiu $t4, $t4, 1
- addiu $t9, $t9, 1
- j normalWord
- endNormalWord:
- beq $s1, '\0', exit
- li $s2, 0
- addiu $t0, $t0, 1
- addiu $s1, $s1, 1
- j prep
- exit:
- la $a0, secondMsg #calling opening prompt
- li $v0, 4
- syscall
- la $a0, output #calling opening prompt
- li $v0, 4
- syscall
- li $v0,10 #Terminate
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement