Skip to content
Snippets Groups Projects
Commit ec7bb4ae authored by Leo Trung (Student)'s avatar Leo Trung (Student)
Browse files

Add README.md for task 4 of worksheet 1

parent 8993161c
Branches master
No related tags found
No related merge requests found
# Learn Week 3 # Operating System Worksheet Submission
## Log file
## App/State Repository-Machine ## Description
Srd-shm This document contains the worksheet submissions and related lesson files for *Dao Hieu Trung*, a student from *UWE Bristol - Phenikaa Campus*.
## Unlock File Single - **Student Username**: DH2-TRUNG
\ No newline at end of file - **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.
...@@ -6,8 +6,10 @@ section .text ...@@ -6,8 +6,10 @@ section .text
global asm_main global asm_main
asm_main: asm_main:
;Print the message
push msg push msg
call printf call printf
add esp, 4 ; Clean up the stack add esp, 4 ; Clean up the stack
xor eax, eax ; Return 0 xor eax, eax ; Return 0
ret ret
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment