任何人都可以理解这段代码吗?不知道这个算法如何知道何时停止。
例如,当数字为144时 - 如何知道停止除以2?它为什么停在12而不是6?
.ent isqrt
isqrt:
//v0 - return / root
//t0 - bit
//t1 - num
//t2,t3 - temps
//Store parameter
sw a0, 0(fp)
//Make stack frame for output_string
addiu sp, sp, -32
sw ra, 28(sp)
sw fp, 24(sp)
move fp, sp
move v0, zero //initalize return
move t1, a0 //move a0 to t1
addi t0, zero, 1
sll t0, t0, 30
isqrt_bit:
slt t2, t1, t0 //num < bit
beq t2, zero, isqrt_loop
nop
srl t0, t0, 1 //Divide by 4
j isqrt_bit
nop
isqrt_loop:
beq t0, zero, isqrt_return
nop
add t3, v0, t0 //t3 = return + bit
slt t2, t1, t3
beq t2, zero, isqrt_else
nop
srl v0, v0, 1 //Divide by two
j isqrt_loop_end
nop
isqrt_else:
sub t1, t1, t3 //num -= return + bit
srl v0, v0, 1 //Divide by two
add v0, v0, t0 //return + bit
isqrt_loop_end:
srl t0, t0, 2 //Divide by 4
j isqrt_loop
nop
isqrt_return:
move sp, fp
lw ra, 28(fp)
lw fp, 24(fp)
addiu sp, sp, 32
jr ra
nop
.end isqrt