且构网

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

汇编:printf不打印新行

更新时间:2023-12-03 17:45:46

NASM 中对字符串使用双引号或双引号时,它不接受 C 样式转义序列.在Linux上,您可以像这样将\n编码为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 \n 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 \n`, 0

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

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

3.4.2字符串

3.4.2 Character Strings

一个字符串由最多八个字符组成,这些字符包含在单引号('...'),双引号("...")或反引号(...)中.单引号或双引号等效于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.