且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

程序集:printf 不打印新行

更新时间:2023-12-03 17:41:10

当您在 NASM 中使用引号或双引号将字符串括起来时,它不接受 C样式转义序列.在 Linux 上,您可以像这样将 编码为 ASCII 10:

When you use quotes or double quotes around a string in NASM, it doesn't accept C style escape sequences. On Linux you can encode as ASCII 10 like this:

fmt db "Number of parameters: %d", 10, 0 

还有一个选择.NASM 支持反引号(反引号),这将允许 NASM 将它们之间的字符处理为 C 样式的转义序列.这也应该有效:

There is an alternative. NASM supports backquotes (backticks) which will allow NASM to process the characters between them as C style escape sequences. This should work as well:

fmt db `Number of parameters: %d 
`, 0

请注意:这些不是单引号,而是反引号.这在 NASM 文档中有描述:

Please note: Those are not single quotes, but backticks. This is described in the NASM documentation:

3.4.2 字符串

一个字符串最多由八个字符组成,用单引号 ('...')、双引号 ("...") 或反引号 (...) 括起来.单引号或双引号等价于 NASM(当然,用单引号包围常量允许其中出现双引号,反之亦然);这些内容是逐字表示的.用反引号括起来的字符串支持 C 风格的特殊字符转义.

A character string consists of up to eight characters enclosed in either single quotes ('...'), double quotes ("...") or backquotes (...). Single or double quotes are equivalent to NASM (except of course that surrounding the constant with single quotes allows double quotes to appear within it and vice versa); the contents of those are represented verbatim. Strings enclosed in backquotes support C-style -escapes for special characters.