0

I'm attempting to write ASM that uses a logical right shift to shift a byte over without destroying the bytes at the end, but instead rotating them to the front. Essentially, I'm trying to emulate the ROR instruction without specifically using that instruction.

I know the right shift instruction automatically replace the leftover space with 0's, but is there a way to potentially change that value?

.data
InArr: .word 0xe0000000
OutArr: .word 0

.text
.global main

main:
    lw $s2, InArr
    lw $s3, OutArr

loop:
    #ror $s2, $s2, 4
    srl $s2, $s2, 4
    sw $s2, InArr
    bne $s2, $s3, loop

    syscall

In this case, the code runs until "e" is shifted all the way to the right.

harold
  • 61,398
  • 6
  • 86
  • 164
Connor D
  • 103
  • 1
  • 9
  • 1
    Why can't you use the `ror` instruction? Are there any other instructions you are not allowed to use? – fuz Oct 26 '18 at 16:28
  • Related: [Best practices for circular shift (rotate) operations in C++](https://stackoverflow.com/a/13732181). `(n<>(32-c)` is a rotate-left. – Peter Cordes Oct 27 '18 at 02:04

1 Answers1

3

You can put those bottom bits back in the top manually, for example

sll $t0, $s2, 28
srl $s2, $s2, 4
or $s2, $s2, $t0
harold
  • 61,398
  • 6
  • 86
  • 164