From 51b71dc92d090029ae1298753ee868f36069428e Mon Sep 17 00:00:00 2001 From: "Nguyen13.Minh@live.uwe.ac.uk" <nguyen13.minh@live.uwe.ac.uk> Date: Thu, 12 Dec 2024 16:59:35 +0000 Subject: [PATCH] Update file README.md --- worksheet1/README.md | 165 +++++++++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 60 deletions(-) diff --git a/worksheet1/README.md b/worksheet1/README.md index ee8b558..4f6e5f4 100644 --- a/worksheet1/README.md +++ b/worksheet1/README.md @@ -10,25 +10,31 @@ This worksheet focuses on the implementation of assembler programs, use of exter --- -## Repository Structure - -repo-name/ -├── README.md -├── asm_io.inc -├── asm_io.asm -├── driver.c -├── task1.asm -├── task1.2.asm -├── task2.1.asm -├── task2.2.asm -├── task2.3.asm -├── Makefile - -## Task 1 -Task 1: Adding Two Integers - - -Task 1.1: Basic Addition + **Repository Structure** +``` +ws-os/ +├──worksheet1 + ├── image/ + ├── 1.png + ├── 1.2.png + ├── 2.1.png + ├── 2.2.png + ├── 2.3.png + ├── Makefile.png + ├── README.md + ├── asm_io.inc + ├── asm_io.asm + ├── driver.c + ├── task1.asm + ├── task1.2.asm + ├── task2.1.asm + ├── task2.2.asm + ├── task2.3.asm + ├── Makefile + +``` +**Task 1: Adding Two Integers** +#Task 1.1: Basic Addition  The program initializes two integers, computes their sum, and displays the result using print_int from asm_io. @@ -45,18 +51,22 @@ Output: The sum is printed on the console. Testing and Build Instructions: Assemble the code: +``` nasm -f elf task1.asm -o task1.o - +``` Link the object file with asm_io.o: +``` gcc -m32 task1.o asm_io.o -o task1 - +``` Run the executable: +``` ./task1 - +``` Output: +``` 21 - -Task 1.2: User-Defined Addition +``` +**Task 1.2: User-Defined Addition**  Extends Task 1.1 to accept user input for two integers and prints their sum with a formatted message. @@ -67,20 +77,28 @@ Add the integers and store the result in a register. Use print_string and print_int to format and display the result. Build Instructions: -Assemble the code: +**Assemble the code:** +``` nasm -f elf task1.2.asm -o task1.2.o -Link the object file with asm_io.o: +``` +**Link the object file with asm_io.o:** +``` gcc -m32 task1.2.o asm_io.o -o task1.2 -Run the executable: +``` +**Run the executable:** +``` ./task1_2 -Output Example: +``` +**Output Example:** +``` Enter a number: 15 Enter a number: 6 The sum of 15 and 6 is: 21 +``` +## Task 2 -##Task 2 -Task 2: Loops, Conditions, and Arrays -##Task 2.1 +**Task 2: Loops, Conditions, and Arrays** +#Task 2.1 Task 2.1: User Interaction and Validation  @@ -91,16 +109,25 @@ This task implements a program that: 3 Validates user input, shows error if number is not valid Build Instructions: +**Assemble the code:** +``` nasm -f elf task2.1.asm -o task2.1.o +``` +**Link the object file with asm_io.o:** +``` gcc -m32 task2.1.o asm_io.o -o task2.1 +``` +**Run the executable:** +``` ./task2.1 - -Output Example: +``` +**Output Example:** +``` Enter your name: Minh Enter the number of times to print the welcome message: 5 The number must be greater than 50 and less than 100! - -##Task 2.2 +``` +#Task 2.2 Task 2.2: Array Initialization and Summation  @@ -113,17 +140,23 @@ Use another loop to compute the sum of the array elements. Display the result using print_int. Build Instructions: -Assemble the code: +**Assemble the code:** +``` nasm -f elf task2.2.asm -o task2.2.o -Link the object file with asm_io.o: +``` +**Link the object file with asm_io.o:** +``` gcc -m32 task2.2.o asm_io.o -o task2.2 -Run the executable: +``` +**Run the executable:** +``` ./task2.2 - -Output Example: +``` +**Output Example:** +``` Sum of array: 5050 - -##Task 2.3 +``` +#Task 2.3 Task 2.3: Summing a Range in an Array  @@ -137,25 +170,33 @@ Use a loop to compute the sum of elements in the specified range. Display the result using print_int. Build Instructions: -Assemble the code: +**Assemble the code:** +``` nasm -f elf task2.3.asm -o task2.3.o -Link the object file with asm_io.o: +``` +**Link the object file with asm_io.o:** +``` gcc -m32 task2.3.o asm_io.o -o task2.3 -Run the executable: +``` +**Run the executable:** +``` ./task2.3 - -Output Example: +``` +**Output Example:** +``` Enter start of index(0-99): 10 Enter end index: 20 The sum of the range is: 165 +``` +## Task 3 -Task 3: Automating the Build Process with Make +**Task 3: Automating the Build Process with Make** Objective: The Makefile automates the compilation of all tasks for streamlined testing and execution. -Sample Makefile: +**Sample Makefile:**  - +``` all: task1 task1.2 task2.1 task2.2 task2.3 task1: task1.o asm_io.o @@ -175,17 +216,21 @@ task2_3: task2.3.o asm_io.o 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 +``` +**Commands:** +**Build the Kernel and ISO** +``` +make +``` +**Clean the Workspace** +``` make clean - -Lessons Learned: +``` +**Run the OS in QEMU** +``` +make run +``` +**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. \ No newline at end of file -- GitLab