Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

operatingsystem

  • Forked from Dao2.Trung@live.uwe.ac.uk / OperatingSystem
    Up to date with the upstream repository.
    user avatar
    Leo Trung (Student) authored
    6dc573f7
    History

    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:

    make

    Once the programs are compiled, you can execute them one by one. For example, to run Task 1, use:

    ./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:

    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:

      push prompt
      call printf
      add esp, 4      ; Clean up the stack

      Equivalent in C:

      printf(prompt);
    • Read the input:

      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:

      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.

    Worksheet 2 part 1

    The codebase for Worksheet 2 can be found in the ./os_worksheet_2 directory.

    Task 1

    It's not possible to find 0xCAFEBABE in the logQ.txt because it doesn't use hex to store registers. Instead, you can find EAX=CAFEBABE

    Task 2

    Implement a simple sum_of_three in C using additions.

     int sum_of_three(int arg1, int arg2, int arg3)
     {
     return arg1 + arg2 + arg3;
     }

    in the kmain.c And add a makefile to support transfer control from loader.asm to C as developed in task 1.

    Task 3

    Framebuffer and Serial Console Driver

    This project implements a simple framebuffer and serial port driver for output in an OS, along with a printf function that outputs formatted text to the framebuffer.

    Framebuffer Driver

    The framebuffer driver allows writing text to the screen with basic cursor manipulation. The main operations include writing characters to the screen, scrolling the screen when it reaches the bottom, and moving the cursor to the next line when a newline character (\n) is encountered.

    Key Functions:

    • write: Writes characters from a buffer to the framebuffer. Handles newline characters and automatic scrolling.
    int write(char *buf, unsigned int len);

    Task 4

    Partially completed

    Worksheet 2 part 2

    I did the coding, more revise coming up.