shift register

Shift register. It can do SISO and SIPO. Also, it is possible to reset to a default register
Author: Sputnki
License: BSD
Github: sptnk/logic/shift register.axo

Inlets

int32.positive default value used in reset

bool32 input

bool32.rising shift the register 1 bit left and add the input to the lsb (far right)

bool32.rising shift the register 1 bit right and add the input to the msb (far left)

bool32.rising reset the shift register to the default value

Outlets

bool32 most significant bit of the shift register

bool32 least significant bit of the shift register

int32.positive parallel output of the shift register

Declaration
bool strig;
bool rtrig;
uint32_t reg;

// these constants are used when shifting
uint32_t msb = (1 << 31);
uint32_t lsb = 1;
Init
reg = 0;
Control Rate
if (inlet_reset && !rtrig) // resetting to default value
{
  reg = inlet_default;
  rtrig = 1;
} else if (!inlet_reset) {
  rtrig = 0;
}

if (inlet_lshift && !strig) // shifting left
{
  reg = (reg << 1) | (inlet_in);
  strig = 1;
} else if (inlet_rshift && !strig) // shifting right
{
  reg = (reg >> 1) | ((inlet_in << 31));
  strig = 1;
} else if (!inlet_lshift && !inlet_rshift) {
  strig = 0;
}

outlet_out = reg;
outlet_msb = reg & msb;
outlet_lsb = reg & lsb;

Privacy

© 2024 Zrna Research