db usage in nasm, try to store and print string

前端 未结 1 365
野性不改
野性不改 2020-12-07 06:19

I was trying to store a few strings in my assembly, and use WriteString to print out on the screen. However, I only call one of the strings, it shows up all of them in one s

相关标签:
1条回答
  • 2020-12-07 07:24

    The strings have to be null terminated -- you have to indicate the zero value for the last byte. You may also need to indicate carriage returns and line feeds if you want the output routine to put the string on it's own line.

    You do this by specifying:

    nullstr db 0
    errorMessage db 'critical error', 10, 13, 0
    warningMessage db 'warning', 10, 13, 0
    
    goodbyeWorld1 db 'Goodbye World.', 0
    goodbyeWorld2 db 'Goodbye World.'
    
    endline db 10, 13, 0
    

    The endline string would work on the principle that since goodbyeWorld2 is not null terminated, it would display the ascii codes for carriage feed and line return, so Goodbye World. would appear on it's own line in the shell output. However since goodByeWorld1 is null-terminated it would not appear on it's own line and output would continue at the final '.' character displayed.

    0 讨论(0)
提交回复
热议问题