Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few problems.</p> <p>First, you don't properly set the registers for function 0Ah. You have to set <code>bh</code> to the page number (0), and <code>cx</code> to the repeat count (1).</p> <p>Second, this BIOS function doesn't advance the cursor position and all characters get printed into the same location on the screen, overwriting each other, which should lead to only '!' visible since it's the last character.</p> <p>I advise to use function 0Eh instead.</p> <p>Third, you don't initialize the direction flag (<code>flags.df</code>) which <code>lodsb</code> relies upon. You should use <code>cld</code> to reset <code>df</code>.</p> <p>Fourth, I don't see all the code, but you should use the proper <code>org</code> directive to generate correct offsets for instructions and data.</p> <p>Also, <code>NMIs</code> and <code>SMIs</code> will cause <code>hlt</code> completion and the code that follows will execute (and what follows is your <code>Print</code>). You want to execute <code>hlt</code> in a loop.</p> <p>With these fixes we arrive at:</p> <pre><code>bits 16 org 1 jmp Start ;data fields msg db "Hello World!",0 Start: mov ax, cs mov ds, ax ; set data segment pointer cld mov si, msg ; load message to SI register call Print cli .halt: hlt ; halt the system jmp .halt Print: .PrintLoop: lodsb ; load byte from SI register or al, al ; check if 0 byte jz short .PrintDone ; if so - stop ; mov ah, 0Ah ; function - print text to cursor ; xor bh, bh ; mov cx, 1 mov ah, 0Eh ; function - print text tty int 0x10 ; BIOS interrupt jmp .PrintLoop ; continue with next char .PrintDone: ret </code></pre> <p>The binary which you get by compiling the above with <code>nasm blah.asm -f bin -o blah.bin</code> should then be loaded at <code>0x7e0:0001</code> and jumped to with <code>jmp 0x7e0:0001</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload