0

I am working on a tictactoe assembly program. The issue is for some reason the program goes through all my methods when I only need one to be read. I can't figure out for the life of me why it's doing this as I'm fairly new to this program. Any help would be great.

    la $a0, squarepick2
    li $v0, 4
    syscall

    li $v0, 12 # stores the number you pick in $s5
    syscall
    move $s5, $v0

    beq $s5, '1', box2replacep1
    beq $s5, '2', box2replacep2
    beq $s5, '3', box2replacep3
    beq $s5, '4', box2replacep4
    beq $s5, '5', box2replacep5
    beq $s5, '7', box2replacep7
    beq $s5, '8', box2replacep8
    beq $s5, '9', box2replacep9


box2replacep1:
    move $t1, $s7
box2replacep2:
    move $t2, $s7
box2replacep3:
    move $t3, $s7
box2replacep4:
    move $t4, $s7
box2replacep5:
    move $t5, $s7
box2replacep6:
    move $t6, $s7
box2replacep7:
    move $t7, $s7
box2replacep8:
    move $t8, $s7
box2replacep9:
    move $t9, $s7
Bruce
  • 1
  • FYI, these aren't methods. It goes thru all of them because unless directed otherwise, instructions execute sequentially. Look into the concept of unconditional branches. – Erik Eidt Apr 19 '20 at 00:50
  • Those aren't methods, they're just "if goto" targets in the same function. Or like `case` labels in a switch *without* a `break` between each one. Execution always goes to the next instruction unless a `j` or `b` instruction sets PC to somewhere else. In your case you probably want each jump-target block to end with a `j` to a label at the bottom. (Where you put an exit syscall) – Peter Cordes Apr 19 '20 at 00:50
  • The CPU doesn't know that your labels exist. When you type `beq $s5, '1', box2replacep1`, the assembler converts that to `beq $5,1,28` (jump ahead 28 bytes) and discards the label. The label itself doesn't exist anymore by the time your code is assembled into an executable program. – puppydrum64 Nov 23 '22 at 13:12

0 Answers0