| | |
MIPS: Print array in columns (SPIM)
![]() |
•
•
Join Date: Jun 2009
Posts: 6
Reputation:
Solved Threads: 0
I have written a code that prints array in 6 columns:
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.
Assembly Syntax (Toggle Plain Text)
# ----- # Print array elements. li $t1, 0 la $s0, py_sars print_lp1: bgt $t1, 59, print_end1 lw $a0, 0($s0) #get the value pointed by s0 li $v0, 1 #print int syscall la $a0, space li $v0, 4 #print space between each output syscall addi $t1, $t1, 1 #increment counter for next element addi $s0, $s0, 4 rem $t5, $t1, 6 #print areas in 6 columns beq $t5, $zero, newline j print_lp1 newline: la $a0, new_ln li $v0, 4 #print newline syscall j print_lp1 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.
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!
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!
![]() |
Similar Threads
- Print Array: strings! (C++)
- Print Array: strings! (C#)
- Problem storing numbers into an array from an input file (C)
- How to retrieve three columns using perl (Perl)
- 2d Array Help Please!!! (C++)
- how to print out an array in a message box (Java)
- infile into array and sort (C++)
- displaying two dimensional array in columns help (C++)
- printing double array formatting trouble (C)
- how to set up my for loop to print my array in reverse (Java)
Other Threads in the Assembly Forum
- Previous Thread: Two code snippets that should have the same effect but don't
- Next Thread: Factorial
| Thread Tools | Search this Thread |






