21BPS1108 Lab Report 3 and 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

21BPS1108

SUMUKH SHARMA
BCSE303P
OPERATING SYSTEMS LAB 3
21/05/2023

QEMU
Create a first Bootloader that does nothing.
Source Code
[BITS 16] ;tell the assembler that its a 16 bit code

[ORG 0x7C00] ;Origin, tell the assembler that where the code will

;be in memory after it is been loaded

JMP $ ;infinite loop

TIMES 510 - ($ - $$) db 0 ;fill the rest of sector with 0

DW 0xAA55 ; add boot signature at the end of bootloader


2. Create 2nd Bootloader that prints ‘A’ on the screen.
bits 16
org 0x7c00
boot:
mov si,hello
mov ah, 0x0e
.loop:
lodsb
or al,al
jz halt
int 0x10
jmp .loop
halt:
cli
hlt
hello: db "A",0

times 510 - ($-$$) db 0


dw 0xaa55
3. Third bootloader: 'Hello World This is My OS' Bootloader
SOURCE CODE:-
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV SI, HelloString ;Store string pointer to SI
CALL PrintString ;Call print string procedure
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E ;Tell BIOS that we need to print one character on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is light grey font on black background
INT 0x10 ;Call video interrupt
RET ;Return to calling procedure
PrintString: ;Procedure to print string on screen
;Assume that string starting pointer is in register SI
next_character: ;Lable to fetch next character from string
MOV AL, [SI] ;Get a byte from string and store in AL register
INC SI ;Increment SI pointer
OR AL, AL ;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL register
JMP next_character ;Fetch next character from string
exit_function: ;End label
RET ;Return from procedure
;Data
HelloString db 'Hello Welcome to Rishis OS', 0 ;Hello This is my OS string
ending with 0
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
BOOTLOADER
Create a first Bootloader that does nothing.
Source Code
[BITS 16] ;tell the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
JMP $ ;infinite loop
TIMES 510 - ($ - $$) db 0 ;fill the rest of sector with 0
DW 0xAA55 ; add boot signature at the end of bootloader.

Create 2nd Bootloader that prints ‘A’ on the screen.


Source Code
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV AL, 65
CALL PrintCharacter
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E ;Tell BIOS that we need to print one character on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is light-grey font on black background
INT 0x10 ;Call video interrupt
RET ;Return to calling procedure
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
Third bootloader implementation: 'Hello World This is My OS'
Bootloader.
Source Code
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV SI, HelloString ;Store string pointer to SI
CALL PrintString ;Call print string procedure
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E ;Tell BIOS that we need to print one character on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is light grey font on black
background
INT 0x10 ;Call video interrupt
RET ;Return to calling procedure
PrintString: ;Procedure to print string on screen
;Assume that string starting pointer is in register SI
next_character: ;Lable to fetch next character from string
MOV AL, [SI] ;Get a byte from string and store in AL register
INC SI ;Increment SI pointer
OR AL, AL ;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL register
JMP next_character ;Fetch next character from string
exit_function: ;End label
RET ;Return from procedure
;Data
HelloString db 'Hello World welcome to My OS', 0 ;HelloWorld This is
my OS string ending with 0
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
21BPS1108
SUMUKH SHARMA
BCSE303P
OPERATING SYSTEMS LAB 4
21/05/2023
Q1. Write programs using the following system calls of UNIX operating system:
fork, getpid, getppid, exit

Algorithm:

1. Start the program, Include header files

2. Check if result of fork is successful

3. if fork() returns a negative value, the creation of a child process was unsuccessful

4. if fork() returns a zero value, the new child process is created

5. A process can use function getpid () to retrieve the process ID assigned to this process.

6. Stop the program

Source Code:-
Q2. Program for wait () system call which makes the parent process wait for the
child to finish.
SOURCE CODE:-
Q3. Demonstrates the creation and termination of a zombie process.
SOURCE CODE:-
Q4. Demonstrates the creation of an orphan process.
SOURCE CODE:-
Q5. Create a file named my file.txt that contains the following four lines: Child 1
reads this line Child 2 reads this line Child 3 reads this line Child 4 reads this
line. Write a C program that forks four other processes. After forking the parent
process goes into wait state and waits for the children to finish their execution.
Each child process reads a line from the file my file.txt (Child 1 reads line 1,
child 2 reads line 2, child 3 reads line 3 and child 4 reads line 4) and each prints
the respective line. The lines can be printed in any order.

SOURCE CODE:-

You might also like