简体   繁体   中英

MARS MIPS Bit Shifting using SRA

So when shifting -34 by 2 bits using SRA, I get an output of -9 using the code below. I can not figure out why it is giving me -9 and not another number

addi $t0, $zero, -34
sra $s0, $t0, 2
addi $v0, $zero, 4
la $a0, result1
syscall
addi $v0, $zero, 1
move $a0, $s0
syscall

-34 in (two's complement) binary is:

11111111 11111111 11111111 11011110
^                                 ^
bit 31                            bit 0

Shift that arithmetically 2 bits to the right and you get:

11111111 11111111 11111111 11110111

Which is -9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM