Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
1 result

backtrace

Blame
  • Forked from h-attak / Pintos_Student
    Source project has a limited visibility.
    README.md NaN GiB
    # Task 2 Documentation
    
    ## Overview
    
    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
    
    ### 1. Initial Setup
    
    Initially, I created a directory named `src`, where I stored the necessary files for the project, including:
    - `asm_io.asm`
    - `asm_io.inc`
    - `task2.asm`
    - `driver.c`
    
    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 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.
    3. Print the welcome message the designated number of times.
    4. Define and initialise an array of 100 integers with values from 1 to 100.
    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.
    
    ### 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 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
    
    - **Welcome Message Programme**: 
      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 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 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
        ```
    
    - **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 programme validates the range before summing the elements within those limits and outputs the result.
    
    ### Task 3: Setting Up the Programme
    
    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:
    
    ```bash
    nasm -f elf task2.asm -o task2.o              # Assemble the assembly file
    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
    
    ```
    
    ### Run Programme
    To run the programme, use the command:
    ```bash
    ./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 Outside Of Validation Rule](os_worksheet/ws1/src/Task2_full.jpg)
    
    - **Photo 2**:
      Shows the full code working.
      ![Fully Working Code](os_worksheet/ws1/src/Task2_full.jpg)
    
    ## 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.