intel-syntax

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

百般思念 提交于 2019-12-17 17:12:58
问题 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

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

感情迁移 提交于 2019-12-17 14:53:22
问题 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

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

陌路散爱 提交于 2019-12-17 14:53:08
问题 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

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

帅比萌擦擦* 提交于 2019-12-17 07:38:11
问题 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)? 回答1: This is described in Intel's manual: 3.7.5 Specifying an Offset The offset part of a

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

牧云@^-^@ 提交于 2019-12-17 07:33:56
问题 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); 回答1: 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"); 回答2: This code does what you are trying to achieve. I hope this helps you: #include <stdio.h> int main(void) { /* Compile with C99

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

戏子无情 提交于 2019-12-12 04:13:39
问题 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 loop through a string to count characters

微笑、不失礼 提交于 2019-12-12 03:04:02
问题 i try to make an assembly code that count how many characters is in the string, but i get an error. Code, I use gcc and intel_syntax #include <stdio.h> int main(){ char *s = "aqr b qabxx xryc pqr"; int x; asm volatile ( ".intel_syntax noprefix;" "mov eax, %1;" "xor ebx,ebx;" "loop:" "mov al,[eax];" "or al, al;" "jz print;" "inc ebx;" "jmp loop" "print:" "mov %0, ebx;" ".att_syntax prefix;" : "=r" (x) : "r" (s) : "eax", "ebx" ); printf("Length of string: %d\n", x); return 0; } And i got error:

Interrupt On GAS

送分小仙女□ 提交于 2019-12-11 01:27:06
问题 I'm trying to convert my simple program from Intel syntax to the AT&T(to compile it with GAS). I've successfully converted a big part of my application, but I'm still getting an error with the int (the interrupts). My function is like this: printf: mov $0x0e, %ah mov $0x07, %bl nextchar: lodsb or %al, %al jz return int 10 jmp nextchar return: ret msg db "Welcome To Track!", 0Ah But when I compile it, I got this: hello.S: Assembler messages: hello.S:13: Error: operand size mismatch for int'

Intel x86 to ARM assembly conversion

北战南征 提交于 2019-12-06 04:41:51
问题 I am currently learning ARM assembly language; To do so, I am trying to convert some x86 code (AT&T Syntax) to ARM assembly (Intel Syntax) code. __asm__("movl $0x0804c000, %eax;"); __asm__("mov R0,#0x0804c000"); From this document, I learn that in x86 the Chunk 1 of the heap structure starts from 0x0804c000. But I when I try do the same in arm , I get the following error: /tmp/ccfNZp9F.s:174: Error: invalid constant (804c000) after fixup I am assuming the problem is that ARM can only load

Intel x86 to ARM assembly conversion

戏子无情 提交于 2019-12-04 07:22:32
I am currently learning ARM assembly language; To do so, I am trying to convert some x86 code (AT&T Syntax) to ARM assembly (Intel Syntax) code. __asm__("movl $0x0804c000, %eax;"); __asm__("mov R0,#0x0804c000"); From this document , I learn that in x86 the Chunk 1 of the heap structure starts from 0x0804c000. But I when I try do the same in arm , I get the following error: /tmp/ccfNZp9F.s:174: Error: invalid constant (804c000) after fixup I am assuming the problem is that ARM can only load 32bit instructions. Question 1: Any idea what would be the first chunk in case of ARM processors?