MIPS: Print array in columns (SPIM)

Reply

Join Date: Jun 2009
Posts: 6
Reputation: pokerstar is an unknown quantity at this point 
Solved Threads: 0
pokerstar pokerstar is offline Offline
Newbie Poster

MIPS: Print array in columns (SPIM)

 
0
  #1
Jun 29th, 2009
I have written a code that prints array in 6 columns:
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: MIPS: Print array in columns (SPIM)

 
0
  #2
Jun 29th, 2009
- format integer as a string in some memory buffer
- measure it's length
- output 8-len spaces
- output buffer
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

Re: MIPS: Print array in columns (SPIM)

 
0
  #3
Jun 29th, 2009
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!
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

Re: MIPS: Print array in columns (SPIM)

 
0
  #4
Jun 29th, 2009
You can also print character by character but your column position logic remains the same. Instead of inserting spaces, write spaces.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 6
Reputation: pokerstar is an unknown quantity at this point 
Solved Threads: 0
pokerstar pokerstar is offline Offline
Newbie Poster

Re: MIPS: Print array in columns (SPIM)

 
0
  #5
Jun 30th, 2009
Thanks all! Working on that part of my program now.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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