Search Results for

    Show / Hide Table of Contents

    Class SubAddition

    Implements binary addition for two numbers a, b stored in the same chain.

    Computes a new binary number c := a + b and optionally determines whether the chain length was insufficient to compute all bits of c.

    This procedure requires at least 1 pin and it always uses the "outermost / leftmost" pin when traversing the chain. If an amoebot occurs on the chain multiple times, its predecessor and successor directions must be different for all occurrences.

    Usage:

    • Establish a chain of amoebots such that each amoebot knows its predecessor and successor (except the start and end amoebots). Each amoebot should store a bit a and a bit b.
    • Initialize using the Init(bool, bool, Direction, Direction) method. You must pass the bits a and b and the two chain directions. The chain start should have no predecessor and the end should have no successor.
    • Call SetupPinConfig(PinConfiguration) to modify the next pin configuration.
    • Call ActivateSend() in the same round to start the procedure.
    • After this, call ActivateReceive(), SetupPinConfig(PinConfiguration) and ActivateSend() in this order in every round.
    • The procedure can be paused after each ActivateReceive() call and resumed by continuing with SetupPinConfig(PinConfiguration) in some future round.
    • Call IsFinishedAdd() after ActivateReceive() to check whether the addition is finished. Running another iteration after this, until IsFinishedOverflow() returns true, will make the overflow result available.
    • The addition result c is thereafter available through Bit_C() for each amoebot on the chain.
    Inheritance
    object
    Subroutine
    SubAddition
    Namespace: AS2.Subroutines.BinaryOps
    Assembly: .dll
    Syntax
    public class SubAddition : Subroutine

    Constructors

    | Edit this page View Source

    SubAddition(Particle, ParticleAttribute<int>)

    Declaration
    public SubAddition(Particle p, ParticleAttribute<int> stateAttr = null)
    Parameters
    Type Name Description
    Particle p
    ParticleAttribute<int> stateAttr

    Fields

    | Edit this page View Source

    bit_A

    Declaration
    private const int bit_A = 2
    Field Value
    Type Description
    int
    | Edit this page View Source

    bit_B

    Declaration
    private const int bit_B = 3
    Field Value
    Type Description
    int
    | Edit this page View Source

    bit_C

    Declaration
    private const int bit_C = 4
    Field Value
    Type Description
    int
    | Edit this page View Source

    bit_FinishedAdd

    Declaration
    private const int bit_FinishedAdd = 11
    Field Value
    Type Description
    int
    | Edit this page View Source

    bit_FinishedOverflow

    Declaration
    private const int bit_FinishedOverflow = 12
    Field Value
    Type Description
    int
    | Edit this page View Source

    bit_Overflow

    Declaration
    private const int bit_Overflow = 13
    Field Value
    Type Description
    int
    | Edit this page View Source

    state

    Declaration
    private ParticleAttribute<int> state
    Field Value
    Type Description
    ParticleAttribute<int>

    Methods

    | Edit this page View Source

    ActivateReceive()

    Activation during ActivateBeep() to receive the beeps sent in the last round. Should always be called before SetupPinConfig(PinConfiguration) and ActivateSend(), except in the very first activation, where it should not be called.

    Declaration
    public void ActivateReceive()
    | Edit this page View Source

    ActivateSend()

    Activation during ActivateBeep() to send the beeps required for this step. Must be called after ActivateReceive() and SetupPinConfig(PinConfiguration).

    Declaration
    public void ActivateSend()
    | Edit this page View Source

    Bit_A()

    This amoebot's bit of a.

    Declaration
    public bool Bit_A()
    Returns
    Type Description
    bool

    Whether this amoebot's bit of a is equal to 1.

    | Edit this page View Source

    Bit_B()

    This amoebot's bit of b.

    Declaration
    public bool Bit_B()
    Returns
    Type Description
    bool

    Whether this amoebot's bit of b is equal to 1.

    | Edit this page View Source

    Bit_C()

    This amoebot's bit of c.

    Declaration
    public bool Bit_C()
    Returns
    Type Description
    bool

    Whether this amoebot's bit of c is equal to 1.

    | Edit this page View Source

    GetStateBit(int)

    Helper for reading a single bit from the state integer.

    Declaration
    private bool GetStateBit(int bit)
    Parameters
    Type Name Description
    int bit

    The position of the bit.

    Returns
    Type Description
    bool

    The value of the state bit at position bit.

    | Edit this page View Source

    HaveOverflow()

    Checks whether an overflow occurred during the addition. Should only be called once the procedure has finished completely.

    Declaration
    public bool HaveOverflow()
    Returns
    Type Description
    bool

    true if and only if a carry bit was sent beyond the end of the chain.

    | Edit this page View Source

    Init(bool, bool, Direction, Direction)

    Initializes the subroutine. Must be called by each amoebot on the chain that stores a and b.

    Declaration
    public void Init(bool a, bool b, Direction predDir, Direction succDir)
    Parameters
    Type Name Description
    bool a

    This amoebot's bit of a.

    bool b

    This amoebot's bit of b.

    Direction predDir

    The direction of the predecessor. Should be NONE only at the start of the chain.

    Direction succDir

    The direction of the successor. Should be NONE only at the end of the chain.

    | Edit this page View Source

    IsFinishedAdd()

    Checks whether the addition procedure is finished. Should be called after ActivateReceive(). If an overflow should be detected, another iteration has to be run.

    Declaration
    public bool IsFinishedAdd()
    Returns
    Type Description
    bool

    true if and only if the addition procedure has finished.

    | Edit this page View Source

    IsFinishedOverflow()

    Checks whether the procedure including overflow detection is finished. Should be called after ActivateReceive().

    Declaration
    public bool IsFinishedOverflow()
    Returns
    Type Description
    bool

    true if and only if the overflow detection procedure has finished.

    | Edit this page View Source

    PredDir()

    Helper for reading the predecessor direction from the state integer.

    Declaration
    private Direction PredDir()
    Returns
    Type Description
    Direction

    The direction of the chain predecessor.

    | Edit this page View Source

    Round()

    Helper for reading the round number from the state integer.

    Declaration
    private int Round()
    Returns
    Type Description
    int

    The current round number.

    | Edit this page View Source

    SetRound(int)

    Helper for setting the round counter.

    Declaration
    private void SetRound(int round)
    Parameters
    Type Name Description
    int round

    The new value of the round counter.

    | Edit this page View Source

    SetStateBit(int, bool)

    Helper for setting a single bit from the state integer.

    Declaration
    private void SetStateBit(int bit, bool value)
    Parameters
    Type Name Description
    int bit

    The position of the bit.

    bool value

    The new value of the bit.

    | Edit this page View Source

    SetupPinConfig(PinConfiguration)

    Sets up the required circuits for the next step in the given pin configuration. This must be called after ActivateReceive() and before ActivateSend().

    Declaration
    public void SetupPinConfig(PinConfiguration pc)
    Parameters
    Type Name Description
    PinConfiguration pc

    The pin configuration to set up. Partition set IDs will always equal one of the IDs of the contained pins.

    | Edit this page View Source

    SuccDir()

    Helper for reading the successor direction from the state integer.

    Declaration
    private Direction SuccDir()
    Returns
    Type Description
    Direction

    The direction of the chain successor.

    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX