.quad指令如何在汇编中工作? [英] How does the .quad directive work in assembly?

查看:263
本文介绍了.quad指令如何在汇编中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 .quad 函数在汇编中的工作方式.

I'm having trouble understanding how the .quad function works in assembly.

根据我在网上阅读的内容,它会为当前部分中的每个表达式生成一个64位二进制补码值.我了解二进制补码是什么,以及该部分引用 .quad 的那一行的事实.

From what I read online, it generates a 64 bit twos-complement value for each expression into the current section. I understand what twos-complement is and the fact that section is referencing the line that .quad is called to.

通常在汇编中调用 .quad 的位置和时间?
另外,为什么要使用 .quad 生成任何内容?

Where and when is .quad usually called in assembly?
Also, why use .quad to generate anything?

推荐答案

.quad 指令用于定义64位数字值. .byte 指令的工作方式类似.

The .quad directive is used to define 64 bit numeric value(s). In similar way how .byte directive works.

.quad 0x123456789ABCDEF0, 2, 3

将编译为24个字节:

F0 DE BC 9A 78 56 34 12 02 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00

(为了进行比较, .byte 0x12、2、3 将编译为三个字节 12 02 03 ).

(for comparison, .byte 0x12, 2, 3 will compile to three bytes 12 02 03).

.quad通常在哪里和什么时候在汇编中调用?

Where and when is .quad usually called in assembly?

嗯..它是汇编指令,在编译期间使用,它只会产生机器代码.它不能被调用".您可以调用/执行由它定义的机器代码,但这是一种非常少见的使用模式,如果您手边有汇编程序可以通过助记符来生成指令,则可以通过以数字方式将它们定义为操作码来生成指令.

Uhm.. it's assembler directive, used during compilation, it will just produce machine code. It can't be "called". You can call/execute the machine code defined by it, but that's very rare usage pattern, to produce instructions by defining them in numeric way as opcodes, if you have at hand assembler which can produce it from the mnemonics instead.

此外,为什么要使用.quad生成任何东西?

Also, why use .quad to generate anything?

如果要在数据段中设置64b数字1000000000000(1e12),则将其定义为 .quad 1000000000000 比计算单独的字节值并将其定义为 .byte 0、16、165、212、232、0、0、0 ,在 .quad 的情况下,汇编器将为您进行解析并拆分为字节.

If you want to set up 64b number 1000000000000 (1e12) in data segment, it is much more convenient to define it as .quad 1000000000000 than calculating the separate byte values and defining it as .byte 0, 16, 165, 212, 232, 0, 0, 0, in the .quad case the assembler will do the parsing and splitting into bytes for you.

.quad .L3 (摘自评论)

.L3 是代码中的标签,因此它是一些内存地址,所以它是一些64位数字(对于具有平面内存映射的x86 64b目标平台).如果要在内存中的某个位置具有该值,则使用 .quad .L3 是简单的方法,以产生具有该值的8个字节( .L3 标签的地址).

.L3 is label somewhere in the code, so it is some memory address, so it is some 64 bit number (for x86 64b target platforms with flat memory mapping). If you want to have that value somewhere in memory, then using .quad .L3 is simple way how to produce 8 bytes with that value (address of .L3 label).

switch 代码用于间接跳转,选择由开关值索引的内存中的特定值,然后跳转到表中内存中存储的地址.类似于 jmp [table + index * 8] ,当 table + index * 8 指向 .L3 值时,则 jmp将跳到 .L3 地址.

The switch code does it use for indirect jump, selecting particular value in memory indexed by the switch value, and then jumping to the address stored in memory in the table. Something like jmp [table + index*8], when table+index*8 points at .L3 value, then the jmp will jump to .L3 address.

这篇关于.quad指令如何在汇编中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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