How do you print a newline character in BIOS-level assembly?

Safal Aryal

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 nop instructions in the code at the moment). Rather, I would like to ask about why my newline character 0xA 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.

the output

Here is my 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
William Leara

It looks to me like the newline (0xa) is doing exactly what I would expect--printing a newline. However, you didn't also print a carriage return (0xd), so therefore your next sentence starts in the middle of the screen. Add a carriage return and you should get the result you're looking for.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you print \ in python

How do you remove the first character of a string?

How do I print output without a trailing newline in Rust?

How do I print a bullet character to the console?

How to print out a newline character in a string in Awk

JQ how to print newline and not newline character from json value

How do objects work in x86 at the assembly level?

How do you compare variable types in assembly?

How do you insert a newline character within the RegularExpressionValidator ErrorMessage Field?

Reading Input in BIOS-Level Assembly?

Print Newline for Armv7 assembly program

How do you paste into current line without newline

How do you represent this character in python? 

How to print an string without the newline Mips Assembly language

How do you scan for a single character in C?

How do I print backslash followed by newline with printf?

Assembly - Print Character

How do you insert a newline after every 80 characters in vim?

How do you conditionally check for an escape character?

Cannot print newline with newline character in a string

How do you find the index of a character in a string?

When piping stdout into Perl, how to get it to print a newline character?

How do you keep scanner.next() from including newline?

How do computer programs manage to have consistent speed at the assembly level?

How do I use sed to append a character to a line without a newline?

How do you escape the ~ character in a Batch script?

Macros to read and print a character in assembly

How do you add a newline to the end of a string in C?

How do I print the pipe character in awk