intel-syntax

Position independent addressing in GNU assembler with Intel syntax

若如初见. 提交于 2019-12-04 04:18:58
问题 On x86-64, how do I load an address from the .data section in a position independent manner (PIC and PIE compatible) when using the GNU assembler with intel syntax . For example, using AT&T syntax, you can do this: leaq mystring(%rip), %rdi Is there an equivalent for Intel syntax? I can't seem to find the answer using search engines... I am actually using the noprefix version of intel syntax, in case that makes a difference. Thanks 回答1: An easy way to answer this is to assemble the

How to know if an assembly code has particular syntax (emu8086, NASM, TASM, …)?

孤人 提交于 2019-12-02 08:49:37
问题 I want to know how,by looking through a sample source code, recognise if the syntax used is em8086, TASM or NASM? I am a new to assembly..I would like to know more about emu8086 please. 回答1: NASM/YASM is easy to distinguish from MASM/TASM/emu8086. YASM uses NASM syntax, with a few minor differences in what it accepts for constants and directives. I don't know how to distinguish MASM from TASM, or TASM from emu8086, or FASM, so I'll leave that for another answer to address. In NASM, explicit

Distinguishing memory from constant in GNU as .intel_syntax

ε祈祈猫儿з 提交于 2019-12-02 06:26:14
问题 I have an instruction written in Intel syntax (using gas as my assembler) that looks like this: mov rdx, msg_size ... msg: .ascii "Hello, world!\n" .set msg_size, . - msg but that mov instruction is being assembled to mov 0xe,%rdx , rather than mov $0xe,%rdx , as I would expect. How should I write the first instruction (or the definition of msg_size ) to get the expected behavior? 回答1: In GAS .intel_syntax noprefix mode: OFFSET symbol works like AT&T $symbol . This is somewhat like MASM.

Assembly (Intel syntax + NASM) Error: attempt to define a local label before any non-local labels

孤人 提交于 2019-12-02 02:31:05
问题 I am quite new regarding the assembly and I am trying to work with a program. So whenever I try to compile it, I get the error for the line, as listed under the comments in the code. I am wondering if anyone has any ideas why NASM detects this errors when I am defining some things for the rest of the assembly code? Maybe it has to do something with how the main is defined? P.S. I listed just the first part of the code, since the program is quite long. Thank you for the help .xlist ;attempt to

Assembly (Intel syntax + NASM) Error: attempt to define a local label before any non-local labels

只谈情不闲聊 提交于 2019-12-01 22:53:59
I am quite new regarding the assembly and I am trying to work with a program. So whenever I try to compile it, I get the error for the line, as listed under the comments in the code. I am wondering if anyone has any ideas why NASM detects this errors when I am defining some things for the rest of the assembly code? Maybe it has to do something with how the main is defined? P.S. I listed just the first part of the code, since the program is quite long. Thank you for the help .xlist ;attempt to define a local label before any non-local labels include stdlib.a ; parser: instruction expected

How to determine if the registers are loaded right to left or vice versa

青春壹個敷衍的年華 提交于 2019-11-28 14:16:14
When reviewing gdb output and looking at the assembly calls, usually I can find a command using hard-coded values to determine whether the registers are being loaded right to left or vice versa. Usually something like the following: sub rsp, 16 or sub 16, rsp But other times, no values like above are visible. All I see are calls like the following : (gdb) disassemble Dump of assembler code for function main: 0x0000000100000f54 <main+4>: mov $rdi,%r15 0x0000000100000f59 <main+9>: mov $rsi,%r14 0x0000000100000f60 <main+16>: mov $rdx,%r13 0x0000000100000f67 <main+23>: mov $ecx,$r12d End of

A couple of questions about [base + index*scale + disp]

谁都会走 提交于 2019-11-28 10:20:57
The general form for memory addressing in Intel and AT&T Syntax is the following: [base + index*scale + disp] disp(base, index, scale) My questions are the following: Can base and index be any register? What values can scale take, is it 1, 2, 4 and 8 (with 1 being the default)? Are index and disp interchangeable (with the only difference being that index is a register while disp is an immediate value)? Michael This is described in Intel's manual: 3.7.5 Specifying an Offset The offset part of a memory address can be specified directly as a static value (called a displacement) or through an

Questions about AT&T x86 Syntax design

a 夏天 提交于 2019-11-27 20:09:43
Can anyone explain to me why every constant in AT&T syntax has a '$' in front of it? Why do all registers have a '%'? Is this just another attempt to get me to do a lot of lame typing? Also, am I the only one that finds: 16(%esp) really counterintuitive compared to [esp+16] ? I know it compiles to the same thing but why would anyone want to type a lot of '$' and '%'s without a need to? - Why did GNU choose this syntax as the default? Another thing, why is every instruction in at&t syntax preceded by an: l? - I do know its for the operand sizes, however why not just let the assembler figure

How do RIP-relative variable references like “[RIP + _a]” in x86-64 GAS Intel-syntax work?

最后都变了- 提交于 2019-11-27 16:18:18
Consider the following variable reference in x64 Intel assembly, where the variable a is declared in the .data section: mov eax, dword ptr [rip + _a] I have trouble understanding how this variable reference works. Since a is a symbol corresponding to the runtime address of the variable (with relocation), how can [rip + _a] dereference the correct memory location of a ? Indeed, rip holds the address of the current instruction, which is a large positive integer, so the addition results in an incorrect address of a ? Conversely, if I use x86 syntax (which is very intuitive): mov eax, dword ptr [

How to set a variable in GCC with Intel syntax inline assembly?

风格不统一 提交于 2019-11-27 04:51:34
Why doesn't this code set temp to 1? How do I actually do that? int temp; __asm__( ".intel_syntax;" "mov %0, eax;" "mov eax, %1;" ".att_syntax;" : : "r"(1), "r"(temp) : "eax"); printf("%d\n", temp); You want temp to be an output, not an input, I think. Try: __asm__( ".intel_syntax;" "mov eax, %1;" "mov %0, eax;" ".att_syntax;" : "=r"(temp) : "r"(1) : "eax"); This code does what you are trying to achieve. I hope this helps you: #include <stdio.h> int main(void) { /* Compile with C99 */ int temp=0; asm ( ".intel_syntax;" "mov %0, 1;" ".att_syntax;" : "=r"(temp) : /* no input*/ ); printf("temp=%d