# UFCFWK‑15‑2 Operating Systems 2024: Worksheet 1 - An Echo of Assembler
# Worksheet 1 - An Echo of Assembler
## Getting started
# Nguyen13.Minh@live.uwe.ac.uk - @nn3-minh
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
## Introduction
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
This worksheet focuses on the implementation of assembler programs, use of external libraries, user input/output interaction, and handling of loops, conditions, and arrays. The following are details of tasks completed, with build instructions and their respective outputs.
## Add your files
---
-[ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
## Repository Structure
-[ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
-[ ] [Set up project integrations](https://gitlab.uwe.ac.uk/nn3-minh/ws-os/-/settings/integrations)
├── Makefile
## Collaborate with your team
## Task 1
Task 1: Adding Two Integers
-[ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
Task 1.1: Basic Addition
-[ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
The program initializes two integers, computes their sum, and displays the result using print_int from asm_io.
-[ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
Add the values and store the result in a register.
Use the print_int function from asm_io to display the result.
Use the built-in continuous integration in GitLab.
Code Description:
-[ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
Input: Predefined integers in .data.
-[ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
Output: The sum is printed on the console.
-[ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-[ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
Testing and Build Instructions:
-[ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
Assemble the code:
nasm -f elf task1.asm -o task1.o
***
Link the object file with asm_io.o:
# Editing this README
gcc -m32 task1.o asm_io.o -o task1
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
Run the executable:
./task1
## Suggestions for a good README
Output:
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
21
## Name
Task 1.2: User-Defined Addition
Choose a self-explaining name for your project.
Extends Task 1.1 to accept user input for two integers and prints their sum with a formatted message.
## Description
Implementation Steps:
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
Use read_int from asm_io to get two integers from the user.
Add the integers and store the result in a register.
## Badges
Use print_string and print_int to format and display the result.
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
Build Instructions:
## Visuals
Assemble the code:
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
nasm -f elf task1.2.asm -o task1.2.o
Link the object file with asm_io.o:
## Installation
gcc -m32 task1.2.o asm_io.o -o task1.2
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
Run the executable:
./task1_2
## Usage
Output Example:
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
Enter a number: 15
Enter a number: 6
## Support
The sum of 15 and 6 is: 21
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
##Task 2
## Roadmap
Task 2: Loops, Conditions, and Arrays
If you have ideas for releases in the future, it is a good idea to list them in the README.
##Task 2.1
## Contributing
Task 2.1: User Interaction and Validation
State if you are open to contributions and what your requirements are for accepting them.
This task implements a program that:
1 Prompts the user for their name and a number between 51 and 99.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
2 Prints a greeting message the specified number of times.
3 Validates user input, shows error if number is not valid
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
Build Instructions:
## Authors and acknowledgment
nasm -f elf task2.1.asm -o task2.1.o
Show your appreciation to those who have contributed to the project.
gcc -m32 task2.1.o asm_io.o -o task2.1
./task2.1
## License
For open source projects, say how it is licensed.
Output Example:
Enter your name: Minh
## Project status
Enter the number of times to print the welcome message: 5
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
The number must be greater than 50 and less than 100!
##Task 2.2
Task 2.2: Array Initialization and Summation
The program initializes an array with values from 1 to 100, computes their sum, and prints the result.
Implementation Steps:
Allocate space for the array in .bss.
Use a loop to initialize the array with integers 1 through 100.
Use another loop to compute the sum of the array elements.
Display the result using print_int.
Build Instructions:
Assemble the code:
nasm -f elf task2.2.asm -o task2.2.o
Link the object file with asm_io.o:
gcc -m32 task2.2.o asm_io.o -o task2.2
Run the executable:
./task2.2
Output Example:
Sum of array: 5050
##Task 2.3
Task 2.3: Summing a Range in an Array
Enhances Task 2.2 by allowing the user to specify a range of indices and computes the sum of elements within that range.
Implementation Steps:
Reuse the array from Task 2.2.
Accept a start and end index from the user.
Validate that the indices are within bounds and start <= end.
Use a loop to compute the sum of elements in the specified range.
Display the result using print_int.
Build Instructions:
Assemble the code:
nasm -f elf task2.3.asm -o task2.3.o
Link the object file with asm_io.o:
gcc -m32 task2.3.o asm_io.o -o task2.3
Run the executable:
./task2.3
Output Example:
Enter start of index(0-99): 10
Enter end index: 20
The sum of the range is: 165
Task 3: Automating the Build Process with Make
Objective:
The Makefile automates the compilation of all tasks for streamlined testing and execution.
Sample Makefile:
all: task1 task1.2 task2.1 task2.2 task2.3
task1: task1.o asm_io.o
gcc -m32 task1.o asm_io.o -o task1
task1_2: task1.2.o asm_io.o
gcc -m32 task1.2.o asm_io.o -o task1.2
task2_1: task2.1.o asm_io.o
gcc -m32 task2.1.o asm_io.o -o task2.1
task2_2: task2.2.o asm_io.o
gcc -m32 task2.2.o asm_io.o -o task2.2
task2_3: task2.3.o asm_io.o
gcc -m32 task2.3.o asm_io.o -o task2.3
clean:
rm -f *.o task1 task1.2 task2.1 task2.2 task2.3
Commands:
make all
./task1
./task1.2
./task2.1
./task2.2
./task2.3
make clean
Lessons Learned:
1 Gained familiarity with assembler programming for basic operations, user interaction, and array manipulation.
2 Learned how to call external libraries and integrate assembler code with C.
3 Automated repetitive build tasks with a Makefile.