From ec8e96a57f2058130b4c6b9c21af46476e9bec69 Mon Sep 17 00:00:00 2001 From: Daniel Kibblewhite <daniel2.kibblewhite@live.uwe.ac.uk> Date: Wed, 13 Nov 2024 10:54:26 +0000 Subject: [PATCH] updated task 2 just md to complete then build --- ws1/README.md | 74 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/ws1/README.md b/ws1/README.md index 5d66745..88b9a61 100644 --- a/ws1/README.md +++ b/ws1/README.md @@ -2,7 +2,7 @@ ## Overview -This document details the creation of an assembly program that prompts the user for their name and the number of times to print a welcome message. The program subsequently validates the input and performs various operations, including summing elements in an array. +This document details the creation of an assembly programme that prompts the user for their name and the number of times to print a welcome message. The programme subsequently validates the input and performs various operations, including summing elements in an array. ## Build Process @@ -14,11 +14,11 @@ Initially, I created a directory named `src`, where I stored the necessary files - `task2.asm` - `driver.c` -Note that from task 1 we were already given the `asm_io.asm` & `asm_io.inc` & `driver.c` so it is just making the new assembler langauage work with the rest of the files already presented. +Note that from task 1, we were already given the `asm_io.asm`, `asm_io.inc`, and `driver.c`, so it is just making the new assembly language work with the rest of the files already presented. ### 2. Requirements -The assembly program is designed to accomplish the following objectives: +The assembly programme is designed to accomplish the following objectives: 1. Request the user's name. 2. Ask for a number to specify how many times the welcome message should be printed, ensuring it falls between 50 and 100. @@ -27,44 +27,45 @@ The assembly program is designed to accomplish the following objectives: 5. Calculate and display the total sum of the array's elements. 6. Prompt the user for a valid range (start and end) to sum the elements within the array. -### 2. Now the fun bit...(not) coding !! +### 3. Now the fun bit...(not) coding !! ### Task 2: Extending the Functionality -In `task2.asm`, I incorporated loops, conditionals, and array operations as outlined in the PC Assembly Language book. The program now prompts the user for their name and the number of times to print a welcome message, validating that the input number is within the specified range. +In `task2.asm`, I incorporated loops, conditionals, and array operations as outlined in the PC Assembly Language book. The programme now prompts the user for their name and the number of times to print a welcome message, validating that the input number is within the specified range. -### Key parts of the task +### Key Parts of the Task - **Welcome Message Programme**: - The program prompts for the user’s name and counts how many times to print the welcome message. + The programme prompts for the user’s name and counts how many times to print the welcome message. - ```asm - welcome_msg db "Hello Thanks for playing - may the odds ever be in your favour, ", 0 ; Welcome message string + ```asm + welcome_msg db "Hello! Thanks for playing - may the odds be ever in your favour, ", 0 ; Welcome message string prompt_name db "Please enter your Name (mine is Bob): ", 0 ; Prompt message for entering name prompt_count db "Enter number of times to print (between 50 and 100): ", 0 ; Prompt for number of repetitions + ``` - **How to Handle Errors**: -After prompting the user for the number of times to print the welcome message, the program should check if the input is within the specified range (50–100). If the input is invalid (less than 50 or greater than 100), the program should print an error message and return or exit instead of proceeding. + After prompting the user for the number of times to print the welcome message, the programme should check if the input is within the specified range (50–100). If the input is invalid, the programme prints an error message and exits instead of proceeding. - ```asm - ; --- Validating count --- - mov eax, [count] ; Move count into EAX for validation - cmp eax, 50 ; Compare count with 50 - jl display_error ; Jump to error if less than 50 - cmp eax, 100 ; Compare count with 100 - jg display_error ; Jump to error if greater than 100 + ```asm + ; --- Validating count --- + mov eax, [count] ; Move count into EAX for validation + cmp eax, 50 ; Compare count with 50 + jl display_error ; Jump to error if less than 50 + cmp eax, 100 ; Compare count with 100 + jg display_error ; Jump to error if greater than 100 + ``` - **Array Summing Programme**: - Defined an array of 100 elements initialised with values from 1 to 100. - Calculated and displayed the total sum of the array. - **Range-Specific Sum**: - Extended the functionality to ask the user for a start and end range. The program validates the range before summing the elements within those limits and outputs the result. + Extended the functionality to ask the user for a start and end range. The programme validates the range before summing the elements within those limits and outputs the result. +### Task 3: Setting Up the Programme -#### Task 3: Setting Up the Program - -Based on the assembly build process from Task1, I updated this to include task 2 - from here i was then able to create a make file to create all of the task using one commnd make +Based on the assembly build process from Task 1, I updated this to include Task 2. From here, I was then able to create a makefile to build all of the task using one command. To build the initial assembly project (`task2`), I used the following commands: @@ -74,6 +75,33 @@ nasm -f elf asm_io.asm -o asm_io.o # Assemble the I/O library gcc -m32 -c driver.c -o driver.o # Compile the C driver gcc -m32 driver.o task2.o asm_io.o -o task2 # Link to create the executable -Because this is then set up to be able to run the command task2 we now use the command +... + +### Run Programme +To run the programme, use the command: ```bash -./task2 \ No newline at end of file +./task2 + +... + +## Showing an Example of Task 2 Running + +In order to show that this code runs, I have included two photos: + +- **Photo 1**: + Shows what happens when someone enters a number that is outside of the validation rule. +  + +- **Photo 2**: + Shows the full code working. +  + +## Further Steps & Conclusion + +- **What Would I Do Differently?**: + If I were to write all this code again (though I probably wouldn't), I would add validation to ensure that the input for a name only accepts text rather than numbers. I would also consider changing the colour of the name to make it stand out a bit more. Additionally, I might change the colour of all inputs so it's easy to distinguish what the input is and what the output is. Although users should know what the input is since they just typed it, it would look visually more appealing. + +- **Conclusion**: + My code works just about. Thank you for looking at it and this document. Have a good day, and remember: + + #### May the odds ever be in your favour. -- GitLab