Write Your OWN OPERATING SYSTEM TUTORALIAL

zhaozj2021-02-08  245

Lesson 4: Hello, World

You wait for a long time. Writing our "first" program is time. Every similar program design book will have a "Hello, World" program, now we understand enough, you can write a "Hello, World" operating system. If you have done this step, you can skip this lesson. We will create a function of output strings and use it to display our messages.

Print a character at a time, it is enough. So we have to write a function to print a string of zero end. This will be a loop, print a character each time until the end.

; ---------------------------------------------

PRINT A NULL-TERMINATED STRING ON THE Screen

; ---------------------------------------------

Putstr:

Lodsb;

Al

= [DS: Si]

OR Al, Al; Set Zero Flag IF AL = 0

Jz PutStrd; Jump to Putstrd if Zero Flag is set

MOV AH, 0x0E; Video Function 0EH (Print Char)

MOV BX, 0x0007; Color

INT 0x10

JMP Putstr

Putstrd:

Retn

Now explain this function's usage. First you need to load the address of the first character of the string to Si. Then just call this PUTSTR.

You can create a string as shown below in your program.

MSG DB 'Hello, World!', 0

The last 0 is used to mark the end of this string. Next you can output the string with the following instructions.

MOV Si, MSG; Load Address of Message

Call Putstr; Print The Message

Distance can use only one job. The address of the MSG loaded in the SI register is actually represented by the offset of the first address of the data segment, which is stored by the register DS. So before you can use the MSG address, you must set the current data segment. In terms of now, we will use the flat addressing from the start of the physical memory low address. In order to set the data segment to the start portion of the bottom, the DS can be set to zero. The following two instructions complete this.

XOR AX, AX; ZERO OUT AX

MOV DS, AX; SET DATA Segment to Base of Ram

Try to bind the above code into the H.ASM of Lesson 3. Then use the methods described in the third lesson, compile, copy to floppy disk, start. Then, enjoy it. If you have difficulty, you can look at my method, Helowrld.asm. But only you have tried it yourself, you can taste the happiness between it.

If you have done it, please continue to the next lesson, we will learn interactivity to our operating system.

转载请注明原文地址:https://www.9cbs.com/read-2803.html

New Post(0)