re: [MIPS] 100 characters String and printing it in 10 lines at a time. [assembly]

0

I'm having issues again solving these small task I got. Basically I got a board stored in 1 line, and I need to print 10 characters in 1 line and then break and so on. It's a board of 10 x 10, so it should run 10 times printing 10 character lines.

Something like this:

board: .asciiz " x xx x x x x xxx x x x x x xxxx x x x xx x x xx"

For this we got handed 2 subroutines, print and printlf. print takes in $a0 the string to print, and in $a1 the length, so I just need to jal print once I get the correct characters stored in the registers.

I was reading how to solve this on the internet and got to this source.

write_board:
   ##TODO Implement your solution here ###

  sw $a1, size           #I save 10 in length a1
  la $t0, board          #load the board on t0
  add $t1, $zero, $zero  #counter in t1 set to 0 for chars
  add $t5, $zero, $zero  #counter in t5 for the 10 loops
  li $t3, 10             #10 for the division in t3

count:
  lb $t2, 0($t0)
  addi $t1, $t1, 1
  div $t1, $t3  
  mfhi $t4                   #the remainder of div is in t4
  beq $t4, $zero, lineBreak  #if its 0 then break
  j count   

lineBreak:
  sw $t2, 0($a0)             #save the first 10 chars in a0 for printing
  jal print
  jal print_lf
  addi $t5, $t5, 1           #there needs to be 10 prints, we add 1 everytime one happens
  beq $t5, $t3 endString     #if its 10, the program is over
  j count 

 endString:
    jr $ra

.data
  size:
 .word      10

 board:
    .asciiz     "    x xx   x  x      x  x  xxx x  x         x   x         x xxxx  x x       x   xx    x         x xx"

This doesn't seem to work on QTSpim, it gives this error: Exception occurred at PC=0x004000e4 Unaligned address in store: 0x00000001

Anyone kind enough to maybe know a bug to this simple task yet hard for me.

Thanks in advance.

string
loops
assembly
mips

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0