Square the input

This is a basic example of how to square the value coming in on the Stage input.

Download this project

Program Listing

    // [title] Square the input
// [brief] This is a basic example of how to square the value coming in on the Stage input.
// [categories] Examples - math

initial:
    // ---------------------------------
    // [brief]  Setup and initialization
    // ---------------------------------

    // [acu]    Clear
    // [alu]    Set to zero
    acu(clear, clear) dmux(sa, sa) alu(set0) mac(hold)

    // [acu]    Set modulus arithmentic [ON]
    // [jmp]    Unconditional jump to [wait_for_in1]
    acu(setmod, setmod) dmux(sa, sa) alu(hold) mac(hold) jmp(eob, wait_for_in1)

wait_for_in1:
    // ----------------------------------------------------------------
    // [brief]  Wait for data to be written to Staging Register Input 1
    // ----------------------------------------------------------------

    // [jmpl]:      Is value [in1] register populated with Stage_A data?
    //                  [True]   Value loaded - go to [dataRead]
    //                  [False]  Loop to [wait_for_in1]
    // [dmux].a     Set up to load Stage_A value into [mac].a and [mac].b
    // [mac]        Set up to multiply a * b without adding any accumulated value
    acu(hold, hold) addr(1) dmux(bm, bm) alu(hold) mac(clra) jmpl(in1, dataRead)

dataRead:
    // --------------------------------------------------
    // [brief]  Run the calculation and output the result
    // --------------------------------------------------

    // [mac]    Loads a and b from Stage_A -> Mux_0 -> Mux_1 -> Mux_2 -> mac
    acu(hold, hold) dmux(sm, sm) alu(seta) mac(hold)

    // [mac]    Multiplication of a and b is output
    // [alu]    Set up to output mac result
    acu(hold, hold) dmux(sa, sa) alu(hold) mac(hold)

    // [alu]    Output mac result
    acu(hold, hold) dmux(sm, sm) alu(seta) mac(hold)

    // [write]  Write calculation result to [Hold_A]
    // [jmp]    Unconditional jump to [wait_for_in1]
    acu(hold, hold) addr(1) dmux(sm, sm) alu(hold) mac(hold) write(abus) jmp(eob, wait_for_in1)
  

State Diagrams

Jump Diagram

Your browser does not support SVG
Call Diagram for this program from the DFB Assembler Mini IDE