Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nyambura-pov/ics3203-cat2-assembly-faith-njuguna-150325
ALP CAT 2 : 💻 Assembly Programming: Exploring Control Flow, Array Manipulation, Modular Subroutines, and Hardware Simulation through hands-on tasks showcasing efficient memory management, branching logic, and system-level programming.
https://github.com/nyambura-pov/ics3203-cat2-assembly-faith-njuguna-150325
assembly assembly-language assembly-language-programming conditional-logic control-flow nasm
Last synced: 19 days ago
JSON representation
ALP CAT 2 : 💻 Assembly Programming: Exploring Control Flow, Array Manipulation, Modular Subroutines, and Hardware Simulation through hands-on tasks showcasing efficient memory management, branching logic, and system-level programming.
- Host: GitHub
- URL: https://github.com/nyambura-pov/ics3203-cat2-assembly-faith-njuguna-150325
- Owner: nyambura-pov
- License: other
- Created: 2024-11-15T09:01:20.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-27T18:48:58.000Z (3 months ago)
- Last Synced: 2024-11-27T19:25:46.483Z (3 months ago)
- Topics: assembly, assembly-language, assembly-language-programming, conditional-logic, control-flow, nasm
- Language: Assembly
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## GUIDE TO COMPILING AND EXECUTING CODE
To run and compile assembly programs, ensure you have a suitable environment set up (e.g., NASM for x86 architecture). Follow these instructions for each task:
1. **Compile the Assembly Code**
- For 64-bit systems:
```bash
nasm -f elf64 .asm -o .o
```
- For 32-bit systems:
```bash
nasm -f elf32 .asm -o .o
```2. **Link the Compiled Object File**
```bash
ld .o -o
```3. **Execute the Program**
```bash
./
```> Replace `` with the actual name of the task file (e.g., `task1`, `task2`, etc.).
---
### Task 1: Conditional Logic and Program Flow
#### Summary
This program determines whether a number entered by the user is "POSITIVE," "NEGATIVE," or "ZERO." It highlights the use of both conditional and unconditional jumps to control program execution.#### Key Challenges
- **Using Jump Instructions:** Selecting between unconditional (`jmp`) and conditional jumps (`je`, `jl`, etc.) was crucial for accurate flow control.
- **Branching Decisions:** The program required careful planning to handle the three scenarios without compromising stability.#### Takeaways
- Conditional jumps effectively simplify decision-making by leveraging comparisons for branching.
- Structuring the program into distinct sections improves readability and debugging efficiency.---
### Task 2: Reversing Arrays with Loops
#### Summary
This program accepts an array of integers, reverses its order in memory, and displays the reversed result. The reversal process is performed using a loop and avoids allocating extra memory.#### Key Challenges
- **In-Place Reversal:** Reorganizing elements within the same memory space required precise memory addressing.
- **Boundary Checks:** It was essential to iterate only halfway through the array to avoid errors like segmentation faults.
- **Index Handling:** Managing pointers for the array's start and end required close attention to avoid overlapping.#### Takeaways
- Register-based pointer arithmetic improves the program’s performance by reducing memory access.
- Halving the number of iterations ensures the reversal process is efficient and avoids unnecessary computations.---
### Task 3: Factorial Calculation with Modular Subroutines
#### Summary
This task involves computing the factorial of a user-supplied integer using a dedicated subroutine. The subroutine uses stack operations to preserve registers and applies a loop to perform repeated multiplications.#### Key Challenges
- **Register Preservation:** Using the stack to save and restore register values was crucial to maintaining program stability.
- **Input Conversion:** Handling and validating ASCII input for conversion to an integer was necessary to prevent errors.
- **Handling Large Values:** Factorial calculations produce large results, so input values near the upper limit required testing to avoid overflow.#### Takeaways
- Subroutines improve code modularity and reusability by isolating functionality.
- Proper stack management prevents interference with registers used in other parts of the program.---
### Task 4: Simulating Sensor-Control Systems
#### Summary
This program mimics a water level monitoring system. Depending on the simulated sensor’s input value, the program performs the following actions:
1. Activates a "motor" when water is below the desired level.
2. Stops the motor when the water level is optimal.
3. Sounds an "alarm" when the water level exceeds the safe threshold.#### Key Challenges
- **Port Simulation:** Representing input/output ports using memory locations required an innovative approach.
- **Logic Design:** Implementing efficient branching mechanisms to handle low, moderate, and high water levels without ambiguity.
- **Memory Mapping:** Correctly manipulating specific memory addresses to simulate sensor and motor interactions.#### Takeaways
- Simulating hardware behavior through code provides a practical understanding of port-based systems without relying on actual hardware.
- Using clear logic and modular programming makes it easier to debug and expand the system’s functionality.