I'm really new in MIPS and I have these questions which I found so many dissimil answers for them ... if someone can help, it would be great. Thanks
How many clock cycles does this code take?
#Macro Instructions
li $t0, 32 # 1 or 2 cycles ?
# lui $at, Upper 16-bits of value
# ori Rd, $at, Lower 16-bits of value
# -----------------------------------
# ori Rt, $0, value
#
# Which set of instructions will be executed?
div $t2, $t2, $t0 # 41 cycles?
# bne Rt, $0,
# break $0
# ok: div Rs, Rt
# mflo Rd
#Integer Instruction
lw $t2, 0($t13) # 1 cycles?
sw $t2, 0($t3) # 1 cycles?
How those 4 lines of codes can be significantly improved? by avoiding to use Macros or ... ?
li $t0, 32
This one you can easily check by disassembling your executable or object file. Use objdump
from your MIPS toolchain with the -d
or -D
option. I would guess that the assembler is smart enough not to generate a lui
for such a small value.
div $t2, $t2, $t0
Since you're you're dividing by a power of two (32), there's a much faster way of doing this: shift right by log2(divisor)
bits (i.e. 5 bits):
srl $t2, $t2, 5 # if $t2 is unsigned
or
sra $t2, $t2, 5 # if $t2 is signed