Dealing with multiple conditionals in MIPS
I'm making a MIPS program that reads and solves kakuro puzzles. At the moment it can read and print the puzzle out, but I have been having some issues adding in error checking. There are a lot of checks I have to do, and for some reason the program both doesn't terminate as it should. If the input contains a value that is not legal (legal values would be: 0, or individual clues in the range 1-45, or an individual "block" clue of 99), then your program must print the following error message and the program must terminate. Some examples of legal input:
9999 blocking across and down clues
0799 across clue of 7, blocking down clue
9942 blocking across clue, down clue of 42
1208 across clue of 12, down clue of 8
So, this is what I came up with in C:
acrossClue = num / 100;
downClue = num % 100;
if(num != 0 && (1 > acrossClue || 45 < acrossClue || acrossClue != 99)
|| (1 > downClue || 45 < downClue || downClue != 99)) {
printf("Illegal input value, Cross sums terminatingn");
return 1;
}
Below is the code for main and the read function I made. Any suggestions for transferring the conditionals and logic to MIPS? It doesn't work currently, because even if it gets incorrect input it still runs (readPuzzle returns 1 despite terminating early) and it messes up the puzzle even if the input is correct. My thoughts were if the input isn't any of the values checked it can't be valid, but I'm guessing somewhere along the line I'm not checking properly and it's messing everything up. Does anyone notice anything off with any of the checking I do in readPuzzle?
#
# Name: MAIN PROGRAM
# Description: Main logic for the program.
#
# The program reads these values from standard input:
# 1) an integer representing the size of the puzzle
# 2) integers representing values for each cell for the puzzle
#
# If the dimensions of the board and values of the cells are
# valid, the program then displays the initial puzzle, attempts
# to solve it, and displays the solution if there is one.
.text # this is program code
.align 2 # instructions must be on word boundaries
.globl main # main is a global label
main:
# Allocate stack frame
addi $sp, $sp,-FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
la $t0, size
li $v0, READ_INT
syscall
move $s0, $v0 # save size n
blt $s0, MIN_SIZE, size_error
bgt $s0, MAX_SIZE, size_error
sw $v0, 0($t0)
move $a0, $s0
jal readPuzzle
move $t7, $v0
li $v0, PRINT_INT
move $a0, $t7
syscall
beq $v0, $zero, main_done
la $s1, puzzle
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, banner_mid
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, initial
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
li $v0, PRINT_STRING
la $a0, final
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
j main_done
size_error:
li $v0, PRINT_STRING
la $a0, invalid_size
syscall
j main_done
main_done:
# Restore stack frame
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
# Name: readPuzzle
#
# Description: Reads in the puzzle from a file or stdin.
#
# Arguments: a0 The size n
#
# Returns: 1 if the read was successful, otherwise 0
#
readPuzzle:
addi $sp, $sp, -FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
move $s0, $a0
mul $s1, $s0, $s0 # get n * n
li $s2, 0
la $s3, puzzle
li $s4, 4
li $s5, 0 # row = 0
li $s6, 0 # col = 0
mul $s1, $s1, $s4 # get (n * n) * 4 bytes
li $t1, 100
j read_loop
read_loop:
beq $s2, $s1, read_done
beq $s5, $s1, reset
li $v0, READ_INT
syscall
move $s7, $v0
beq $s7, $zero, continue
div $s7, $t1
mflo $t2 # acrossClue = num / 100
mfhi $t3 # downClue = num % 100
seq $t4, $t2, Block_Value
seq $t5, $t3, Block_Value
seq $t6, $t4, $t5
bne $t6, $zero, continue
li $t6, MIN_CLUE # minimum value = 2
li $t7, MAX_CLUE # maximum value = 45
slt $t4, $t2, $t6 # 1 if acrossClue < 2, otherwise 0
slt $t5, $t7, $t2 # 1 if acrossClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
slt $t4, $t3, $t6 # 1 if downClue < 2, otherwise 0
slt $t5, $t7, $t3 # 1 if downClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
j continue
continue:
move $a0, $s5
move $a1, $s6
move $a2, $s7
jal setElement
addi $s6, $s6, 1
addi $s2, $s2, 4
j read_loop
reset:
addi $s5, $s5, 1
li $s6, 0
illegal_input:
li $v0, PRINT_STRING
la $a0, invalid_input
syscall
li $v0, 0
j read_done
read_done:
li $v0, 1
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
Edit: I got it so that it correctly knows when the input is valid or invalid, but it still doesn't terminate when there's an invalid input value.
assembly mips
|
show 3 more comments
I'm making a MIPS program that reads and solves kakuro puzzles. At the moment it can read and print the puzzle out, but I have been having some issues adding in error checking. There are a lot of checks I have to do, and for some reason the program both doesn't terminate as it should. If the input contains a value that is not legal (legal values would be: 0, or individual clues in the range 1-45, or an individual "block" clue of 99), then your program must print the following error message and the program must terminate. Some examples of legal input:
9999 blocking across and down clues
0799 across clue of 7, blocking down clue
9942 blocking across clue, down clue of 42
1208 across clue of 12, down clue of 8
So, this is what I came up with in C:
acrossClue = num / 100;
downClue = num % 100;
if(num != 0 && (1 > acrossClue || 45 < acrossClue || acrossClue != 99)
|| (1 > downClue || 45 < downClue || downClue != 99)) {
printf("Illegal input value, Cross sums terminatingn");
return 1;
}
Below is the code for main and the read function I made. Any suggestions for transferring the conditionals and logic to MIPS? It doesn't work currently, because even if it gets incorrect input it still runs (readPuzzle returns 1 despite terminating early) and it messes up the puzzle even if the input is correct. My thoughts were if the input isn't any of the values checked it can't be valid, but I'm guessing somewhere along the line I'm not checking properly and it's messing everything up. Does anyone notice anything off with any of the checking I do in readPuzzle?
#
# Name: MAIN PROGRAM
# Description: Main logic for the program.
#
# The program reads these values from standard input:
# 1) an integer representing the size of the puzzle
# 2) integers representing values for each cell for the puzzle
#
# If the dimensions of the board and values of the cells are
# valid, the program then displays the initial puzzle, attempts
# to solve it, and displays the solution if there is one.
.text # this is program code
.align 2 # instructions must be on word boundaries
.globl main # main is a global label
main:
# Allocate stack frame
addi $sp, $sp,-FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
la $t0, size
li $v0, READ_INT
syscall
move $s0, $v0 # save size n
blt $s0, MIN_SIZE, size_error
bgt $s0, MAX_SIZE, size_error
sw $v0, 0($t0)
move $a0, $s0
jal readPuzzle
move $t7, $v0
li $v0, PRINT_INT
move $a0, $t7
syscall
beq $v0, $zero, main_done
la $s1, puzzle
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, banner_mid
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, initial
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
li $v0, PRINT_STRING
la $a0, final
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
j main_done
size_error:
li $v0, PRINT_STRING
la $a0, invalid_size
syscall
j main_done
main_done:
# Restore stack frame
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
# Name: readPuzzle
#
# Description: Reads in the puzzle from a file or stdin.
#
# Arguments: a0 The size n
#
# Returns: 1 if the read was successful, otherwise 0
#
readPuzzle:
addi $sp, $sp, -FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
move $s0, $a0
mul $s1, $s0, $s0 # get n * n
li $s2, 0
la $s3, puzzle
li $s4, 4
li $s5, 0 # row = 0
li $s6, 0 # col = 0
mul $s1, $s1, $s4 # get (n * n) * 4 bytes
li $t1, 100
j read_loop
read_loop:
beq $s2, $s1, read_done
beq $s5, $s1, reset
li $v0, READ_INT
syscall
move $s7, $v0
beq $s7, $zero, continue
div $s7, $t1
mflo $t2 # acrossClue = num / 100
mfhi $t3 # downClue = num % 100
seq $t4, $t2, Block_Value
seq $t5, $t3, Block_Value
seq $t6, $t4, $t5
bne $t6, $zero, continue
li $t6, MIN_CLUE # minimum value = 2
li $t7, MAX_CLUE # maximum value = 45
slt $t4, $t2, $t6 # 1 if acrossClue < 2, otherwise 0
slt $t5, $t7, $t2 # 1 if acrossClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
slt $t4, $t3, $t6 # 1 if downClue < 2, otherwise 0
slt $t5, $t7, $t3 # 1 if downClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
j continue
continue:
move $a0, $s5
move $a1, $s6
move $a2, $s7
jal setElement
addi $s6, $s6, 1
addi $s2, $s2, 4
j read_loop
reset:
addi $s5, $s5, 1
li $s6, 0
illegal_input:
li $v0, PRINT_STRING
la $a0, invalid_input
syscall
li $v0, 0
j read_done
read_done:
li $v0, 1
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
Edit: I got it so that it correctly knows when the input is valid or invalid, but it still doesn't terminate when there's an invalid input value.
assembly mips
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
1
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40
|
show 3 more comments
I'm making a MIPS program that reads and solves kakuro puzzles. At the moment it can read and print the puzzle out, but I have been having some issues adding in error checking. There are a lot of checks I have to do, and for some reason the program both doesn't terminate as it should. If the input contains a value that is not legal (legal values would be: 0, or individual clues in the range 1-45, or an individual "block" clue of 99), then your program must print the following error message and the program must terminate. Some examples of legal input:
9999 blocking across and down clues
0799 across clue of 7, blocking down clue
9942 blocking across clue, down clue of 42
1208 across clue of 12, down clue of 8
So, this is what I came up with in C:
acrossClue = num / 100;
downClue = num % 100;
if(num != 0 && (1 > acrossClue || 45 < acrossClue || acrossClue != 99)
|| (1 > downClue || 45 < downClue || downClue != 99)) {
printf("Illegal input value, Cross sums terminatingn");
return 1;
}
Below is the code for main and the read function I made. Any suggestions for transferring the conditionals and logic to MIPS? It doesn't work currently, because even if it gets incorrect input it still runs (readPuzzle returns 1 despite terminating early) and it messes up the puzzle even if the input is correct. My thoughts were if the input isn't any of the values checked it can't be valid, but I'm guessing somewhere along the line I'm not checking properly and it's messing everything up. Does anyone notice anything off with any of the checking I do in readPuzzle?
#
# Name: MAIN PROGRAM
# Description: Main logic for the program.
#
# The program reads these values from standard input:
# 1) an integer representing the size of the puzzle
# 2) integers representing values for each cell for the puzzle
#
# If the dimensions of the board and values of the cells are
# valid, the program then displays the initial puzzle, attempts
# to solve it, and displays the solution if there is one.
.text # this is program code
.align 2 # instructions must be on word boundaries
.globl main # main is a global label
main:
# Allocate stack frame
addi $sp, $sp,-FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
la $t0, size
li $v0, READ_INT
syscall
move $s0, $v0 # save size n
blt $s0, MIN_SIZE, size_error
bgt $s0, MAX_SIZE, size_error
sw $v0, 0($t0)
move $a0, $s0
jal readPuzzle
move $t7, $v0
li $v0, PRINT_INT
move $a0, $t7
syscall
beq $v0, $zero, main_done
la $s1, puzzle
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, banner_mid
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, initial
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
li $v0, PRINT_STRING
la $a0, final
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
j main_done
size_error:
li $v0, PRINT_STRING
la $a0, invalid_size
syscall
j main_done
main_done:
# Restore stack frame
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
# Name: readPuzzle
#
# Description: Reads in the puzzle from a file or stdin.
#
# Arguments: a0 The size n
#
# Returns: 1 if the read was successful, otherwise 0
#
readPuzzle:
addi $sp, $sp, -FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
move $s0, $a0
mul $s1, $s0, $s0 # get n * n
li $s2, 0
la $s3, puzzle
li $s4, 4
li $s5, 0 # row = 0
li $s6, 0 # col = 0
mul $s1, $s1, $s4 # get (n * n) * 4 bytes
li $t1, 100
j read_loop
read_loop:
beq $s2, $s1, read_done
beq $s5, $s1, reset
li $v0, READ_INT
syscall
move $s7, $v0
beq $s7, $zero, continue
div $s7, $t1
mflo $t2 # acrossClue = num / 100
mfhi $t3 # downClue = num % 100
seq $t4, $t2, Block_Value
seq $t5, $t3, Block_Value
seq $t6, $t4, $t5
bne $t6, $zero, continue
li $t6, MIN_CLUE # minimum value = 2
li $t7, MAX_CLUE # maximum value = 45
slt $t4, $t2, $t6 # 1 if acrossClue < 2, otherwise 0
slt $t5, $t7, $t2 # 1 if acrossClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
slt $t4, $t3, $t6 # 1 if downClue < 2, otherwise 0
slt $t5, $t7, $t3 # 1 if downClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
j continue
continue:
move $a0, $s5
move $a1, $s6
move $a2, $s7
jal setElement
addi $s6, $s6, 1
addi $s2, $s2, 4
j read_loop
reset:
addi $s5, $s5, 1
li $s6, 0
illegal_input:
li $v0, PRINT_STRING
la $a0, invalid_input
syscall
li $v0, 0
j read_done
read_done:
li $v0, 1
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
Edit: I got it so that it correctly knows when the input is valid or invalid, but it still doesn't terminate when there's an invalid input value.
assembly mips
I'm making a MIPS program that reads and solves kakuro puzzles. At the moment it can read and print the puzzle out, but I have been having some issues adding in error checking. There are a lot of checks I have to do, and for some reason the program both doesn't terminate as it should. If the input contains a value that is not legal (legal values would be: 0, or individual clues in the range 1-45, or an individual "block" clue of 99), then your program must print the following error message and the program must terminate. Some examples of legal input:
9999 blocking across and down clues
0799 across clue of 7, blocking down clue
9942 blocking across clue, down clue of 42
1208 across clue of 12, down clue of 8
So, this is what I came up with in C:
acrossClue = num / 100;
downClue = num % 100;
if(num != 0 && (1 > acrossClue || 45 < acrossClue || acrossClue != 99)
|| (1 > downClue || 45 < downClue || downClue != 99)) {
printf("Illegal input value, Cross sums terminatingn");
return 1;
}
Below is the code for main and the read function I made. Any suggestions for transferring the conditionals and logic to MIPS? It doesn't work currently, because even if it gets incorrect input it still runs (readPuzzle returns 1 despite terminating early) and it messes up the puzzle even if the input is correct. My thoughts were if the input isn't any of the values checked it can't be valid, but I'm guessing somewhere along the line I'm not checking properly and it's messing everything up. Does anyone notice anything off with any of the checking I do in readPuzzle?
#
# Name: MAIN PROGRAM
# Description: Main logic for the program.
#
# The program reads these values from standard input:
# 1) an integer representing the size of the puzzle
# 2) integers representing values for each cell for the puzzle
#
# If the dimensions of the board and values of the cells are
# valid, the program then displays the initial puzzle, attempts
# to solve it, and displays the solution if there is one.
.text # this is program code
.align 2 # instructions must be on word boundaries
.globl main # main is a global label
main:
# Allocate stack frame
addi $sp, $sp,-FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
la $t0, size
li $v0, READ_INT
syscall
move $s0, $v0 # save size n
blt $s0, MIN_SIZE, size_error
bgt $s0, MAX_SIZE, size_error
sw $v0, 0($t0)
move $a0, $s0
jal readPuzzle
move $t7, $v0
li $v0, PRINT_INT
move $a0, $t7
syscall
beq $v0, $zero, main_done
la $s1, puzzle
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, banner_mid
syscall
li $v0, PRINT_STRING
la $a0, banner_border
syscall
li $v0, PRINT_STRING
la $a0, newline
syscall
li $v0, PRINT_STRING
la $a0, initial
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
li $v0, PRINT_STRING
la $a0, final
syscall
move $a0, $s0
move $a1, $s1
jal printPuzzle
j main_done
size_error:
li $v0, PRINT_STRING
la $a0, invalid_size
syscall
j main_done
main_done:
# Restore stack frame
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
# Name: readPuzzle
#
# Description: Reads in the puzzle from a file or stdin.
#
# Arguments: a0 The size n
#
# Returns: 1 if the read was successful, otherwise 0
#
readPuzzle:
addi $sp, $sp, -FRAMESIZE_40
sw $ra, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
move $s0, $a0
mul $s1, $s0, $s0 # get n * n
li $s2, 0
la $s3, puzzle
li $s4, 4
li $s5, 0 # row = 0
li $s6, 0 # col = 0
mul $s1, $s1, $s4 # get (n * n) * 4 bytes
li $t1, 100
j read_loop
read_loop:
beq $s2, $s1, read_done
beq $s5, $s1, reset
li $v0, READ_INT
syscall
move $s7, $v0
beq $s7, $zero, continue
div $s7, $t1
mflo $t2 # acrossClue = num / 100
mfhi $t3 # downClue = num % 100
seq $t4, $t2, Block_Value
seq $t5, $t3, Block_Value
seq $t6, $t4, $t5
bne $t6, $zero, continue
li $t6, MIN_CLUE # minimum value = 2
li $t7, MAX_CLUE # maximum value = 45
slt $t4, $t2, $t6 # 1 if acrossClue < 2, otherwise 0
slt $t5, $t7, $t2 # 1 if acrossClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
slt $t4, $t3, $t6 # 1 if downClue < 2, otherwise 0
slt $t5, $t7, $t3 # 1 if downClue > 45, otherwise 0
bne $t4, $zero, illegal_input
bne $t5, $zero, illegal_input
j continue
continue:
move $a0, $s5
move $a1, $s6
move $a2, $s7
jal setElement
addi $s6, $s6, 1
addi $s2, $s2, 4
j read_loop
reset:
addi $s5, $s5, 1
li $s6, 0
illegal_input:
li $v0, PRINT_STRING
la $a0, invalid_input
syscall
li $v0, 0
j read_done
read_done:
li $v0, 1
lw $ra, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, FRAMESIZE_40
jr $ra
Edit: I got it so that it correctly knows when the input is valid or invalid, but it still doesn't terminate when there's an invalid input value.
assembly mips
assembly mips
edited Nov 22 '18 at 2:00
70ny
asked Nov 21 '18 at 23:54
70ny70ny
134
134
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
1
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40
|
show 3 more comments
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
1
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
1
1
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422078%2fdealing-with-multiple-conditionals-in-mips%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422078%2fdealing-with-multiple-conditionals-in-mips%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I haven't done MIPS assembler in years, but should not you insert some delay slots after each branch instruction? Suppose, this depends on the exact version of the MIPS core you're targeting, but you haven't specified this in the question.
– oakad
Nov 22 '18 at 0:22
@oakad I have never heard of that before. I looked it up though and I am confused as to how I got this far without using them. Do you have any idea what they look like in MIPS? I'll try to find an example online in the meantime.
– 70ny
Nov 22 '18 at 0:27
An instruction immediately following the branch must not be a branch. That's it. Start with putting a NOP after each branch - if it works, try to optimize further.
– oakad
Nov 22 '18 at 0:29
blogs.msdn.microsoft.com/oldnewthing/20180412-00/?p=98495
– oakad
Nov 22 '18 at 0:31
1
@oakad: The SPIM and MARS simulators for MIPS by default simulate a MIPS without branch delay slots. There's an option you can uncheck that will make them emulate a normal MIPS with branch delay slots (which yes it does have: en.wikipedia.org/wiki/Delay_slot#Branch_delay_slots). Most MIPS questions on Stack Overflow are from students using MARS/SPIM, with the simplified architecture (and "system calls" that read or print integers), not from people learning or programming Linux or IRIX or whatever embedded OS on real MIPS.
– Peter Cordes
Nov 22 '18 at 2:40