[Oberon] Implementing unsigned right shift for Oberon RISC5 machine
Peter Matthias
PeterMatthias at web.de
Tue Apr 11 23:03:31 CEST 2023
Not necessarily RISC5 assembler, but I think you get what I mean:
MOV R1, -1
LSL R1, R1, Rc
AND Rs, Rs, R1
ROR Rd, Rs, Rc
Peter
Am 11.04.23 um 21:27 schrieb Michael Schierl:
> Hello,
>
>
> as you may know, Oberon RISC5 machine only has an arithmetic right shift
> (extending the sign) and no unsigned right shift (fillingwith zeroes).
> For Oberon, that instruction is not needed, but what if you want other
> languages to target the architecture?
>
>
> I was thinking of how to implement it in a concise way
>
> - No loops, as little branching as possible
> - Having the count in a register (for a constant it is trivial to emit
> an additional AND to mask the bits), should work for all values from 0
> to 31
> - Should work even if the destination is one of the source registers
> - As few scratch registers as possible
>
>
> I came up with this (using two scratch registers R1, R2):
>
> USR Rd, Rs, Rc (destination, source, count) translates to
>
> SUB R1, Rc, 1
> B CS move # Rc was zero
> ASR Rd, Rs, 1
> MOV+U R2, 80000000H
> ANN Rd, Rd, R2
> ASR Rd, Rs, R1
> B done
> move: MOV Rd, Rs
> done:
>
>
> Or in case Rd is neither Rs nor Rc, you can get away with only one
> scratch register, and the same number of instructions/branches on each
> path:
>
> ASR Rd, Rs, 1
> MOV+U R1, 80000000H
> ANN Rd, Rd, R1
> SUB R1, Rc, 1
> B CS move
> ASR Rd, Rs, R1
> B done
> move: MOV Rd, Rs
> done:
>
> Any easier solution I missed?
>
>
> Regards,
>
>
> Michael
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list