0

it compiles but in the output, it does not show anywhere I can input numbers. Have any idea?

.data
msg1:  .asciiz "array printing "
msg2:   .asciiz  "enter the number of rows: "
msg3:   .asciiz "enter the number of cols: "
msg4:   .asciiz "the value at the location is:  "
EOL:    .byte  '\n'
SPACES:   .asciiz "  "
MATRIX:   .word   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
.text
.globl main
main:
li   $v0,4
la  $a0,msg1
syscall
addiu $sp,$sp,-4
sw  $ra,0($sp)
jal  PRTMTX
lw  $ra,0($sp)
addiu  $sp,$sp,4
li $v0, 10
syscall
PRTMTX:
la $s0, MATRIX
li $s1,1
li $s2,1
li $s6,5

TOPPRT:
addiu $t1,$s1,-1
addiu $t2,$s2,-1
li $t4,20
li $t5,4
mul $t1,$t1,$t4
mul $t2,$t2,$t5
add $s4,$s0,$t1
add $s4,$s4,$t2
li $v0,1
lw $a0,0($s4)
syscall
li $v0,4
la $a0,SPACES
syscall
li $t6,5
div $s2,$t6
mfhi $t6
beqz $t6,ENDROW
addiu $s2,$s2,1
j TOPPRT
ENDROW:  li $s2,1
li $v0, 11
lb $a0,EOL
syscall
li $t6,5
div $s1,$t6
mfhi $t6
beqz $t6,DONEPRT
addiu $s1,$s1,1
j TOPPRT
DONEPRT: 
jr $ra
PRTNUM:
move $t1,$a0
move $t2,$a1
addiu $t1,$t1,-1
addiu $t2,$t2,-1
li $t3,20
mul $t1,$t1,$t3
li $t3,4
mul $t2,$t2,$t3
la $s0,MATRIX
add $s0,$s0,$t1
add $s0,$s0,$t2
li $v0,4
la $a0,msg4
syscall
lw $a0,0($s0)
li $v0,1
syscall
EXIT:
    li $v0, 10
    syscall
gusbro
  • 22,357
  • 35
  • 46
  • 2
    Do you know how this code works?? It doesn't have any syscalls for input in the programming, so, yeah, it's not going to ask for input. – Erik Eidt Jul 09 '21 at 20:59
  • Yeah, I'm new to learning MIPS codes :( Can you help me where I can add a line for syscall to get inputs? – Marken Chris Jul 10 '21 at 07:40
  • Does this answer your question? [MIPS how to store user input and print it out](https://stackoverflow.com/questions/16205225/mips-how-to-store-user-input-and-print-it-out) – ggorlen Jul 11 '21 at 17:11
  • I recommend breaking the problem down into small steps. If all you need to do is add input, that's about 3 lines of code and is well documented. Once you have a simple program that reads and input, you can integrate that into whatever you're trying to achieve here (no specification was provided, but I assume you want to input and output a matrix). See [Reading and printing an integer in mips](https://stackoverflow.com/questions/19748054/reading-and-printing-an-integer-in-mips) – ggorlen Jul 11 '21 at 17:12

0 Answers0