From ec7bb4ae7b83abe6c0ae5ba3630f6fc620db872e Mon Sep 17 00:00:00 2001 From: "Leo Trung (Student)" <dao2.trung@live.uwe.ac.uk@csctcloud.prxhn32zsyjupl12zde3wlfkch.cwx.internal.cloudapp.net> Date: Thu, 12 Dec 2024 21:10:14 +0000 Subject: [PATCH] Add README.md for task 4 of worksheet 1 --- README.md | 85 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/task1.asm | 2 ++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4ff7854..ffa0f98 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,80 @@ -# Learn Week 3 -## Log file -## App/State Repository-Machine -Srd-shm -## Unlock File Single \ No newline at end of file +# Operating System Worksheet Submission + +## Description +This document contains the worksheet submissions and related lesson files for *Dao Hieu Trung*, a student from *UWE Bristol - Phenikaa Campus*. +- **Student Username**: DH2-TRUNG +- **Student ID**: 23085493 + +## Worksheet 1 + +### Overview +The source code for Worksheet 1 is located in the `./src` directory. +To compile the programs, use the provided `Makefile` by running: + +```bash +make +``` + +Once the programs are compiled, you can execute them one by one. For example, to run **Task 1**, use: + +```bash +./task1 +``` + +### Task 1 +In this task, the memory layout of the program is explained. The sections are as follows: + +- **`section .data`**: Used to store initialized variables. +- **`section .bss`**: Used to store uninitialized variables. +- **`section .text`**: This section contains the actual machine code (instructions) of the program, and in this case, the instructions are sourced from `driver.o`. + +The program begins with `asm_main`, a global function that is typically called from C using `_start`. Below is an example of how `printf` is used to print a message: + +```assembly +push msg +call printf +add esp, 4 ; Clean up the stack (removes 4 bytes) +``` + +In this example, `msg` is pushed onto the stack (which is 4 bytes). After calling `printf`, the stack is cleaned up by adjusting the stack pointer to release the 4 bytes. + +### Task 2 + +#### 2.1 Equivalent C Code Comments +The assembly code in this worksheet mimics certain functions that would typically be found in C programming. To clarify the relationship between assembly and C, I have added comments to point out the equivalent C functions. For example: + +- **Print the prompt**: + ```assembly + push prompt + call printf + add esp, 4 ; Clean up the stack + ``` + Equivalent in C: + ```c + printf(prompt); + ``` + +- **Read the input**: + ```assembly + push name ; Address of the buffer to store the input + push format ; Format string for scanf + call scanf + add esp, 8 ; Clean up the stack (2 arguments) + ``` + Equivalent in C: + ```c + scanf(format, name); + ``` + +#### 2.2 Loops +In assembly, loops are implemented with a mechanism similar to that of C. Loops in assembly typically involve setting up a counter, checking a condition, and then jumping to a specific part of the code based on that condition. + +#### 2.3 Conditional Statements +Conditional statements in assembly are implemented using comparison and jump instructions, like `cmp` and `jne`. This can be directly mapped to if-else statements in C. + +#### 2.4 Added Variables +In the program, I have added the variables `start_range` and `end_range` to define the range for summing values or performing other calculations. + +## Worksheet 2 + +The codebase for Worksheet 2 can be found in the `./os_worksheet_2` directory. diff --git a/src/task1.asm b/src/task1.asm index b73a117..85e3f32 100644 --- a/src/task1.asm +++ b/src/task1.asm @@ -6,8 +6,10 @@ section .text global asm_main asm_main: + ;Print the message push msg call printf add esp, 4 ; Clean up the stack + xor eax, eax ; Return 0 ret \ No newline at end of file -- GitLab