Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. .data
  2. fin: .asciiz "pizda.c" # filename for input
  3.  
  4. input: .space 4096
  5. output: .space 8192
  6.  
  7. firstMsg: .asciiz "\nWczytany string:\n"
  8. secondMsg: .asciiz "\nPo obrobce\n"
  9. aux: .asciiz "\nhelp print:\n"
  10.  
  11. hexdigits: .ascii "0123456789ABCDEFabcdef"
  12. octdigits: .ascii "01234567"
  13.  
  14. .text
  15.  
  16. ################################################ fileRead:
  17.  
  18. # Open file for reading
  19. main:
  20. li $v0, 13 # system call for open file
  21. la $a0, fin # input file name
  22. li $a1, 0 # flag for reading
  23. li $a2, 0 # mode is ignored
  24. syscall # open a file
  25. move $s0, $v0 # save the file descriptor
  26.  
  27. # reading from file just opened
  28.  
  29. li $v0, 14 # system call for reading from file
  30. move $a0, $s0 # file descriptor
  31. la $a1, input # address of buffer from which to read
  32. li $a2, 4096 # hardcoded buffer length
  33. syscall # read from file
  34. # Close the file
  35. li $v0, 16 # system call for close file
  36. move $a0, $s0 # file descriptor to close
  37. syscall # close file
  38.  
  39. la $a0, firstMsg #calling opening prompt
  40. li $v0, 4
  41. syscall
  42.  
  43.  
  44. la $a0, input #calling opening prompt
  45. li $v0, 4
  46. syscall
  47.  
  48. xor $t0, $t0, $t0
  49.  
  50. la $t9, output #output
  51.  
  52. xor $s1, $s1, $s1 #whole string counter
  53. xor $s2, $s1, $s1 #word counter
  54.  
  55. prep:
  56. li $t3, 0
  57. li $t4, 0
  58.  
  59. iterate_word:
  60. lb $t1, input($t0) #word iterate, looking for white space
  61. beq $t1, ' ', word_end
  62. beq $t1, '\n', word_end
  63. beq $t1, '\0', word_end
  64. addiu $t0, $t0, 1
  65. addiu $s1, $s1, 1
  66. addiu $s2, $s2, 1
  67. j iterate_word
  68.  
  69. word_end:
  70. move $t2, $t0
  71. subiu $t2, $t2, 1
  72. lb $t3, input($t2)
  73. #beq $t3, 'h', hexDetected
  74. #beq $t3, 'q', octDetected
  75. subu $t4, $s1, $s2
  76.  
  77. normalWord:
  78. bgt $t4, $s1, endNormalWord
  79. lb $t3, input($t4)
  80. sb $t3, ($t9)
  81.  
  82. la $a0, aux #calling opening prompt
  83. li $v0, 4
  84. syscall
  85.  
  86. la $a0, output #calling opening prompt
  87. li $v0, 4
  88. syscall
  89.  
  90. addiu $t4, $t4, 1
  91. addiu $t9, $t9, 1
  92. j normalWord
  93.  
  94. endNormalWord:
  95. beq $s1, '\0', exit
  96.  
  97. li $s2, 0
  98. addiu $t0, $t0, 1
  99. addiu $s1, $s1, 1
  100. j prep
  101.  
  102. exit:
  103. la $a0, secondMsg #calling opening prompt
  104. li $v0, 4
  105. syscall
  106.  
  107. la $a0, output #calling opening prompt
  108. li $v0, 4
  109. syscall
  110.  
  111. li $v0,10 #Terminate
  112. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement