| Program Library |
|
| Author: |
William Pantoja |
| Date: |
December 22, 2011 |
|
|
| |
|
Contents
1. Overview
2. Using
3. Programs
3.1. Library::HalfAdder
3.2. Library::FullAdder
3.3. Library::Decode
3.4. Library::Mux
3.5. Library::Demux
1. OVERVIEW
The program library is a set of programs that you can use when writing your own programs.
2. USING
You may use a program by using the CALL operator and specifing the program name. Many programs require input that must be placed on the stack using the PUSH operator before calling the program. When the program completes, its output is placed on the stack and may be read using the POP or PEEK operators.
3. PROGRAMS
In the programs below, inputs are listed in the order that they should be pushed onto the stack using the PUSH operator. Outputs are listed in the order that they would be popped off the stack using the POP operator.
3.1. LIBRARY::HALFADDER
The Library::HalfAdder program implements a binary half adder. This program helps illustrate how a computer adds two binary numbers together and is available for educational purposes. The ADD operator implements this functionality and more efficient to use.
Inputs:
Bn -- Bit n from the second binary number.
An -- Bit n from the first binary number.
Outputs:
S -- The sum of An, Bn, and Cin.
Cout -- The value of the carry resulting from the sum of An, Bn, and Cin.
Program Listing:
POP R1 POP R0 AND R0 R1 R3 PUSH R3 XOR R0 R1 R3 PUSH R3
3.2. LIBRARY::FULLADDER
The Library::FullAdder program implements a binary full adder. This program helps illustrate how a computer adds two binary numbers together and is available for educational purposes. The ADD operator implements this functionality and more efficient to use.
Inputs:
Cin -- The value of the carry from the previous call to Library::FullAdder or Library::HalfAdder. If this is the first call to Library::FullAdder, this value should be FALSE.
Bn -- Bit n from the second binary number.
An -- Bit n from the first binary number.
Outputs:
S -- The sum of An, Bn, and Cin.
Cout -- The value of the carry resulting from the sum of An, Bn, and Cin.
Program Listing:
POP R2 POP R1 POP R0 XOR R0 R1 R3 AND R2 R3 R4 AND R0 R1 R5 OR R4 R5 R4 PUSH R4 XOR R2 R3 R4 PUSH R4
3.3. LIBRARY::DECODE
The Library::Decode program implements a 2-to-4 line single bit decoder.
Inputs:
I0 -- The first bit of the encoded value.
I1 -- The second bit of the encoded value.
Outputs:
O0 -- The first bit of the decoded value.
O1 -- The second bit of the decoded value.
O2 -- The third bit of the decoded value.
O3 -- The fourth bit of the decoded value.
Program Listing:
POP R1 POP R0 AND R0 R1 R2 PUSH R2 NOT R0 R2 AND R2 R1 R2 PUSH R2 NOT R1 R2 AND R0 R2 R2 PUSH R2 NAND R0 R1 R2 PUSH R2
3.4. LIBRARY::MUX
The Library::Mux program implements a 4-to-1 line multiplexer.
Inputs:
I0 -- The first input stream.
I1 -- The second input stream.
I2 -- The third input stream.
I3 -- The fourth input stream.
S0 -- The first bit of the selector.
S1 -- The second bit of the selector.
Outputs:
F -- The multiplexed value.
Program Listing:
POP R5 POP R4 POP R3 POP R2 POP R1 POP R0 PUSH R4 PUSH R5 CALL Library::Decode POP R4 POP R5 POP R6 POP R7 AND R0 R4 R10 AND R1 R5 R11 AND R2 R6 R12 AND R3 R7 R13 OR R10 R11 R14 OR R14 R12 R14 OR R14 R13 R14 PUSH R14
3.5. LIBRARY::DEMUX
The Library::Demux program implements a 1-to-4 line demultiplexer.
Inputs:
F -- The multiplexed stream.
S0 -- The first bit of the selector.
S1 -- The second bit of the selector.
Outputs:
O0 -- The first output stream.
O1 -- The second output stream.
O2 -- The third output stream.
O3 -- The fourth output stream.
Program Listing:
POP R2 POP R1 POP R0 PUSH R1 PUSH R2 CALL Library::Decode POP R3 POP R4 POP R5 POP R6 OR R0 R6 R7 PUSH R7 OR R0 R5 R7 PUSH R7 OR R0 R4 R7 PUSH R7 OR R0 R3 R7 PUSH R7
|