gas

segmentation fault when assigning value of an array to eax (AT&T syntax)

点点圈 提交于 2020-01-23 10:20:08
问题 I'm just trying to load the value of myarray[0] to eax : .text .data # define an array of 3 words array_words: .word 1, 2, 3 .globl main main: # assign array_words[0] to eax mov $0, %edi lea array_words(,%edi,4), %eax But when I run this, I keep getting seg fault. Could someone please point out what I did wrong here? 回答1: It seems the label main is in the .data section. It should lead to segmentation fault if the system doesn't allow to execute codes in .data section. Program code should be

get string length in inline GNU Assembler

风流意气都作罢 提交于 2020-01-18 17:55:06
问题 I am re-learning assembler which I used on very old MS-DOS machines!!! This is my understanding of what that function should look like. It compiles but crashes with a SIGSEGV when trying to put 0xffffffff in ecx . The code is run in a VM with 32-bit Debian 9. Any help would be appreciated. int getStringLength(const char *pStr){ int len = 0; char *Ptr = pStr; __asm__ ( "movl %1, %%edi\n\t" "xor %%al, %%al\n\t" "movl 0xffffffff, %%ecx\n\t" "repne scasb\n\t" "subl %%ecx,%%eax\n\t" "movl %%eax,%0

Error Raised When Attempting to Assign Value At Index of Array With x86 Assembly GNU GAS

倾然丶 夕夏残阳落幕 提交于 2020-01-15 03:46:33
问题 I am using x86 GNU assembly with GCC and am attempting to implement the Assembly equivalent of the following c/c++ : int x[10]; x[0] = 5; However, when I attempt to run (with command ./a.out ) my Assembly code below (after first compiling with the gcc filename.s ), the error Segmentation fault: 11 is printed to the console: .data x:.fill 10 index:.int 0 .text .globl _main _main: pushq %rbp movq %rsp, %rbp subq $16, %rsp lea x(%rip), %rdi mov index(%rip), %rsi; movl $5, %eax; movl %eax, (%rdi,

Translation from NASM to GAS

时间秒杀一切 提交于 2020-01-07 03:10:12
问题 how do I translate mov [ebx], al from NASM to GAS? I tried mov %al, (%ebx) but it does segmentatiob fault. Another question, lets say I have an array in GAS .lcomm array, 50 Do I have to put a dollar($) sign in array like this: mov %rbx, $array or need not to? Any answer would be helpful :) 回答1: How about intel2gas? usage: intel2gas [options] [-o outfile] [infile] where options include: -h this help -i convert from intel to at&t format (default) -g convert from at&t to intel format -m -t

Simple input to output program in Assembly

南笙酒味 提交于 2020-01-05 05:00:26
问题 So, I'm new to learning Assembly and am very confused on how the memory works in Assembly etc. I got the following code: .global main .text format_input: .asciz "%ld" main: subq $8, %rsp leaq -8(%rbp), %rsi movq $format_input, %rdi movq $0, %rax call scanf movq %rsp, %rdi call printf end: movq $0, %rax call exit What I wanted to do here is to input a number and output the same number. But here, I'm already having a problem. If I input a number , I get a Segmentation fault . If I input one

Getting address of data variable in x86 AT&T Assembly

旧街凉风 提交于 2020-01-05 03:32:13
问题 Possible duplicate exist, but I couldnt figure out how to apply this or othere solutions to similar problems so here I am. I am creating a function that returns and integer as a string in x86 AT&T Assembly. I have this code to declare the variable resdes . .data .align 4 resdes: .long 12 resdes now points to a memory location followed by 11 other bytes free for me to use (I have understood this correctly?). I want to load one digit at a time from the integer into the bytes one by one. this is

Why doesn't the GCC assembly output generate a .GLOBAL for printf

时光总嘲笑我的痴心妄想 提交于 2020-01-04 04:09:29
问题 I have a trivial example C program:- #include <stdio.h> int main() { printf("hello world!"); return 1; } I use the following command to compile it and generate assembly:- riscv32-unknown-elf-gcc -S hello.c -o hello.asm Which generates the following assembly: - .file "hello.c" .option nopic .section .rodata .align 2 .LC0: .string "hello world!" .text .align 2 .globl main .type main, @function main: addi sp,sp,-16 sw ra,12(sp) sw s0,8(sp) addi s0,sp,16 lui a5,%hi(.LC0) addi a0,a5,%lo(.LC0) call

gnu arm assembler command line macro fails with “Invalid identifier for .ifdef”

牧云@^-^@ 提交于 2020-01-01 09:36:05
问题 My toolchain is a recent version of arm-gcc. I have a piece of code in an assembly file which must be conditionally included/assembled. .ifdef MACRO_FROM_CMDLINE Assembly instr1 Assembly instr2 .endif Encapsulated code is a recent addition. I have tried both: gcc -x assembler-with-cpp --defsym MACRO_FROM_CMDLINE=1 <along with other necessary options> gcc -x assembler-with-cpp -D MACRO_FROM_CMDLINE=1 <along with other necessary options> The -D results in "Invalid identifier for .ifdef " and "

How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? [duplicate]

 ̄綄美尐妖づ 提交于 2020-01-01 05:40:11
问题 This question already has answers here : How to generate plain binaries like nasm -f bin with the GNU GAS assembler? (2 answers) Closed 6 months ago . I want to compile this source code in Windows (It just an example): start: NOP NOP When I compile it with NASM or FASM, output file length is 2 bytes. But when I compile it with GNU assembler (as) the output file length is 292 bytes! How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? Why I do this? I

Assembling with GCC causes weird relocation error with regards to .data

纵然是瞬间 提交于 2019-12-30 10:35:58
问题 This is an issue that didn't used to ever occur. I'm pretty convinced it's probably an issue with my package repos (I recently reinstalled my Arch system and this has only just started happening). I wrote a small hello world in x86_64: .data str: .asciz "Test" .text .globl main main: sub $8, %rsp mov $str, %rdi call puts add $8, %rsp ret and then I attempt to assembly and link using GCC - like I have done many times in the past - with, simply: gcc test.s -o test and then this error is