Question about arrays

Reply

Join Date: Oct 2009
Posts: 2
Reputation: zmwg is an unknown quantity at this point 
Solved Threads: 0
zmwg zmwg is offline Offline
Newbie Poster

Question about arrays

 
0
  #1
Oct 18th, 2009
I'm writing a program that takes input for an an array. It then uses a loop to replace the values in another array that has preset values with the values from the array that received input.

When I try to move the values though...well let's say arrayA is the one with the preset values and arrayB is the one that has the inputted values. lw $t3, arrayB($t0) - yields an error, but lw $t3, arrayA($0) works. Is there another command that needs to be used when getting the value from an array that doesn't have preset content?

  1. .data
  2. strOutput: .asciiz "Input: "
  3. arrayA: .word 1,2,3,4
  4. arrayB: .space 16
  5. .text
  6. .globl main
  7. main:
  8.  
  9. li $v0, 4
  10. la $a0, strOutput
  11. syscall
  12.  
  13. la $t1,arrayB
  14. li $v0, 8
  15. la $a0, 0($t1)
  16. syscall
  17.  
  18. li $v0, 8
  19. la $a0, 4($t1)
  20. syscall
  21.  
  22. li $v0, 8
  23. la $a0, 8($t1)
  24. syscall
  25.  
  26. li $v0, 8
  27. la $a0, 12($t1)
  28. syscall
  29.  
  30. li $t0, 0
  31. lw $t3, arrayB($t0)

I know it's very basic, but I don't know if I'm missing a command or something. Using PCSpim.

And also the number replacement will be done with a loop hence why I'm using arrayB($t0) instead of something else...if that makes any sense at all.
Last edited by zmwg; Oct 18th, 2009 at 9:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
1
  #2
Oct 19th, 2009
I think you misunderstand the syscall function. It doesn't return a four byte integer. It returns a string!
You also aren't setting $a1 to maximum number of characters to read - 1. The function returns the string with a NULL terminaton.

$a0 = buffer
$a1 = sizeof buffer - 1
$v0 = 8 Function read string.

think you meant $v0 = 5 ? Upon return $v0 contains integer read!
Last edited by wildgoose; Oct 19th, 2009 at 12:35 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: zmwg is an unknown quantity at this point 
Solved Threads: 0
zmwg zmwg is offline Offline
Newbie Poster
 
0
  #3
Oct 19th, 2009
Ahh...I was copy pasting that part from a previous program. We just started assembly. Staring at the code feels kind of like mind screw compared to other stuff like C++.

I see what you're talking about though, I got it to work now. Thanks.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC