I\'m struggling with learning MIPS right now, and I\'m finding it isn\'t as easy
ID: 3846369 • Letter: I
Question
I'm struggling with learning MIPS right now, and I'm finding it isn't as easy as C++ was.
Right now, I'm to edit/write a program that will take ten number's from a user, then print those numbers out at the end with commas between them, and no comma after the last number.
Example:
This is the given code:
Where I believe I'm struggling at is the "print" portion. I have the following for printstr: and for getdata:
And then this is the code I've been trying to use for the print instruction...
However, when I run the program it spits out "268500992, ,". So I'm not getting my input numbers or the correct number of commas even. I know that means that my loop isn't running all the way through. I'm not supposed to use and pseudo code, and only what I've learned so far - so array's are out of the question.
Can someone help me figure out what I'm missing? Does it have something to do with the stack values (which I don't completely understand)?
Someone please answer w/o copy pasting my question and help me understand the code... Thanks.
Explanation / Answer
You can use this codde this will work.
$LFB0 = .
main:
addiu $sp,$sp,-80
sw $31,76($sp)
sw $fp,72($sp)
move $fp,$sp
sw $0,24($fp)
lw $2,24($fp)
nop
slt $2,$2,10
beq $2,$0,$L2
nop
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
jal printf
nop
addiu $3,$fp,28
lw $2,24($fp)
nop
sll $2,$2,2
addu $2,$3,$2
move $5,$2
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
jal scanf
nop
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
b $L3
nop
lw $2,28($fp)
nop
move $5,$2
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
jal printf
nop
li $2,1 # 0x1
sw $2,24($fp)
lw $2,24($fp)
nop
slt $2,$2,10
beq $2,$0,$L4
nop
lw $2,24($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,4($2)
nop
move $5,$2
lui $2,%hi($LC2)
addiu $4,$2,%lo($LC2)
jal printf
nop
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
b $L5
nop
move $2,$0
move $sp,$fp
lw $31,76($sp)
lw $fp,72($sp)
addiu $sp,$sp,80
j $31
nop