title: How do you print a newline character in BIOS-level assembly?
body: <p>I am trying to write a bootloader on my own using the NASM Assembler. I am trying to print two lines of text, wait for a keypress, and reboot if the key pressed is 'r' and continue booting if the key pressed is 'b'. However, that is not the subject of my question (I will implement those functions later, hence the <code>nop</code> instructions in the code at the moment). Rather, I would like to ask about why my newline character <code>0xA</code> prints in such a strange way? I have done all three items in my TODO at one point, but I think this is important as the loader must not look bad. <br><br> <a href="https://i.stack.imgur.com/4XLB7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4XLB7.png" alt="the output"></a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>BITS 16     ; tell nasm we're working in 16 bit real mode
  
  start:          ; entry symbol for the os          
  
          mov ax, 0x07C0          ; 4 kilobyte stack space set up
          add ax, 288             ; (4096+512) / 16 bytes per paragraph
          mov ss, ax              
          mov sp, 4096
  
          mov ax, 0x07C0          ; set data segment to where we've loaded
          mov ds, ax
  
          mov si, text_string     ; put our string position into SI
          call write_string       ; call our string-printing function
          mov si, text_string_tutorial
  
          cli                     ; jump here for an infinite loop
          hlt
  
          text_string db 'Mao Mao Loader 0.01 written by Safal Aryal', 0xA
          text_string_tutorial db 'Press r to reboot or b to continue booting', 0x9
  
  
  write_string:                   ; output string located in si
      mov ah, 0xE                 ; the 'print char' function of int 0x10
  .repeat:                
      lodsb                       ; get character from the string
      cmp al, 0                   ; check if it is zero   
      je .done                    ; if it is, jump to .done and finish the function
      int 10h                     ; call interrupt 10h    
      jmp .repeat                 ; repeat for every char in the string
  .done:                  
      ret
  
  read_input:
      mov ah, 0x00
      int 16h
      cmp al, 'r'
      nop
      cmp al, 'b'
      nop
  
      times 510-($-$$) db 0       ; pad boot sector with zeroes
      dw 0xAA55                   ; standard bootsig
  
  ;TODO: read key pressed, change background colour and start writing kernel
  </code></pre>