Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › MIPS Assembly Error "Can't expand stack segment by 8 bytes to 524288 bytes"
New Posts  All Forums:Forum Nav:

MIPS Assembly Error "Can't expand stack segment by 8 bytes to 524288 bytes"

post #1 of 7
Thread Starter 
I'm trying to make a letter puzzle solver. The puzzle consists of a grid 9x9 and given the letters A,B,C,D,E,F,G,H,I you must fill the blank spaces (filled with 0) with them so each line and column has one of each letters. I'm trying to find all the possible solutions and print them in the console but im having an infinite loop at the solve function and i don't know why... PLEASE HELP ME



.data

sol_msg1:
.asciiz "
solution"
sol_msg2:
.asciiz "
\n"
newln:
.asciiz "\n"
space:
.asciiz ""

symbols:.asciiz "ABCDEFGHI"

grid1:.ascii"00B4D0HF0"
grid2:.ascii"D0HBE0000"
grid3:.ascii"AG0C0000D"
grid4:.ascii"0A00000GF"
grid5:.ascii"F0EG0BCDA"
grid6:.ascii"0I00000BH"
grid7:.ascii"EB0I0000G"
grid8:.ascii"H0FEG0000"
grid9:.ascii"00GHB0FC0"

.text
.align 2
.globl main

main:
la $a0,grid1
#jal print_solution
li $a0,0
jal solve

exit:
li $v0,10
syscall

print_solution:

addi $sp,-16#setup stack frame
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)

li $t2,0#initialize the counters
li $t3,0
move $s0,$a0#load the parameter
print_loop:
add $s0,$s0,$t2#get the specific letter to print
lb $t6,0($s0)

li $v0,11
move $a0,$t6#print that character
syscall

addi $t3,1#counters++
addi $t2,1

bne $t3,3,cont1#print the space
li $t3,0
li $v0,4
la $a0,space
syscall
cont1:
div $t5,$t2,9#print the new line
mfhi $t5
bne $t5,0,cont2
li $v0,4
la $a0,newln
syscall

cont2:
la $s0,grid1
blt $t2,81,print_loop#call the loop
li $v0,4
la $a0,newln#each time a grid is done printing
syscall#print to new lines to separate
syscall
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp,16#destroy stack

jr $ra#return

safe:
addi $sp,-16#setup stack frame
sw $t2,12($sp)#store the registers values
sw $ra,0($sp)
sw $s0,4($sp)
sw $s1,8($sp)


move $s0,$a0#load the parameter

li $t0,9
div $s0,$t0
mflo $t0#Row index
mfhi $t1#Column index

move $s0,$a1#Load character argument
la $s1,grid1

mul $s2,$t0,9
add $s2,$s2,$t1
add $s1,$s1,$s2#gridPtr+row*COLUNMS)+col
lb $t3,0($s1)

bne $t3,$s0,step2
li $v0,1
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp,16#destroy stack
jr $ra#return 1

step2:
lb $t3,0($s1)
beq $t3,48,step3
li $v0,0
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp,16#destroy stack
jr $ra#return 0

step3:

li $t2,0
st3_loop:
sub $s1,$s1,$t1 #gridPtr+row*COLUNMS
add $s1,$s1,$t2
lb $t3,0($s1)
bne $t3,$s0,st3_cont
li $v0,0
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp,16#destroy stack
jr $ra#return 0

st3_cont:
sub $s1,$s1,$t2#gridPtr+row*COLUNMS
addi $t2,1
bne $t2,9,st3_loop

step4:

li $t2,0
la $s1,grid1
add $s1,$s1,$t1#gridPtr+col

st4_loop:
move $s2,$t2
mul $s2,$s2,9#r*COLUMNS
add $s1,$s1,$s2#gridPtr+r*COLUNMS)+col
lb $t3,0($s1)
bne $t3,$s0,st4_cont
li $v0,0
lw $t2,12($sp)#re-store the registers values
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp,16#destroy stack
jr $ra#return 0

st4_cont:
addi $t2,1
la $s1,grid1
add $s1,$s1,$t1#gridPtr+col
bne $t2,9,st4_loop

li $v0,1
lw $t2,24($sp)#re-store the registers values
lw $ra,16($sp)
lw $t0,12($sp)
lw $t1,8($sp)
lw $s0,4($sp)
lw $s1,0($sp)
lw $s2,20($sp)
addi $sp,28#destroy stack
jr $ra#return 1

solve:
addi $sp,-16#setup the stack frame
sw $ra,0($sp)#store the previous registers values
sw $s1,4($sp)
sw $t2,8($sp)
sw $s0,12($sp)
move $s0,$a0#load the parameter

li $t0,9
div $s0,$t0
mflo $t0#calculate Row index
mfhi $t1#calculate Column index

bne $t0,9,solv_cont1#if a solution is fount
la $s3,grid1
move $a0,$s3
jal print_solution#call print_solution
move $s3,$a0

