c - MIPS Code Cycle Time -
i need task of determining number of cycles mips code below.
my main issue determining if condition not met, if statement still executed (thus adding number of total cycles)
assuming single cycle implementation scheme i.e., each instruction requires 1 clock cycle execute. 1. number of cycles required execute code when a. s==0? b. s==1?
this have come myself:
a. 9 cycles
b. 8 cycles (it not instruction contained in if statement, , not jump endif statement - (goes function) final endif.
this sample of mips:
main: # evaluate expression. # put final result in a0 prepare syscall. addi $sp, $sp, -4 # make space on stack. sw $ra, 0($sp) # save return address. li $t0, 1 # put 0 in register li $a1, 4 # put 4 in register li $a2, 6 # put 6 in register if: bne $t0, $zero, else # (i == 0) ? add $v0, $a1, $a2 # v0 = a1 + a2 j endif else: jal func endif: add $a0, $v0, $zero li $v0, 1
so need determine number of cycles if a. s = 1, , b. s = 0 assuming each instruction take 1 cycle.
the c code is
main() { int a; a=4; b=6; s=3; int function(a,b); if (s==0) = a+b; else = function(a,b) return; } # function multiply 2 numbers function(z,y) { int tmp; tmp = z × y; ret
apologies formatting. first post on forum , still working things out. appreciated.
depending on whether want approximate time (by instruction counting) or determine actual execution time, have count if
instruction no matter what.
in modern cpus, flavor of jump instruction includes penalties—maybe (for cpus) when conditional branch not taken!
penalties arise cache misses, pipeline perturbations, , branch prediction.
since don't understand statement means, not dissecting code path further.
tmp = z × y;
Comments
Post a Comment