Need someone to run my mips code please

Thread Solved

Join Date: Sep 2007
Posts: 58
Reputation: Noliving is an unknown quantity at this point 
Solved Threads: 0
Noliving Noliving is offline Offline
Junior Poster in Training

Need someone to run my mips code please

 
0
  #1
26 Days Ago
Can someone run my mips code? I'm using pcSpim as my simulator

The issue I'm having is that it doesn't correctly output the number of othercharacters.

Other characters would be like !@#$%^&*()_+-=.,<>?/ \

The other problem I'm having is that it doesn't output the number of characters there are in the string inputted. If I get rid of the othercharacters loop then it will output or display the number of characters or the length of the string inputted.

Thank you to anyone who can help me!

  1. ## This program prints out the length of characters, digits, upper and lower case characters that are inputted through the user
  2. ## t0 holds each byte from input
  3. ## t1 contains the count of characteters
  4. ## t2 points to the input of characters
  5.  
  6. .data
  7.  
  8. input: .asciiz "Please enter up to eighty characters "
  9.  
  10. ans: .asciiz "\nThis is how many characters your input has "
  11.  
  12. anstwo: .asciiz "\nThis is how many uppercase characters your input has "
  13.  
  14. ansthree: .asciiz "\nThis is how many lowercase characters your input has "
  15.  
  16. ansfour: .asciiz "\nThis is how many digits your input has "
  17.  
  18. ansfive: .asciiz "\nThis is how many spaces your input has "
  19.  
  20. anssix: .asciiz "\nThis is how many othercharacters your input has "
  21.  
  22.  
  23.  
  24.  
  25.  
  26. buffer: .space 80
  27.  
  28. .text
  29. .globl main
  30. main:
  31.  
  32.  
  33. li $v0, 4 # system call code for print_str
  34. la $a0, input # address of string to print
  35. syscall # print the input
  36.  
  37. li $v0, 8 # code for syscall read_string
  38. la $a0, buffer # tell syscall where the buffer is
  39. li $a1, 80 # tell syscall how big the buffer is
  40. syscall
  41.  
  42. la $t2, buffer # t2 points to the input
  43. li $t1, 0 # t1 holds the count
  44.  
  45.  
  46.  
  47.  
  48. la $a0, buffer
  49. jal uppercasecount # call uppercasecount
  50.  
  51. la $t2, buffer # t2 points to the input
  52. li $t3, 0 # t3 holds the count for how many uppercase
  53.  
  54. la $a0, buffer
  55. jal lowercasecount # call lowercasecount
  56.  
  57. la $t2, buffer # t2 points to the input
  58. li $t4, 0 # t4 holds the count for how many lowercase
  59.  
  60. la $t2, buffer # t2 points to the input
  61. li $t5, 0 # t5 holds the count for how many digits
  62.  
  63. jal digitcount # call digitcount
  64.  
  65. la $t2, buffer # t2 points to the input
  66. li $t6, 0 # t6 holds the count for how many spaces
  67. jal spacecount # call spacecount
  68.  
  69.  
  70.  
  71.  
  72. la $t2, buffer
  73. #li $t7, 0
  74. jal Othercharacters
  75.  
  76.  
  77.  
  78.  
  79.  
  80. nextcharacter:
  81.  
  82.  
  83. lb $t0,($t2) # get a byte from the input
  84. beqz $t0, characterend # zero means it is the end of the input
  85. addi $t1, $t1, 1 # increment the count
  86. addi $t2,1 # move the pointer to the next character
  87. j nextcharacter # go through the next character loop again
  88.  
  89.  
  90.  
  91. characterend:
  92.  
  93. la $a0, ans # system call to print
  94. li $v0, 4 # out a message
  95. sub $t1, $t1, 1 # subtract 1 from count of characters to get correct number
  96. syscall
  97.  
  98.  
  99. move $a0, $t1 # system call to print
  100. li $v0, 1 # out the length worked out
  101. syscall
  102.  
  103. li $v0,10 # exit
  104. syscall
  105.  
  106. #
  107. #------------------------------------------------
  108. # uppercase - takes a single character as a
  109. # parameter and returns 1 if the character
  110. # is a uppercase otherwise return 0.
  111. # a0 - holds character
  112. # v0 - returns 0 or 1
  113. #------------------------------------------------
  114. uppercase:
  115. li $v0, 0 #
  116. beq $a0,'A',ucyes #beq means branch is equal to
  117. beq $a0,'B',ucyes
  118. beq $a0,'C',ucyes
  119. beq $a0,'D',ucyes
  120. beq $a0,'E',ucyes
  121. beq $a0,'F',ucyes
  122. beq $a0,'G',ucyes
  123. beq $a0,'H',ucyes
  124. beq $a0,'I',ucyes
  125. beq $a0,'J',ucyes
  126. beq $a0,'K',ucyes
  127. beq $a0,'L',ucyes
  128. beq $a0,'M',ucyes
  129. beq $a0,'N',ucyes
  130. beq $a0,'O',ucyes
  131. beq $a0,'P',ucyes
  132. beq $a0,'Q',ucyes
  133. beq $a0,'R',ucyes
  134. beq $a0,'S',ucyes
  135. beq $a0,'T',ucyes
  136. beq $a0,'U',ucyes
  137. beq $a0,'V',ucyes
  138. beq $a0,'W',ucyes
  139. beq $a0,'X',ucyes
  140. beq $a0,'Y',ucyes
  141. beq $a0,'Z',ucyes
  142. jr $ra # return (to the operating system)
  143.  
  144. ucyes:
  145. li $v0,1 # this is the code perform print_int
  146. jr $ra # return (to the operating system)
  147.  
  148.  
  149.  
  150. jr $ra
  151.  
  152. #------------------------------------------------
  153. # uppercasecount - use vowelp to count the vowels in a
  154. # string.
  155. # a0 - holds buffer address
  156. # t3 - holds number of uppercasecharacters
  157. # v0 - returns number of uppercasecharacters
  158. #------------------------------------------------
  159.  
  160. uppercasecount:
  161. sub $sp,$sp,16 # save registers on stack
  162. sw $a0,0($sp)
  163. sw $t3,4($sp)
  164. sw $s1,8($sp)
  165. sw $ra,12($sp)
  166.  
  167. li $t3,0 # count of vowels
  168. move $s1,$a0 # address of string
  169.  
  170.  
  171. nextcharacter2:
  172. lb $a0,($s1) # get each character
  173. beqz $a0,uppercasedone # zero marks end
  174. jal uppercase # call uppercase
  175. add $t3,$t3,$v0 # add 0 or 1 to count
  176. add $s1,$s1,1 # move along string
  177. j nextcharacter2
  178.  
  179.  
  180. uppercasedone:
  181.  
  182. la $a0, anstwo
  183. li $v0, 4
  184. syscall
  185.  
  186. move $a0, $t3 # system call to print
  187. li $v0, 1 # out the length worked out
  188. syscall
  189.  
  190.  
  191. lw $a0,0($sp) # restore registers
  192. lw $s0,4($sp)
  193. lw $t3,8($sp)
  194. lw $ra,12($sp)
  195. add $sp,$sp,16
  196. jr $ra
  197.  
  198.  
  199. #
  200. #------------------------------------------------
  201. # lowercase - takes a single character as a
  202. # parameter and returns 1 if the character
  203. # is a uppercase otherwise return 0.
  204. # a0 - holds character
  205. # v0 - returns 0 or 1
  206. #------------------------------------------------
  207. lowercase:
  208. li $v0, 0 #
  209. beq $a0,'a',lcyes #beq means branch is equal to
  210. beq $a0,'b',lcyes
  211. beq $a0,'c',lcyes
  212. beq $a0,'d',lcyes
  213. beq $a0,'e',lcyes
  214. beq $a0,'f',lcyes
  215. beq $a0,'g',lcyes
  216. beq $a0,'h',lcyes
  217. beq $a0,'i',lcyes
  218. beq $a0,'j',lcyes
  219. beq $a0,'k',lcyes
  220. beq $a0,'l',lcyes
  221. beq $a0,'m',lcyes
  222. beq $a0,'n',lcyes
  223. beq $a0,'o',lcyes
  224. beq $a0,'p',lcyes
  225. beq $a0,'q',lcyes
  226. beq $a0,'r',lcyes
  227. beq $a0,'s',lcyes
  228. beq $a0,'t',lcyes
  229. beq $a0,'u',lcyes
  230. beq $a0,'v',lcyes
  231. beq $a0,'w',lcyes
  232. beq $a0,'x',lcyes
  233. beq $a0,'y',lcyes
  234. beq $a0,'z',lcyes
  235. jr $ra # return (to the operating system)
  236.  
  237. lcyes:
  238. li $v0,1 # this is the code perform print_int
  239. jr $ra # return (to the operating system)
  240.  
  241.  
  242.  
  243.  
  244. #------------------------------------------------
  245. # lowercasecount - use lowercase to count the lowercase characters in a
  246. # string.
  247. # a0 - holds buffer address
  248. # t4 - holds number of lowercasecharacters
  249. # v0 - returns number of lowercasecharacters
  250. #------------------------------------------------
  251.  
  252. lowercasecount:
  253. sub $sp,$sp,16 # save registers on stack
  254. sw $a0,0($sp)
  255. sw $t4,4($sp)
  256. sw $s1,8($sp)
  257. sw $ra,12($sp)
  258.  
  259. li $t4,0 # count of lowercase
  260. move $s1,$a0 # address of string
  261.  
  262. nextcharacter3:
  263. lb $a0,($s1) # get each character
  264. beqz $a0,lowercasedone # zero marks end
  265. jal lowercase # call lowercase
  266. add $t4,$t4,$v0 # add 0 or 1 to count
  267. add $s1,$s1,1 # move along string
  268. j nextcharacter3
  269.  
  270.  
  271. lowercasedone:
  272.  
  273. la $a0, ansthree
  274. li $v0, 4
  275. syscall
  276.  
  277. move $a0, $t4 # system call to print
  278. li $v0, 1 # out the length worked out
  279. syscall
  280.  
  281.  
  282. lw $a0,0($sp) # restore registers
  283. lw $t4,4($sp)
  284. lw $s1,8($sp)
  285. lw $ra,12($sp)
  286. add $sp,$sp,16
  287.  
  288. jr $ra # return (to the operating system)
  289.  
  290.  
  291.  
  292.  
  293.  
  294. digit:
  295. li $v0, 0
  296. beq $a0,'1',dyes
  297. beq $a0,'2',dyes
  298. beq $a0,'3',dyes
  299. beq $a0,'4',dyes
  300. beq $a0,'5',dyes
  301. beq $a0,'6',dyes
  302. beq $a0,'7',dyes
  303. beq $a0,'8',dyes
  304. beq $a0,'9',dyes
  305. beq $a0,'0',dyes
  306.  
  307. jr $ra # return (to the operating system)
  308.  
  309.  
  310. dyes:
  311. li $v0,1
  312. jr $ra
  313.  
  314. digitcount:
  315.  
  316. sub $sp, $sp, 16
  317. sw $a0,0($sp)
  318. sw $t5,4($sp)
  319. sw $s1,8($sp)
  320. sw $ra,12($sp)
  321.  
  322. li $t5,0 # count of digits
  323. move $s1,$a0 # address of string
  324.  
  325. nextdigit:
  326. lb $a0,($s1) # get each character
  327. beqz $a0,digitdone # zero marks end
  328. jal digit # call digit
  329. add $t5,$t5,$v0 # add 0 or 1 to count
  330. add $s1,$s1,1 # move along string
  331. j nextdigit
  332.  
  333. digitdone:
  334. la $a0, ansfour
  335. li $v0, 4
  336. syscall
  337.  
  338. move $a0, $t5 # system call to print
  339. li $v0, 1 # out the length worked out
  340. syscall
  341.  
  342. lw $a0,0($sp) # restore registers
  343. lw $t5,4($sp)
  344. lw $s1,8($sp)
  345. lw $ra,12($sp)
  346. add $sp,$sp,16
  347. jr $ra
  348.  
  349. space:
  350. li $v0, 0
  351. beq $a0,' ',syes
  352.  
  353. jr $ra # return (to the operating system)
  354.  
  355. syes:
  356. li $v0,1
  357. jr $ra
  358.  
  359. spacecount:
  360.  
  361. sub $sp, $sp, 16
  362. sw $a0,0($sp)
  363. sw $t6,4($sp)
  364. sw $s1,8($sp)
  365. sw $ra,12($sp)
  366.  
  367. li $t6,0 # count of space
  368. move $s1,$a0 # address of string
  369.  
  370. nextspace:
  371.  
  372. lb $a0,($s1) # get each character
  373. beqz $a0,spacedone # zero marks end
  374. jal space # call space
  375. add $t6,$t6,$v0 # add 0 or 1 to count
  376. add $s1,$s1,1 # move along string
  377. j nextspace
  378.  
  379. spacedone:
  380.  
  381. la $a0, ansfive # how many spaces are in the characters
  382. li $v0, 4
  383. syscall
  384.  
  385. move $a0, $t6 # system call to print
  386. li $v0, 1 # out the length worked out
  387. syscall
  388.  
  389.  
  390. lw $a0,0($sp) # restore registers
  391. lw $t6,4($sp)
  392. lw $s1,8($sp)
  393. lw $ra,12($sp)
  394. add $sp,$sp,16
  395. jr $ra
  396.  
  397. Othercharacters:
  398. add $t7, $t3, $t4
  399. add $t8, $t5, $t6
  400. add $t9, $t8, $t7
  401.  
  402. sub $t9, $t2, $t9
  403.  
  404. li $v0, 4
  405. la $a0, anssix
  406. syscall
  407.  
  408. li $v0, 1
  409. move $a0, $t9
  410. syscall
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 58
Reputation: Noliving is an unknown quantity at this point 
Solved Threads: 0
Noliving Noliving is offline Offline
Junior Poster in Training
 
0
  #2
26 Days Ago
Ok good news, I was able to get my how many character output back, but I'm still having trouble getting the number of othercharacters to print.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 58
Reputation: Noliving is an unknown quantity at this point 
Solved Threads: 0
Noliving Noliving is offline Offline
Junior Poster in Training
 
0
  #3
26 Days Ago
Well I was able to get all of it to pretty much work.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC