diff --git a/Worksheet_1/Makefile b/Worksheet_1/Makefile index aaec790657ade094ac4c4b416eab9d42485e2506..7d859d4358150520451a2b39b4d910d1982c7aca 100644 --- a/Worksheet_1/Makefile +++ b/Worksheet_1/Makefile @@ -1,22 +1,22 @@ -all: task1 task2 task3 +all: task1 task2_1 task2_2 task1: src/task1.o src/driver.o src/asm_io.o gcc -m32 -o src/task1 src/task1.o src/driver.o src/asm_io.o -task2: src/task2.o src/driver.o src/asm_io.o src/print_int.o - gcc -m32 -o src/task2 src/task2.o src/driver.o src/asm_io.o src/print_int.o +task2_1: src/task2_1.o src/driver.o src/asm_io.o src/print_int.o + gcc -m32 -o src/task2_1 src/task2_1.o src/driver.o src/asm_io.o src/print_int.o -task3: src/task3.o src/driver.o src/asm_io.o src/print_int.o - gcc -m32 -o src/task3 src/task3.o src/driver.o src/asm_io.o src/print_int.o +task2_2: src/task2_2.o src/driver.o src/asm_io.o src/print_int.o + gcc -m32 -o src/task2_2 src/task2_2.o src/driver.o src/asm_io.o src/print_int.o src/task1.o: src/task1.asm nasm -f elf src/task1.asm -o src/task1.o -src/task2.o: src/task2.asm - nasm -f elf src/task2.asm -o src/task2.o +src/task2_1.o: src/task2_1.asm + nasm -f elf src/task2_1.asm -o src/task2_1.o -src/task3.o: src/task3.asm - nasm -f elf src/task3.asm -o src/task3.o +src/task2_2.o: src/task2_2.asm + nasm -f elf src/task2_2.asm -o src/task2_2.o src/driver.o: src/driver.c gcc -m32 -c src/driver.c -o src/driver.o @@ -28,4 +28,4 @@ src/print_int.o: src/print_int.c gcc -m32 -c src/print_int.c -o src/print_int.o clean: - rm -f src/*.o src/task1 src/task2 src/task3 + rm -f src/*.o src/task1 src/task2_1 src/task2_2 diff --git a/Worksheet_1/README.md b/Worksheet_1/README.md index 95264be27189a4b7f554e1965f2fed505a74d080..fddd09141e8678cf3b05ea3651de850a3aef1a37 100644 --- a/Worksheet_1/README.md +++ b/Worksheet_1/README.md @@ -61,11 +61,11 @@ apt install -y libc6-dev ``` - Task 2: ```bash - ./src/task2 + ./src/task2_1 ``` - - Task 3: + - Task 2_2: ```bash - ./src/task3 + ./src/task2_2 ``` - Clean up object files and executables: ```bash @@ -113,11 +113,11 @@ call _print_int #### How to Compile and Run: 1. Compile the assembly file: ```bash - nasm -f elf32 src/task1.asm -o task1.o + nasm -f elf32 src/task1.asm -o src/task1.o ``` -2. Link with `driver.o` and `print_int.o`: +2. Link the compiled task1.o, driver.o, and print_int.o files using gcc to create an executable file: ```bash - gcc -m32 task1.o src/driver.o src/print_int.o -o src/task1 + gcc -m32 src/task1.o src/driver.o src/print_int.o -o src/task1 ``` 3. Run the executable: ```bash @@ -133,8 +133,8 @@ call _print_int --- -## Task 2: Loops and Conditionals -- **File**: `task2.asm` +## Task 2_1: Loops and Conditionals +- **File**: `task2_1.asm` - **Description**: Implements a loop to sum an array of integers and validates user input. ### Code Explanation: @@ -186,33 +186,34 @@ call _print_int #### How to Compile and Run: 1. Compile the assembly file: ```bash - nasm -f elf32 src/task2.asm -o task2.o + nasm -f elf32 src/task2_1.asm -o src/task2_1.o ``` -2. Link with `driver.o`: +2. Link the compiled task2_1.o, driver.o, and print_int.o files using gcc to create an executable file: ```bash - gcc -m32 task2.o driver.o asm_io.o -o task2 + gcc -m32 src/task2_1.o src/driver.o src/print_int.o -o src/task2_1 + ``` 3. Run the executable: ```bash - ./src/task2 + ./src/task2_1 ``` -# Task 2 Output +# Task 2_1 Output -## Screenshot of Task 2 +## Screenshot of Task 2_1 The following screenshot demonstrates the successful execution of Task 2. It showcases the program's ability to validate user input and sum an array of integers within a specified range. - + ## Explanation -In Task 2, the program performs two main functions: +In Task 2_1, the program performs two main functions: 1. Validates user input to ensure the entered number is within a specified range (50–100). 2. Sums integers from an array and displays the result. --- -### Task 3: Loops and Conditionals -- **File**: `task3.asm` +### Task 2_2: Loops and Conditionals +- **File**: `task2_2.asm` - **Description**: This task sums integers within a specified range using loops in assembly. It calculates the total sum of all numbers between two user-provided inputs. @@ -252,22 +253,24 @@ Uses a loop to add all integers between start and end inclusively. #### How to Compile and Run: 1. Compile the assembly file: ```bash - nasm -f elf32 src/task3.asm -o task3.o + nasm -f elf32 src/task2_2.asm -o src/task2_2.o + ``` -2. Link with driver.o to create the executable: +2. Link the compiled task1.o, driver.o, and print_int.o files using gcc to create an executable file: ```bash - gcc -m32 task3.o driver.o asm_io.o -o task3 + gcc -m32 src/task2_2.o src/driver.o src/print_int.o -o src/task2_2 + ``` 3. Run the program: ```bash - ./src/task3 + ./src/task2_2 ``` -# Task 3 Output +# Task 2_2 Output -## Screenshot of Task 3 -The following screenshot demonstrates the successful execution of Task 3. It shows the program prompting the user to enter the size of an array and values one by one. It calculates the maximum, minimum, and sum of all values. +## Screenshot of Task 2_2 +The following screenshot demonstrates the successful execution of Task 2_2. It shows the program prompting the user to enter the size of an array and values one by one. It calculates the maximum, minimum, and sum of all values. - + ## Explanation In Task 3, the program performs the following operations: @@ -294,24 +297,14 @@ worksheet_1/ │ ├── driver.c # Main C program calling assembly functions │ ├── print_int.c # Helper C program for printing integers │ ├── task1.asm # Assembly code for Task 1 -│ ├── task2.asm # Assembly code for Task 2 -│ ├── task3.asm # Assembly code for Task 3 +│ ├── task2_1.asm # Assembly code for Task 2 +│ ├── task2_2.asm # Assembly code for Task 3 ├── task1 # Compiled Task 1 executable -├── task2 # Compiled Task 2 executable -├── task3 # Compiled Task 3 executable -└── *.o # Object files (task1.o, task2.o, task3.o, asm_io.o, driver.o, print_int.o) +├── task2_1 # Compiled Task 2 executable +├── task2_2 # Compiled Task 3 executable +└── *.o # Object files (task1.o, task2.o, task2_2.o, asm_io.o, driver.o, print_int.o) ``` -## Screenshots and Outputs - -To fulfill the documentation requirements, include screenshots of: -1. **Task 1 Output**: Showing the result of adding two integers. -2. **Task 2 Output**: Demonstrating user input validation and array summation. -3. **Task 3 Build**: Displaying the successful build process using the `Makefile`. - -Include brief explanations for each screenshot. - ---- ## Authors diff --git a/Worksheet_1/asm_io.o b/Worksheet_1/src/asm_io.o similarity index 100% rename from Worksheet_1/asm_io.o rename to Worksheet_1/src/asm_io.o diff --git a/Worksheet_1/driver.o b/Worksheet_1/src/driver.o similarity index 100% rename from Worksheet_1/driver.o rename to Worksheet_1/src/driver.o diff --git a/Worksheet_1/print_int.o b/Worksheet_1/src/print_int.o similarity index 100% rename from Worksheet_1/print_int.o rename to Worksheet_1/src/print_int.o diff --git a/Worksheet_1/task1 b/Worksheet_1/src/task1 similarity index 100% rename from Worksheet_1/task1 rename to Worksheet_1/src/task1 diff --git a/Worksheet_1/task1.o b/Worksheet_1/src/task1.o similarity index 100% rename from Worksheet_1/task1.o rename to Worksheet_1/src/task1.o diff --git a/Worksheet_1/task2 b/Worksheet_1/src/task2_1 similarity index 65% rename from Worksheet_1/task2 rename to Worksheet_1/src/task2_1 index c49fc7e86669300ab26b842fa868822260757a24..003c988ef5d830390da2ca657d6c623304e2e69a 100644 Binary files a/Worksheet_1/task2 and b/Worksheet_1/src/task2_1 differ diff --git a/Worksheet_1/src/task2.asm b/Worksheet_1/src/task2_1.asm similarity index 100% rename from Worksheet_1/src/task2.asm rename to Worksheet_1/src/task2_1.asm diff --git a/Worksheet_1/task2.o b/Worksheet_1/src/task2_1.o similarity index 57% rename from Worksheet_1/task2.o rename to Worksheet_1/src/task2_1.o index 729f3797fae73c0f128fb7d0fcc4863424f71882..4ef86beeca53f454b69a84b15f50dd5eeef29f40 100644 Binary files a/Worksheet_1/task2.o and b/Worksheet_1/src/task2_1.o differ diff --git a/Worksheet_1/task3 b/Worksheet_1/src/task2_2 similarity index 73% rename from Worksheet_1/task3 rename to Worksheet_1/src/task2_2 index ea2533f331c34a404d87e47704b91fd2fcfdf2fb..4a9c4dce4c0b4e8c8f1c9f084342dd6759e5f0c3 100644 Binary files a/Worksheet_1/task3 and b/Worksheet_1/src/task2_2 differ diff --git a/Worksheet_1/src/task3.asm b/Worksheet_1/src/task2_2.asm similarity index 100% rename from Worksheet_1/src/task3.asm rename to Worksheet_1/src/task2_2.asm diff --git a/Worksheet_1/task3.o b/Worksheet_1/src/task2_2.o similarity index 61% rename from Worksheet_1/task3.o rename to Worksheet_1/src/task2_2.o index 7dfc7551e6fa30642e85cea7eb702e6b5a6c007e..a4c8f0679bea8d70b22a26bf3edcc8798cd1068c 100644 Binary files a/Worksheet_1/task3.o and b/Worksheet_1/src/task2_2.o differ