0

How can I make my all operating system in one .ASM file? I examined MikeOS and it works with multiply files (like string.asm, screen.asm etc.). How can I work and write codes after boot signature? In MikeOS, I understood that it loads kernel.asm file into memory. Why it loads into memory? Why does not it work in one file?

Example code:

bits 16

org 7c00h

mov si, bootmsg
call ps
call hidecursor

jmp $

bs:
    pusha
    mov al, 8 ;BACKSPACE
    mov ah, 0eh
    int 10h
    mov al, 32 ;SPACE
    mov ah, 0eh
    int 10h
    mov al, 8 ;BACKSPACE
    mov ah, 0eh
    int 10h
    popa
    ret

nl:
    pusha
    mov al, 13
    mov ah, 0eh
    int 10h
    mov al, 10
    mov ah, 0eh
    int 10h
    popa
    ret

ps:
    pusha
    .test:
    lodsb
    cmp al, 0h
    je .eof
    mov ah, 0eh
    int 10h
    jmp .test
    .eof:
    popa
    ret

hidecursor:
    pusha
    mov ah, 1
    mov cx, 2607h
    int 10h
    popa
    ret


showcursor:
    pusha
    mov ah, 1
    mov cx, 0607h
    int 10h
    popa
    ret

bootmsg db 'Hi', 0

times 510 - ($ - $$) db 0
dw 0xaa55
Nafe Bon
  • 33
  • 7
  • It works in one file too. It's for readability and maintainability. Have you programmed in any language yet? You need to load things because the BIOS only loads the first 512 bytes. You can still have everything in a single source file though, it's just not recommended. – Jester Jan 14 '20 at 19:41
  • In Assembly, I could not code after 512 bytes (boot signature). How can I create second sector and resume coding? – Nafe Bon Jan 14 '20 at 19:44
  • Yes you can continue. You'd still have to load it yourself at runtime. – Jester Jan 14 '20 at 19:45
  • I created `shutdown` label and I tryed to `jmp shutdown`. I do not know did it jump or not but it did not execute the command (it did not shutdown). – Nafe Bon Jan 14 '20 at 19:48
  • As I said, you still need code to **load** the rest at runtime because the BIOS only loads the first 512 bytes. It does not matter how many source files you use. – Jester Jan 14 '20 at 19:48
  • How can I load the rest at runtime? I am new to Assembly and OS programming. – Nafe Bon Jan 14 '20 at 19:49
  • Look at other examples such as that MikeOS you mentioned. You need to invoke the [read sectors BIOS function](https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=02h:_Read_Sectors_From_Drive). – Jester Jan 14 '20 at 19:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/205964/discussion-between-nafe-bon-and-jester). – Nafe Bon Jan 14 '20 at 19:58
  • 2
    The code in this answer provides a basic bootloader that loads a second stage starting from the sectors just after the bootloader on disk, reading them into memory right after the first 512 bytes loaded by the BIOS: https://stackoverflow.com/a/54894586/3857942 . This answer also generated a 1.44 MiB disk image that should be usable on emulators as a floppy disk or on USB drive booted with floppy drive emulation. – Michael Petch Jan 15 '20 at 00:11

0 Answers0