Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [bits 16] ;Tell nasm that this code should be written in 16 bits !
- [org 0x7c00] ;Tell BIOS where our boot sector should be loaded (the boot sector lays in between the adresses starting from 0x7c00 to 0x7e00)
- mov bp, 0x9000 ;Place the start of the stack very far away from BIOS files so that we don't overwrite them
- mov sp, bp ;Same thing here
- mov bx, msg ;Using the register bx as an argument to our print_string function. We put the value of msg in bx
- call print_string ;Call our function for printing strings
- jmp $ ;Jump to the current adress AKA hanging in one place
- print_string: ;Start of our print string function
- pusha ;Push all registers to the stack
- char_loop: ;In this function, we loop through every byte in bx and print it, ending when there are no bytes left
- mov al, [bx] ;Move the next byte into al
- cmp al, 0 ;Check if there is a byte
- jne char_print ;If there is, we print the char
- popa ;If there isn't, we retrieve all registers from the stack
- ret ;And return to our main loop
- char_print: ;Printing individual chars
- mov ah, 0x0e ;Enabling BIOS Tele-type mode
- int 0x10 ;Calling BIOS interupt for printing to screen, equvialent to, in python: 'print(al)'; Interupts are special functions in lower-level programming which when called stop all processes on the pc, do what they must do and let the pc continue it's work
- add bx, 1 ;Moving to the next adress AKA next char in bx
- jmp char_loop ;Going back to the char loop
- msg: db 'Hello world!', 0 ;Making a variable called 'msg' that holds databytes given to it by the db(declare byte(s)). In it's current state it's a char, not a string, so we have to tell the router when to stop printing, which we do witj the ', 0'
- times 510-($-$$) db 0 ;Pad the file with zeros 510 times !
- dw 0xaa55 ;The last two bytes tell BIOS that this is a boot sector and that it should boot it !
- ;All lines that have a '!' at the end of their comments are only read by the assembler and are deleted while assembling.
Advertisement
Advertisement