solv_cont1:
li $t2,1
move $a0,$s0
la $s1,symbols
add $s1,$s1,$t2
addi $s1,-1#symbols[n-1]
lb $t3,0($s1)
move $a1,$t3
jal safe
beqz $v0,solv_cont2

solv_cont2:
la $s3,grid1
mul $s2,$t0,9
add $s2,$s2,$t1
add $s3,$s3,$s2#gridPtr+row*COLUNMS)+col
#t = $t4
lb $t4,0($s3)#t = *((gridPtr+row*COLUNMS)+col)
sb $t3,0($s3)#*((gridPtr+row*COLUNMS)+col)=symbols[n-1]

bne $t1,8,solv_cont3
addi $t0,1#counter++
move $a0,$s0

jal solve#call solve

solv_cont3:
addi $s0,1
move $a0,$s0

jal solve#call solve

sb $t4,0($s3)
addi $t2,1
bne $t2,9,solve

lw $ra,0($sp)#restore the previous registers values
lw $s1,4($sp)
lw $t2,8($sp)
lw $s0,12($sp)

addi $sp,12#destroy stack

jr $ra#return

Edited by drummerfist - 10/28/13 at 10:23pm
post #2 of 7
Thread Starter 
Please guys ... this is urgent!!!
post #3 of 7
I hate your code. I don't really know MIPS, but I do know IA-32. However I can't really read it because you have zero comments on your code, when you should have almost one per line.... It's something you should do when programming in assembly.

Try to comment each line in your code, and probably you will find the error yourself!
Competitive CS:GO
(15 items)
 
  
CPUMotherboardGraphicsRAM
A10-6800k gigabyte GA-F2A88XM-HD3 iGPU TridentX 2x4gb @2400mhz CL10 
Hard DriveOptical DriveCoolingOS
crucial m4 256gb none Stock.. 8 pro + mint 15 cinnamon 
MonitorKeyboardPowerMouse
SyncMaster 997 mb (crt) random TR2 600w CM Storm Spawn 
Mouse PadAudio
QcK+ Shure SRH 750DJ+FiiO E5 
  hide details  
Reply
Competitive CS:GO
(15 items)
 
  
CPUMotherboardGraphicsRAM
A10-6800k gigabyte GA-F2A88XM-HD3 iGPU TridentX 2x4gb @2400mhz CL10 
Hard DriveOptical DriveCoolingOS
crucial m4 256gb none Stock.. 8 pro + mint 15 cinnamon 
MonitorKeyboardPowerMouse
SyncMaster 997 mb (crt) random TR2 600w CM Storm Spawn 
Mouse PadAudio
QcK+ Shure SRH 750DJ+FiiO E5 
  hide details  
Reply
post #4 of 7
Thread Starter 
Thank you for replying ! I tried putting comments but the editor gave me some errors. I will try again!
post #5 of 7
Quote:
Originally Posted by drummerfist View Post

Thank you for replying ! I tried putting comments but the editor gave me some errors. I will try again!

How come? O.O That makes no sense.. Hehehe

In MIPS assembly, comments are denoted with a number sign ("#"). Everything after that sign on the same line is a comment. Are you sure you are doing it right?


The reason for commenting is that it's hard for humans to understand the meaning of the codes, specially if it's a big code. Assembly has a simple syntax, but you should comment every line.
Competitive CS:GO
(15 items)
 
  
CPUMotherboardGraphicsRAM
A10-6800k gigabyte GA-F2A88XM-HD3 iGPU TridentX 2x4gb @2400mhz CL10 
Hard DriveOptical DriveCoolingOS
crucial m4 256gb none Stock.. 8 pro + mint 15 cinnamon 
MonitorKeyboardPowerMouse
SyncMaster 997 mb (crt) random TR2 600w CM Storm Spawn 
Mouse PadAudio
QcK+ Shure SRH 750DJ+FiiO E5 
  hide details  
Reply
Competitive CS:GO
(15 items)
 
  
CPUMotherboardGraphicsRAM
A10-6800k gigabyte GA-F2A88XM-HD3 iGPU TridentX 2x4gb @2400mhz CL10 
Hard DriveOptical DriveCoolingOS
crucial m4 256gb none Stock.. 8 pro + mint 15 cinnamon 
MonitorKeyboardPowerMouse
SyncMaster 997 mb (crt) random TR2 600w CM Storm Spawn 
Mouse PadAudio
QcK+ Shure SRH 750DJ+FiiO E5 
  hide details  
Reply
post #6 of 7
Thread Starter 
I edited the code and added comments. Please help me i can't find the reason for the error. It seems to be an endless loop but i don't know where.
post #7 of 7
Thread Starter 
I found the solution to the stack overflow. But now i have another problem. The results are multiple solutions of the puzzle but the letters are in wrong position and there are zeros still in them..please guys help...
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › MIPS Assembly Error "Can't expand stack segment by 8 bytes to 524288 bytes"