gas

Accessing global variable defined in C from Asm

有些话、适合烂在心里 提交于 2019-12-20 02:27:15
问题 I have a C file which contain a global variable foo. How I can access foo from another assemby program. I am using i586-elf-as (GNU assembler) and i586-elf-gcc (gnu compiler) for building. 回答1: You can just use the symbol name; as treats all undefined symbols as external. Check compiler output ( gcc -S ) and/or documentation to find out if C variable names get a leading _ prepended or not. ( int myglobal becomes asm _myglobal on many non-ELF platforms, but still myglobal on Linux/ELF.) And of

How can I jump relative to the PC using the gnu assembler for AVR?

烂漫一生 提交于 2019-12-19 10:21:07
问题 I have a binary file that I've disassembled using avr-objcopy. The interrupt vector table looks like: 00000000 : ; VECTOR TABLE 0: 13 c0 rjmp .+38 ; 0x28, RESET 2: b8 c1 rjmp .+880 ; 0x374, INT0 4: fd cf rjmp .-6 ; 0x0 6: fc cf rjmp .-8 ; 0x0 8: fb cf rjmp .-10 ; 0x0 a: fa cf rjmp .-12 ; 0x0 c: f9 cf rjmp .-14 ; 0x0 e: f8 cf rjmp .-16 ; 0x0 10: f7 cf rjmp .-18 ; 0x0 12: c7 c1 rjmp .+910 ; 0x3a2, TIMER1 OVF 14: f5 cf rjmp .-22 ; 0x0 16: f4 cf rjmp .-24 ; 0x0 18: f3 cf rjmp .-26 ; 0x0 1a: f2 cf

ARM64 using gas on iOS?

放肆的年华 提交于 2019-12-19 09:44:27
问题 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

How to create a statically linked position independent executable ELF in Linux?

坚强是说给别人听的谎言 提交于 2019-12-18 08:58:40
问题 I have a working position independent Linux freestanding x86_64 hello world: main.S .text .global _start _start: asm_main_after_prologue: /* Write */ mov $1, %rax /* syscall number */ mov $1, %rdi /* stdout */ lea msg(%rip), %rsi /* buffer */ mov $len, %rdx /* len */ syscall /* Exit */ mov $60, %rax /* syscall number */ mov $0, %rdi /* exit status */ syscall msg: .ascii "hello\n" len = . - msg which I can assemble and run with: as -o main.o main.S ld -o main.out main.o ./main.out Since it is

Assembly - How to multiply/divide a constant by another constant in assembly?

放肆的年华 提交于 2019-12-17 22:04:12
问题 So, I have an assembly function, which is called in C. It compiles and gives me no warnings, but when I try to run it, it gives me a segmentation fault. I think it's because I can't move a constant into a register, but to use the mul/div command it requires a value to be in EAX register. How can I multiply or divide two constants in Assembly? Here's the code so far... .section .data .global n .equ A, 50 .equ B, 5 .section .text .global loop_function loop_function: # prologue pushl %ebp # save

Is it possible to create threads without system calls in Linux x86 GAS assembly?

佐手、 提交于 2019-12-17 17:27:26
问题 Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using system calls. These system calls come in very handy and are sometimes even necessary as your program runs in user-space. However system calls are rather expensive in terms of performance as they require an interrupt (and of course a system call) which means that a context switch must be made from your current active program in user-space to

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

gas: too many memory reference

冷暖自知 提交于 2019-12-17 09:59:55
问题 When compiling the following instruction: movl 4(%ebp), 8(%ebp) I got: too many memory reference . What's wrong with it? 回答1: The number before the parenthesis is a byte offset (which causes a memory reference to occur), and you cannot have two of them with movl . You need to move the value temporarily to a register first. movl 4(%ebp), %ecx movl %ecx, 8(%ebp) 回答2: It is not a legal instruction. For most instructions that reference memory you must move it to/from a register. 回答3: movl doesn't

What are CFI directives in Gnu Assembler (GAS) used for?

本小妞迷上赌 提交于 2019-12-17 05:32:27
问题 There seem to be a .CFI directive after every line and also there are wide varities of these ex., .cfi_startproc , .cfi_endproc etc.. more here. .file "temp.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 movl $0, %eax leave ret .cfi_endproc .LFE0: .size main, .-main .globl func .type func, @function func: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp