1

What changes when using the instruction sra and the srl one? I can't understand the difference between the two. The language in use is MIPS assembly.

sll $t1,$t0,2
sra $t2,$t0,2

sll $t1,$t0,2
srl $t2,$t0,2
NyW
  • 107
  • 8
Corot
  • 33
  • 1
  • 1
  • 8
  • You might want to specify *which* assembly language you're interested in (probably ARM). There *are* quite a few different CPUs in the world :-) – paxdiablo Jul 04 '19 at 02:11
  • Sorry about that haha, the language is actually MIPS. – Corot Jul 04 '19 at 02:14
  • If the right shifts took their input from the result of the left shift, these snippets would be zero- or sign-extending from 30 bits to 32 bits, respectively. But they're not, the left shift is independent in both cases so IDK why it's repeated. – Peter Cordes Jul 04 '19 at 02:42

1 Answers1

5

SLR is a typo and should be SRL instead. SRA does an arithmetic shift and SRL does a logical one. So SRL will shift zeros in whereas SRA shifts the sign bit in. For example shifting 0xFFFF1234 right logically gives 0x3FFFC48D and arithmetically gives 0xFFFFC48D because the sign bit is 1 (assuming this is MIPS32). For more information read

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • The typo in the question is only in the title. Probably we should just fix that. `slr` isn't a valid mnemonic at all, according to the assembler in MARS. IDK why you're saying it's a left shift; MIPS's left shift is `sll`. – Peter Cordes Jul 05 '19 at 00:35