Search Results for

    Show / Hide Table of Contents

    Class SubBinOps

    Wrapper for several operations on a chain storing one or two binary counters.

    Implements MSB detection, comparison, addition, subtraction, multiplication and division with remainder. Only one of these operations can be performed at a time. This wrapper is implemented such that all subroutines share their state attribute, making it very memory efficient.

    This procedure requires at least 2 pins and it always uses the "outermost / leftmost" pins 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 (if an operation for two counters is required).
    • Initialize using the Init(Mode, bool, Direction, Direction, bool, bool) method. You must pass the mode of operation, the bit a and the two chain directions, plus the bit b and the marked MSB of a for some operations. The chain start should have no predecessor and the end should have no successor.
    • Call SetupPinConfig(PinConfiguration) to modify the 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 IsFinished() after ActivateReceive() to check whether the procedure is finished. The result is thereafter available through one of the interface methods, such as ResultBit(). If the operation has an optional overflow check (addition/subtraction) that you want to use, call IsFinishedOverflow() instead.
    Inheritance
    object
    Subroutine
    SubBinOps
    Namespace: AS2.Subroutines.BinaryOps
    Assembly: .dll
    Syntax
    public class SubBinOps : Subroutine

    Constructors

    | Edit this page View Source

    SubBinOps(Particle)

    Declaration
    public SubBinOps(Particle p)
    Parameters
    Type Name Description
    Particle p

    Fields

    | Edit this page View Source

    add

    Declaration
    private SubAddition add
    Field Value
    Type Description
    SubAddition
    | Edit this page View Source

    comp

    Declaration
    private SubComparison comp
    Field Value
    Type Description
    SubComparison
    | Edit this page View Source

    div

    Declaration
    private SubDivision div
    Field Value
    Type Description
    SubDivision
    | Edit this page View Source

    mode

    Declaration
    private ParticleAttribute<SubBinOps.Mode> mode
    Field Value
    Type Description
    ParticleAttribute<SubBinOps.Mode>
    | Edit this page View Source

    msb

    Declaration
    private SubMSBDetection msb
    Field Value
    Type Description
    SubMSBDetection
    | Edit this page View Source

    mult

    Declaration
    private SubMultiplication mult
    Field Value
    Type Description
    SubMultiplication
    | Edit this page View Source

    state

    Declaration
    private ParticleAttribute<int> state
    Field Value
    Type Description
    ParticleAttribute<int>
    | Edit this page View Source

    sub

    Declaration
    private SubSubtraction sub
    Field Value
    Type Description
    SubSubtraction

    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

    CompResult()

    Returns the result of the comparison procedure. Should only be called after IsFinished() returns true.

    Declaration
    public SubComparison.ComparisonResult CompResult()
    Returns
    Type Description
    SubComparison.ComparisonResult

    The result of comparing a to b.

    | Edit this page View Source

    HaveOverflow()

    Checks whether the operation created an overflow (only works for addition, subtraction and multiplication). Should only be called after IsFinished() returns true.

    Declaration
    public bool HaveOverflow()
    Returns
    Type Description
    bool
    | Edit this page View Source

    Init(Mode, bool, Direction, Direction, bool, bool)

    Initializes the subroutine. Must be called by each amoebot on the chain.

    Declaration
    public void Init(SubBinOps.Mode mode, bool a, Direction predDir, Direction succDir, bool b = false, bool msbA = false)
    Parameters
    Type Name Description
    SubBinOps.Mode mode

    The operation to be initialized.

    bool a

    This amoebot's bit of a.

    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.

    bool b

    The amoebot's bit of b if a second binary number is involved.

    bool msbA

    Whether this amoebot stores the MSB of a (required for multiplication and division).

    | Edit this page View Source

    IsFinished()

    Checks whether the current procedure is finished. Should be called after ActivateReceive(). Note that for addition and subtraction, this becomes true before the overflow has been determined. Call IsFinishedOverflow() to check whether the procedure has finished completely.

    Declaration
    public bool IsFinished()
    Returns
    Type Description
    bool

    true if and only if the computation procedure has finished.

    | Edit this page View Source

    IsFinishedOverflow()

    Checks whether the current addition or subtraction procedure has determined its overflow flag. This is similar to IsFinished() but it will become true later.

    Declaration
    public bool IsFinishedOverflow()
    Returns
    Type Description
    bool

    true if and only if the current procedure is addition or subtraction and it has already computed its overflow result.

    | Edit this page View Source

    IsMSB()

    Checks whether this amoebot is the MSB. Should only be called after IsFinished() returns true.

    Declaration
    public bool IsMSB()
    Returns
    Type Description
    bool

    true if and only if this amoebot stores the highest-value 1-bit of a or it is the start and the stored number is 0.

    | Edit this page View Source

    RemainderBit()

    Returns the remainder bit resulting from division. Should only be called after IsFinished() returns true.

    Declaration
    public bool RemainderBit()
    Returns
    Type Description
    bool

    true if and only if this amoebot's bit of the remainder is 1.

    | Edit this page View Source

    ResultBit()

    Returns the resulting bit for mathematical operations. For division, this returns the bit of the quotient. Should only be called after IsFinished() returns true.

    Declaration
    public bool ResultBit()
    Returns
    Type Description
    bool

    This amoebot's bit of the resulting number.

    | 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
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX