Click or drag to resize

CommandListAppendBranchAbs(Int32) Method

Unconditionally branches to an absolute target command position within the current list.


Namespace: RAYLASE.SPICE3.ClientLib
Assembly: RAYLASE.SPICE3.ClientLib (in RAYLASE.SPICE3.ClientLib.dll) Version: 3.5.2
Syntax
C#
public void AppendBranchAbs(
	int pos
)

Parameters

pos  Int32
The absolute position of the branch target command within the current list.
Remarks
Appends a BRANCH_ABS command to the list.


See also: 12.5.3.1 Flow-Control within the current Command List

Example
Common Branch Command Examples
uint bitmask = 0x5AA5;

string labelname = "label";
string varname = "var";

CommandList list = new CommandList();
list.AppendJumpAbs( 0, 0 );         // at list offset 0.
list.AppendMarkAbs( 500, 500 );     // at list offset 1.
list.AppendJumpAbs( 100, 200 );     // at list offset 2.
list.AppendLabel( labelname );      // label placed before the command it designates
list.AppendMarkAbs( 500, 500 );     // <--- this is the branch target, at list offset 3.
list.AppendJumpAbs( 200, 300 );     // at list offset 4.

// Append various branch commands to the list:
for ( int i = 0; i < 9; i++ )
{
    switch ( i )
    {
        case 0:
            list.AppendBranchAbs( 3 ); // Unconditional
            break;

        case 1:
            list.AppendBranchRel( -2 ); // Unconditional
            break;

        case 2:
            list.AppendBranchToLabel( labelname ); // Unconditional
            break;

        case 3:
            list.AppendBranchAbs( 3, bitmask, IOPort.PortB, true ); // Conditional on value read from port.
            break;

        case 4:
            list.AppendBranchRel( -2, bitmask, IOPort.PortB, true ); // Conditional on value read from port.
            break;

        case 5:
            list.AppendBranchToLabel( labelname, bitmask, IOPort.PortB, true ); // Conditional on value read from port.
            break;

        case 6:
            list.AppendBranchAbs( 3, varname ); // Conditional on value of the boolean variable on the card.
            break;

        case 7:
            list.AppendBranchRel( -2, varname ); // Conditional on value of the boolean variable on the card.
            break;

        case 8:
            list.AppendBranchToLabel( labelname, varname ); // Conditional on value of the boolean variable on the card.
            break;

        default:
            break;
    };

    Console.WriteLine( $"{i + 1}: list commands:" );
    int count = 0;
    foreach ( var cmd in list )
        if ( count < ( list.Count - 2 ) )
            Console.Write( $" {count++}: {cmd.ToString()} " );
        else
            Console.WriteLine( $" {count++}: {cmd.ToString()}" );

    list.RemoveAt( list.Count - 1 ); // we're going to replace the branch command, but re-use the rest of the list
};

// output should be:
// 1: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BA, I32[ 3 ] }
// 2: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BR, I32[ -2 ] }
// 3: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BA, I32[ 0 ] }
// 4: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BAC, I32[ 3 ], U32[ 23205 ], I32[ 1 ], Bool[ False ], Bool[ True ], U32[ 4294967295 ] }
// 5: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BRC, I32[ -2 ], U32[ 23205 ], I32[ 1 ], Bool[ False ], Bool[ True ], U32[ 4294967295 ] }
// 6: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BAC, I32[ 0 ], U32[ 23205 ], I32[ 1 ], Bool[ False ], Bool[ True ], U32[ 4294967295 ] }
// 7: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BACF, I32[ 3 ], U32[ 2317739966 ], Bool[ False ] }
// 8: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BRCF, I32[ -2 ], U32[ 2317739966 ], Bool[ False ] }
// 9: list commands:
//  0: { JA, P2D[ X=0 Y=0 ] }  1: { MA, P2D[ X=500 Y=500 ] }  2: { JA, P2D[ X=100 Y=200 ] }  3: { MA, P2D[ X=500 Y=500 ] }  4: { JA, P2D[ X=200 Y=300 ] }
//  5: { BACF, I32[ 0 ], U32[ 2317739966 ], Bool[ False ] }
See Also