943,666 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2713
  • Assembly RSS
Jun 29th, 2009
0

MIPS: Print array in columns (SPIM)

Expand Post »
I have written a code that prints array in 6 columns:
Assembly Syntax (Toggle Plain Text)
  1. # -----
  2. # Print array elements.
  3.  
  4.  
  5. li $t1, 0
  6. la $s0, py_sars
  7.  
  8. print_lp1:
  9. bgt $t1, 59, print_end1
  10.  
  11. lw $a0, 0($s0) #get the value pointed by s0
  12. li $v0, 1 #print int
  13. syscall
  14.  
  15. la $a0, space
  16. li $v0, 4 #print space between each output
  17. syscall
  18.  
  19. addi $t1, $t1, 1 #increment counter for next element
  20. addi $s0, $s0, 4
  21. rem $t5, $t1, 6 #print areas in 6 columns
  22. beq $t5, $zero, newline
  23. j print_lp1
  24.  
  25. newline:
  26. la $a0, new_ln
  27. li $v0, 4 #print newline
  28. syscall
  29. j print_lp1
  30.  
  31. print_end1:

I can't get the elements aligned however.
We can asume that the longest length of the integer is 8, and must be right justified.
Could you please guide me on how to do this?
Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokerstar is offline Offline
6 posts
since Jun 2009
Jun 29th, 2009
0

Re: MIPS: Print array in columns (SPIM)

- format integer as a string in some memory buffer
- measure it's length
- output 8-len spaces
- output buffer
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 29th, 2009
0

Re: MIPS: Print array in columns (SPIM)

Use a static buffer 256 or so bytes in size. Plenty of room!

You can subtract the current add new character position from the buffer base to get your index. Do a modulus operation and advance that many slots by inserting spaces.
OR you can have a moving partition.

NEXT = THIS + 12 space.
print column entry,
If THIS < NEXT
SKIP = NEX - THIS print skip spaces.

OR prefill entire buffer with spaces (0x20).
Then merely skip, no fill needed since its prefilled.
But don't forget your ASCIIz terminator after the last column!
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jun 29th, 2009
0

Re: MIPS: Print array in columns (SPIM)

You can also print character by character but your column position logic remains the same. Instead of inserting spaces, write spaces.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jun 30th, 2009
0

Re: MIPS: Print array in columns (SPIM)

Thanks all! Working on that part of my program now.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokerstar is offline Offline
6 posts
since Jun 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: Two code snippets that should have the same effect but don't
Next Thread in Assembly Forum Timeline: Factorial





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


Follow us on Twitter


© 2011 DaniWeb® LLC