Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- input: .asciiz "\nPrzed zamiana stalych:\n"
- output: .asciiz "\nPo zamianie stalych:\n"
- fin: .asciiz "text.txt" # filename for input
- fout: .asciiz "after.c"
- buffer: .space 4096
- processingBuffer: .space 8192
- .text
- ################################################ fileRead:
- # Open file for reading
- 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, buffer # 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, input #calling opening prompt
- li $v0, 4
- syscall
- la $a0, buffer #calling opening prompt
- li $v0, 4
- syscall
- li $t0, 0
- la $t7, processingBuffer
- li $t8, 0
- li $t9, 'x'
- checkChar:
- lb $t1, buffer($t0)
- beqz $t1, finish
- blt $t1, '0', copy
- bgt $t1, '9', copy
- digitFound:
- la $t2, ($t0)
- checkForHexOrOct:
- addi $t2, $t2, 1
- lb $t3, buffer($t2)
- beq $t3, 'h', toHex
- beq $t3, 'q', toOct
- blt $t3, '0', endOfNumber
- bgt $t3, '9', endOfNumber
- j checkForHexOrOct
- toHex:
- sb $t9, ($t7)
- addi $t7, $t7, 1
- sb $t8, ($t7)
- addi $t7, $t7, 1
- copyHexNumber:
- sb $t1, ($t7)
- addi $t0, $t0, 1
- addi $t7, $t7, 1
- lb $t1, buffer($t0)
- bne $t1, $t3, copyHexNumber
- j checkChar
- toOct:
- sb $t8, ($t7)
- addi $t7, $t7, 1
- copyOctNumber:
- sb $t1, ($t7)
- addi $t7, $t7, 1
- addi $t0, $t0, 1
- lb $t1, buffer($t0)
- bne $t1, $t3, copyOctNumber
- j checkChar
- endOfNumber:
- sb $t1, ($t7)
- addi $t0, $t0, 1
- addi $t7, $t7, 1
- lb $t1, buffer($t0)
- bgt $t1, $t3, checkChar
- j endOfNumber
- copy:
- sb $t1, ($t2)
- addi $t2, $t2, 1
- addi $t0, $t0, 1
- j checkChar
- finish:
- la $a0, output #calling opening prompt
- li $v0, 4
- syscall
- li $v0, 4
- la $a0, processingBuffer
- syscall
Advertisement
Add Comment
Please, Sign In to add comment