Machine: Machine 1 - Integer Machine
Subject: CSARCH2
Section: S03
Group: Group 7
GitHub Link: https://github.com/ainere/CSARCH2-Case-Study-1-Integer-Machine
Website Link: https://csarch2-case-study-1-integer-machine-s03-group7.streamlit.app/
Youtube Demo Link: https://youtu.be/p0JcdHcN3fA
- Alain Zuriel Marcos
- Elkan La Madrid
- Jenrick Lim
- Kent Lopez
The Machine 1 Integer Machine is a functional Streamlit web application that demonstrates fixed-width integer representation and register-level arithmetic. It is intended to make each algorithm easier to follow by showing both the final answer and the intermediate register states used to reach it.
The website currently includes three working tools:
- decimal-to-binary integer conversion;
- signed sequential multiplication (Booth's algorithm); and
- unsigned non-restoring division.
Each tool accepts user input, validates it against the selected data size, and displays an explanation of the result. Multiplication and division also include complete cycle-by-cycle trace tables.
| Technology | Role |
|---|---|
| Python 3.12+ | Implements the integer algorithms, validation, and application logic |
| Streamlit | Provides the interactive web interface and technical-lab layout |
| CSS | Adds the custom colors, cards, tables, typography, and responsive styling |
Python provides the calculation layer for the machine. The arithmetic modules are separate from the interface, allowing the algorithms to be tested without running Streamlit.
Used for:
- fixed-width signed and unsigned conversion;
- input parsing and range validation;
- signed sequential multiplication (Booth's algorithm) using
A,Q,Q-1, andM; - non-restoring division using
A,Q, andM; and - immutable result and trace records.
Streamlit provides the website interface. It allows the group to build a working Python-based web application without maintaining a separate frontend and backend.
Used for:
- data-size and number-format controls;
- separate Conversion, Multiplication, and Division tabs;
- inline validation messages that preserve the user's input;
- result cards and guided explanations; and
- responsive register trace tables.
Concept: Converts one decimal integer into fixed-width binary while evaluating its unsigned and signed two's-complement interpretations independently.
Inputs:
- a decimal integer; and
- a data size from 2 to 256 bits.
Outputs:
- unsigned decimal and fixed-width binary, when the value fits;
- signed decimal and fixed-width two's-complement binary, when the value fits;
- minimum and maximum values for both interpretations; and
- a separate overflow message for any interpretation that cannot represent the input.
This separation is important because a value may fit one interpretation but
not the other. For example, 255 fits unsigned 8-bit representation but does
not fit signed 8-bit two's complement.
Concept: Demonstrates signed sequential circuit multiplication using Booth's algorithm using the A, Q, Q-1, and M registers.
How it works:
Mstores the multiplicand.Qstores the multiplier.Astores the partial product.Q-1stores the extra bit for Booth's recoding.- The machine inspects the bit pair Q₀Q₋₁ each cycle:
- If 10: subtract M from A (A = A - M)
- If 01: add M to A (A = A + M)
- If 00 or 11: no operation (copy)
- The combined
A,Q,Q-1registers undergo an arithmetic shift right after every cycle (preserving the sign bit). - After
ncycles, the final product is the concatenatedA:Qvalue.
The website shows the initial register state, the action taken based on Q0 Q-1, the
registers before and after each shift, and the final product in decimal and
binary.
Concept: Demonstrates unsigned non-restoring division using the A, Q,
and M registers.
How it works:
Qbegins with the dividend.Mstores the divisor.Astores the signed partial remainder.- The combined
A,Qregisters are shifted left during each cycle. - The machine subtracts
Mwhen the previousAis non-negative and addsMwhen it is negative. - A quotient bit is assigned after each arithmetic operation.
- If the final partial remainder is negative, the machine restores it by
adding
M.
The website displays the quotient, remainder, final registers, optional restoration step, and a complete cycle trace.
The interface uses one shared data-size control and supports two operand formats for multiplication and division.
| Input | Accepted values |
|---|---|
| Data size | Whole numbers from 2 to 256 bits; 8 bits by default |
| Conversion value | Signed base-10 integer |
| Decimal arithmetic operand | Non-negative base-10 integer |
| Binary arithmetic operand | 0 and 1, with optional 0b prefix, spaces, or underscores |
| Divisor | Any supported positive value; zero is rejected |
Arithmetic operands must fit the selected unsigned width. Invalid values are reported beside the form without clearing the user's entries.
The 256-bit maximum is an interface guardrail that prevents accidentally generating an impractically large trace table. The pure Python calculation modules use arbitrary-precision integers and are not internally limited to 256 bits.
- Python 3.12 or newer
pip
Clone the repository and enter its folder:
git clone https://github.com/ainere/CSARCH2-Case-Study-1-Integer-Machine.git
cd CSARCH2-Case-Study-1-Integer-MachineCreate and activate a virtual environment:
python -m venv .venv
.\.venv\Scripts\Activate.ps1Install the dependencies:
python -m pip install -r requirements.txtpython -m streamlit run app.pyStreamlit will print a local address, normally
http://localhost:8501. Open that address in a browser and stop the server
with Ctrl+C when finished.
app.py Streamlit forms, tabs, and result presentation
integer_machine/
conversion.py Fixed-width signed and unsigned conversion
multiplication.py Unsigned sequential add-and-shift multiplier
division.py Unsigned non-restoring divider
models.py Immutable result and trace records
parsing.py Input validation and binary formatting
.streamlit/config.toml Streamlit theme and server defaults
requirements.txt Runtime dependency
The integer_machine/ package is the independent teaching core. It has no
Streamlit dependency. The app.py file acts as the presentation layer: it
collects inputs, calls the appropriate algorithm, and renders the results.
- Created a working Streamlit website with a responsive technical-laboratory visual style.
- Implemented independent unsigned and signed fixed-width conversion results.
- Implemented signed sequential multiplication (Booth's algorithm) with complete
A,Q,Q-1,Mregister traces. - Implemented unsigned non-restoring division with complete
A,Q,Mtraces and final remainder restoration. - Added decimal and binary operand formats with readable grouped binary output.
- Added inline validation while retaining the user's entered values.
- Separated the arithmetic core from the Streamlit presentation layer.
- Documented local installation, execution, input rules, limitations, and project structure.
The team utilized AI tools such as ChatGPT for brainstorming our code and UI platform, eventually landing on Python and Streamlit.
All core content and actual implementation of the interactive exhibit were reviewed, verified, and executed entirely by us. AI tools were merely used to support our learning and polish the user experience.
| Tool | Purpose |
|---|---|
| ChatGPT | Brainstorming the platforms to be used for both logic and UI design |













































