gas

How to create a GNU GAS macro that expands to an expression like “(x+y*240)*2”?

孤者浪人 提交于 2019-12-07 07:47:49
问题 I'm building a program for ARM Linux using GAS, but I want to do some macros to make my development some more smart. Then I want to know: How could I do a macro for this: (x+y*240)*2 , were x and y are int , that will be used like this: mov r0, MACRO_SHOULD_BE_CALLED_HERE And how could I do a macro that should be called like this: JUST_MACRO_CALLED_HERE_TO_DO_SOMETHING That will just do something that is already defined inside it, like a print function for example. Also, if I need some

How many byes is each instruction compiled to in x86 assembly?

百般思念 提交于 2019-12-07 01:32:30
问题 0x004012d0 <main+0>: push %ebp 0x004012d1 <main+1>: mov %esp,%ebp 0x004012d3 <main+3>: sub $0x28,%esp If the address is not available , can we calculate it ourselves? I mean we only have this: push %ebp mov %esp,%ebp sub $0x28,%esp 回答1: amount of bytes is difference of addresses between adjacent instructions: 0x004012d0 <main+0>: push %ebp ;1 byte 0x004012d1 <main+1>: mov %esp,%ebp ;2 bytes 0x004012d3 <main+3>: sub $0x28,%esp if you have only text then go here: http://www.swansontec.com

GNU assembler did not produce a program that I can execute

末鹿安然 提交于 2019-12-06 11:52:34
I tried assembling some intermediate code generated by gcc. I used the command as -o hello hello.s , which, as far as I can tell, is the correct syntax. When I tried to run the program, it said bash: ./hello: cannot execute binary file . It doesn't seem like there's a problem with the assembly code, since it was the code generated by gcc, and it doesn't seem like there's anything wrong with how I invoked the assembler, since that seems to be the right syntax according to this manual . Can anyone help me with this? Working with GNU Assembler Assume that your assembly file is called hello.s and

ARM/Thumb code for firmware patches…How to tell gcc assembler / linker to BL to absolute addr?

北城余情 提交于 2019-12-06 07:47:55
I'm trying to write a firmware mod (to existing firmware, for which i don't have source code) All Thumb code. does anybody have any idea how to do this, in gcc as (GAS) assembler: Use BL without having to manually calculate offsets, when BL 'ing to some existing function (not in my code.. but i know its address) Currently, if i want to use BL ...i have to : -go back in my code -figure out and add all the bytes that would result from assembling all the previous instructions in the function i'm writing -add the begining address of my function to that (i specify the starting address of what i'm

how to export a function in GAS assembler?

醉酒当歌 提交于 2019-12-06 06:13:50
Hi I have the following assembly code , .export __ls__11NSDOM_EncapFf .text __ls__11NSDOM_EncapFf: /* first load the symbolic constant*/ movq _IEEE_FP@GOTPCREL(%rip), %r8 /*%r8 is a scratch register*/ movq (%r8), %r9 /* %r9 and %r11 are scratch registers*/ movl (%r9), %r11d /* second, see if it is zero and branch accordingly */ test %r11d, %r11d /* zero call TNS procedure */ /* non-zero call IEEE procedure */ je ____ls__11NSDOM_EncapFf_tns/* constant equals 0 */ jmp ____ls__11NSDOM_EncapFf_ieee/* constant not equal to 0 */ ret I compile the .s file to .o file(compilation is fine) , but when I

Why is this simple c program with gcc (clang) inline assembly exhibiting undefined behaviour?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 05:47:59
I'm trying to do a very simple thing with gcc assembler extension: load an unsigned int variable into a register add 1 to it output the result While compiling my solution: #include <stdio.h> #define inf_int volatile unsigned long long int main(int argc, char *argv[]){ inf_int zero = 0; inf_int one = 1; inf_int infinity = ~0; printf("value of zero, one, infinity = %llu, %llu, %llu\n", zero, one, infinity); __asm__ volatile ( "addq $1, %0" : "=r" (infinity) ); __asm__ volatile ( "addq $1, %0" : "=r" (zero) ); __asm__ volatile ( "addq $1, %0" : "=r" (one) ); printf("value of zero, one, infinity =

Calling C function from x64 assembly with registers instead of stack

旧时模样 提交于 2019-12-06 04:08:39
This answer puzzled me. According to the standard C calling conventions , the standard way to call C functions is to push arguments to the stack and to call the subroutine. That is clearly different from syscalls , where you set different registers with appropriate arguments and then syscall . However, the answer mentioned above gives this GAS code: .global main .section .data hello: .asciz "Hello\n" .section .text main: movq $hello, %rdi movq $0, %rax call printf movq $0, %rax ret which works with gcc hello.s -o hello . The part that calls printf is: movq $hello, %rdi movq $0, %rax call

ARM64 using gas on iOS?

有些话、适合烂在心里 提交于 2019-12-05 19:10:24
I've got some assembly functions I've ported to 64-bit ARM, and they work fine on Android, but when I tried to compile the same files in Xcode, I discovered that clang uses a different syntax (different from the official ARM documentation). I've found some scripts which convert a source file from one format to the other, but this is not the ideal solution (and it seems these scripts don't work when the source files contain preprocessor defines). Can I simply use gas in Xcode, or configure clang to accept the gas syntax? If not, where is the clang assembler documentation? UPDATE - September

What does 0x4 do in “movl $0x2d, 0x4(%esp)”?

♀尐吖头ヾ 提交于 2019-12-05 17:36:29
问题 I am looking into assembly code generated by GCC. But I don't understand: movl $0x2d, 0x4(%esp) In the second operand, what does 0x4 stands for? offset address? And what the use of register EAX? 回答1: movl $0x2d, 0x4(%esp) means to take the current value of the stack pointer ( %esp ), add 4 ( 0x4 ) then store the long (32-bit) value 0x2d into that location. The eax register is one of the general purpose 32-bit registers. x86 architecture specifies the following 32-bit registers: eax

Understanding Base Pointer and Stack Pointers: In Context with gcc Output

安稳与你 提交于 2019-12-05 16:23:38
问题 I have the following C program: int main() { int c[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2}; return c[0]; } and when compiled using the -S directive with gcc I get the following assembly: .file "array.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $0, -48(%rbp) movl $0, -44(%rbp) movl $0, -40(%rbp) movl $0, -36(%rbp) movl $0, -32(%rbp) movl $0, -28(%rbp) movl $0, -24(%rbp)