Search code examples
assemblyx86fasm

FASM x86 msg db new line


I was wondering something. I continued learning some assembly, and I started to understand more of it. Anyways, let's carry on. This is what I've made:

org 100h
; Message 1
mov ah,09
mov dx,msg
int 21h
; Message 2
; LOL
mov ah,09
mov dx,msg2
int 21h
mov ah,08
int 21h
; ENd
int 20h
msg db "hello world!$", 0Dh, 0Ah, 0
msg2 db "made by Josh!$", 0Dh, 0Ah, 0        

However, between msg and msg2, there's no new line. It means, both 'hello world!' and 'made by Josh!' are on the same line. How can I add a new line?

Also, if somebody wants to comment on the code itself, please do it. I am a starter on Assembly and I really want to learn it. Thanks a lot!


Solution

  • For the interrupt you are using -- "AH = 09h - WRITE STRING TO STANDARD OUTPUT" -- the character code $ is the End of String marker, not the binary 0 as you seem to think.

    Put the $ at the very end to solve it:

    msg db "hello world!", 0Dh, 0Ah, "$"
    

    There is no need for the 0 byte here, so better leave it out for clarity.

    Is this all your code? It seems you are missing an End of Program interrupt:

    mov ah, 4Ch
    mov al, 0
    int 21h
    

    (AH = 4Ch - "EXIT" - TERMINATE WITH RETURN CODE)