944,079 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 447
  • Assembly RSS
Oct 18th, 2009
0

Question about arrays

Expand Post »
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?

assembly Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zmwg is offline Offline
2 posts
since Oct 2009
Oct 19th, 2009
1
Re: Question about arrays
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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Oct 19th, 2009
0
Re: Question about arrays
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zmwg is offline Offline
2 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: need help how about assebly error
Next Thread in Assembly Forum Timeline: EMU8086 OS Command Comparison





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC