CC2032 COAL Lab # 08
CC2032 COAL Lab # 08
bne rs, rt, label: Branch to label if the contents of registers rs and rt are not equal.
bgez rs, label: Branch to label if the contents of register rs are greater than or equal to zero.
bgtz rs, label: Branch to label if the contents of register rs are greater than zero.
blez rs, label: Branch to label if the contents of register rs are less than or equal to zero.
bltz rs, label: Branch to label if the contents of register rs are less than zero.
addi $t0, $s1, 1 # Add 1 to $s1 and store the result in $t0
beq $t0, $s2, equal_block # Branch if $t0 equals $s2
# Code executed if $t0 is not equal to $s2
j end
addi $t0, $s1, 1 # Add 1 to $s1 and store the result in $t0
bne $t0, $s2, not_equal_block # Branch if $t0 is not equal to $s2
# Code executed if $t0 is equal to $s2
j end
addi $t0, $s1, 3 # Add 3 to $s1 and store the result in $t0
bgtz $t0, positive # Branch if $t0 is greater than zero
# Code executed if $t0 is zero or negative
addi $t0, $s1, 0 # Add 0 to $s1 and store the result in $t0
(essentially copying $s1)
blez $t0, non_positive # Branch if $t0 is less than or equal to zero
# Code executed if $t0 is positive
addi $t0, $s1, -8 # Add -8 to $s1 and store the result in $t0
bltz $t0, negative # Branch if $t0 is less than zero
# Code executed if $t0 is zero or positive
.text
main:
lw $t0, value1 # Load value1 into register $t0
lw $t1, value2 # Load value2 into register $t1
beq $t0, $t1, equal # Branch to 'equal' if $t0 == $t1
equal:
# Code if equal
li $v0, 4 # Load 4 into $v0 (print string syscall)
la $a0, msg # Load address of msg into $a0
syscall # Print the string
li $v0, 10 # Load 10 into $v0 (exit syscall)
syscall # Exit
.data
msg: .asciiz "Values are equal\n"
Q1. Have you received any output message in the I/O console. If not, why have you not received
any output message?
5. Task # 2: Add a message in the above program to show if the value are
not equal. For example, “The given values are not equal”. Write the
piece of code below.
6. Task # 3: Write a MIPS32 assembly program that loads a value and
checks if the value is greater than or equal to zero. If the value is non-
negative, the program should branch to a label where it prints the
message "Register is non-negative". If the value is negative, the
program should terminate without printing the message.