在装配%D&QUOT,10,0,DB&QUOT:intfmt的含义 [英] Meaning of intfmt: db "%d", 10, 0 in assembly

查看:131
本文介绍了在装配%D&QUOT,10,0,DB&QUOT:intfmt的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我看到这个在我的组件文件之一的顶部,并意识到我在打印整数的过程中使用它花了年龄没有真正实现了它来自哪里最初(在我的基本组件,模板中使用),或者什么10 ,0就结束方式:

I recently saw this at the top of one of my assembly files and realised I had spent ages using it in the process of printing integers without actually realising where it came from originally (used in my basic assembly template) or what the 10, 0 on the end means:

section .data
    intfmt: db "%d", 10, 0

谁能打破这和解释不同的组件,特别是2号线的?

Could anyone break this down and explain the different components, specifically of line 2?

我现在想用scanf函数读取输入,似乎这种格式无法正常工作了这一点。想想它的时候我才知道这些数字的意思!

I am now trying to read input using scanf and it seems this format isn't working correctly for this. Think it's about time I learned what the numbers meant!

另外,如果你在阅读中输入的64位体系结构使用scanf的任何想法,我以前没有做过,这是造成我一些问题,所以任何指针,这样做也将是AP preciated!

Also, if you have any ideas about reading in input on a 64bit architecture using scanf, I haven't done it before and it's causing me some problems so any pointers to doing that would also be appreciated!

在此先感谢!

推荐答案

intfmt:是一个标签 - 它可以是任何字符串,但其他的code指吧。

intfmt: is a label -- it could be any string, but other code refers to it.

分贝是定义字节伪指令。相反,组装一台机器code指令,它转储原始字节到code流(在这种情况下.data段)。

db is the "define bytes" pseudo-instruction. Instead of assembling a machine code instruction, it dumps raw bytes into the code stream (.data section in this case).

%D,10,0 是字节转储到流。第一种是ASCII字符串,转储两个字节(字符'%'和'D'), 10 是一个换行符( C语言),而0是一个空字节。

"%d", 10, 0 are the bytes to dump into the stream. The first is an ascii string, which dumps two bytes (the characters '%' and 'd'), 10 is a newline character (\n in C), and 0 is a null byte.

请注意,该字符串是一个原始字符串 - 不NUL终止,并且不支持任何C风格的逃逸(如的换行)。所以,总体来说这将创建一个新行和NUL终止的东西相当于C字符串%D \ N。

Note that the string is a raw string -- NOT nul terminated, and NOT supporting any C style escapes (like \n for newline). So overall this creates something equivalent to the C string "%d\n" with a newline and a NUL terminator.

现在,为什么这个工程的printf和不适合的scanf(为什么切换,如果你删除10)做如何的printf和scanf工作,意味着每个什么换行。

Now as to why this works for printf and not for scanf (and why that switches if you remove the 10) has to do with how printf and scanf work and what a newline means to each.

在printf的,换行打印一个换行符,然后(如果输出是行缓冲模式下,它有可能是),刷新内部输出缓冲区,所以你可以看到的结果。所以,当你删除10,没有冲水,你看不到输出。

In printf, the newline prints a newline and then (if the output is in line buffered mode, which it probably is), flushes the internal output buffer so you can actually see the result. So when you remove the 10, there's no flush and you don't see the output.

在scanf函数,换行的意思是阅读和扔掉的性格,直到你达到一个非空白字符,使该字符作为下一个被读取。所以,如果你正在做一个端子输入scanf函数(例如),换行符将导致其阻塞,直到你的号码后输入一个非空行...

In scanf, the newline means "read and throw away character until you reach a NON-whitespace character", leaving that character as the next to be read. So if you're doing scanf on a terminal input (for example), the newline will cause it to block until you enter a non-blank line after the number...

这篇关于在装配%D&QUOT,10,0,DB&QUOT:intfmt的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