Search code examples
assemblynasmqemureal-mode

My assembly code for printing string works on QEMU, but not on real hardwares


I want to make an OS, but it works only in a way, Cosmos C# make me a bunch of errors for only an iso, where is the error here?

[bits 16]
[org 0x7c00]

start:
    mov si, msg
    call printer
    jmp $

printer:
    mov ah, 0x0E
.prntloop:
    lodsb
    or al,al
    jz .done
    int 10h
    jmp .prntloop
.done:
    ret

msg db "Hello World!", 0

times 510-($-$$) db 0
dw 0xaa55

I'm using NASM as a compiler. Thanks.

I've tried this on my real hardware, such as an laptop, the thing that happens when booted finally is that teleports cursor and then casually beeps


Solution

  • You need to initialize the 'DS' register. It is not required to initialize with a BPB (BIOS Parameter Block) with your code either on virtual machine or hardware. I noticed you originated the code to [ORG 0x7C00] I would still set your DS register, regardless, to 0x7C00 (segmented of course 0x07C0).