mips

In MIPS, how do I divide register contents by two?

Deadly 提交于 2020-12-13 10:34:42
问题 Let's say I have $t0 , and I'd like to divide its integer contents by two, and store it in $t1 . My gut says: srl $t1, $t0, 2 ... but wouldn't that be a problem if... say... the right-most bit was 1? Or does it all come out in the wash because the right-most bit (if positive) makes $t0 an odd number, which becomes even when divided? Teach me, O wise ones... 回答1: Use instruction sra: Shift right arithmetic !! sra $t1, $t0, 1 Divides the content of $t0 by the first power of 2. Description: