Guest User

Untitled

a guest
Dec 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. .data
  2. input: .asciiz "\nPrzed zamiana stalych:\n"
  3. output: .asciiz "\nPo zamianie stalych:\n"
  4. fin: .asciiz "text.txt" # filename for input
  5. fout: .asciiz "after.c"
  6. buffer: .space 4096
  7. processingBuffer: .space 8192
  8. .text
  9.  
  10. ################################################ fileRead:
  11.  
  12. # Open file for reading
  13.  
  14. li $v0, 13 # system call for open file
  15. la $a0, fin # input file name
  16. li $a1, 0 # flag for reading
  17. li $a2, 0 # mode is ignored
  18. syscall # open a file
  19. move $s0, $v0 # save the file descriptor
  20.  
  21. # reading from file just opened
  22.  
  23. li $v0, 14 # system call for reading from file
  24. move $a0, $s0 # file descriptor
  25. la $a1, buffer # address of buffer from which to read
  26. li $a2, 4096 # hardcoded buffer length
  27. syscall # read from file
  28. # Close the file
  29. li $v0, 16 # system call for close file
  30. move $a0, $s0 # file descriptor to close
  31. syscall # close file
  32.  
  33.  
  34. la $a0, input #calling opening prompt
  35. li $v0, 4
  36. syscall
  37.  
  38. la $a0, buffer #calling opening prompt
  39. li $v0, 4
  40. syscall
  41.  
  42. li $t0, 0
  43. la $t7, processingBuffer
  44. li $t8, 0
  45. li $t9, 'x'
  46.  
  47. checkChar:
  48. lb $t1, buffer($t0)
  49. beqz $t1, finish
  50. blt $t1, '0', copy
  51. bgt $t1, '9', copy
  52.  
  53. digitFound:
  54. la $t2, ($t0)
  55.  
  56. checkForHexOrOct:
  57. addi $t2, $t2, 1
  58. lb $t3, buffer($t2)
  59. beq $t3, 'h', toHex
  60. beq $t3, 'q', toOct
  61. blt $t3, '0', endOfNumber
  62. bgt $t3, '9', endOfNumber
  63. j checkForHexOrOct
  64.  
  65. toHex:
  66. sb $t9, ($t7)
  67. addi $t7, $t7, 1
  68. sb $t8, ($t7)
  69. addi $t7, $t7, 1
  70.  
  71. copyHexNumber:
  72. sb $t1, ($t7)
  73. addi $t0, $t0, 1
  74. addi $t7, $t7, 1
  75. lb $t1, buffer($t0)
  76. bne $t1, $t3, copyHexNumber
  77. j checkChar
  78.  
  79. toOct:
  80. sb $t8, ($t7)
  81. addi $t7, $t7, 1
  82.  
  83. copyOctNumber:
  84. sb $t1, ($t7)
  85. addi $t7, $t7, 1
  86. addi $t0, $t0, 1
  87. lb $t1, buffer($t0)
  88. bne $t1, $t3, copyOctNumber
  89. j checkChar
  90.  
  91. endOfNumber:
  92. sb $t1, ($t7)
  93. addi $t0, $t0, 1
  94. addi $t7, $t7, 1
  95. lb $t1, buffer($t0)
  96. bgt $t1, $t3, checkChar
  97. j endOfNumber
  98.  
  99. copy:
  100. sb $t1, ($t2)
  101. addi $t2, $t2, 1
  102. addi $t0, $t0, 1
  103. j checkChar
  104.  
  105. finish:
  106. la $a0, output #calling opening prompt
  107. li $v0, 4
  108. syscall
  109. li $v0, 4
  110. la $a0, processingBuffer
  111. syscall
Advertisement
Add Comment
Please, Sign In to add comment