gas

Error “no such instruction” while assembling project on Mac OS X

和自甴很熟 提交于 2019-11-27 05:43:25
问题 I used homebrew to install GCC 4.7.0 and my project's make is failing at assembly-time. I can successfully take code from .c -> .s, but .s -> .o fails. To view the brew formula used to install GCC, please look at: https://github.com/Homebrew/homebrew-dupes/blob/master/gcc.rb . I also installed binutils from upstream using https://github.com/mxcl/homebrew/blob/master/Library/Formula/binutils.rb . Install binutils does not appear to introduce a new 'as' in the /usr/local/lib or similar. How can

What is the use of .byte assembler directive in gnu assembly?

可紊 提交于 2019-11-27 03:22:38
问题 While going through some C code having inline assembly I came across the .byte (with a Dot at the beginning) directive. On checking the assembly reference on web I found that it is used to reserve a byte in memory. But in the code there was no label before the statement. So I was wondering what is use of an unlabeled .byte directive or any other data storage directive for that matter. For e.g. if i code .byte 0x0a , how can i use it ? 回答1: There are a few possibilities... here are a couple I

x86_64 Assembly Linux System Call Confusion

≯℡__Kan透↙ 提交于 2019-11-27 02:16:36
问题 I am currently learning Assembly language on Linux. I have been using the book 'Programming From the Ground Up' and all the examples are 32-bit. My OS is 64-bit and I have been trying to do all the examples in 64-bit. I am having trouble however: .section .data .section .text .global _start _start: movq $60, %rax movq $2, %rbx int $0x80 This merely just calls the Linux exit System call or it should. Instead it causes a SEG FAULT and when I instead do this .section .data .section .text .global

What is register %eiz?

不打扰是莪最后的温柔 提交于 2019-11-27 00:50:24
问题 In the following assembly code that I dumped out using objdump : lea 0x0(%esi,%eiz,1),%esi What is register %eiz ? What does the preceding code mean? 回答1: See Why Does GCC LEA EIZ?: Apparently %eiz is a pseudo-register that just evaluates to zero at all times (like r0 on MIPS). ... I eventually found a mailing list post by binutils guru Ian Lance Taylor that reveals the answer. Sometimes GCC inserts NOP instructions into the code stream to ensure proper alignment and stuff like that. The NOP

How to generate a nasm compilable assembly code from c source code on Linux?

自作多情 提交于 2019-11-27 00:02:27
问题 Test platform is 32 bit Linux. Basically, I know gcc can be used to generate both Intel and At&T style assembly code, but it seems that you can not directly use nasm/tasm to compile the Intel style assembly code gcc generated. I am conducting a project analysis asm code on both windows and Linux platform, so I am thinking if they can be both compiled by platform independent assembler like nasm\yasm, I could have a much easier time... So my question is how to generate a nasm compilable

How do GNU assembler x86 instruction suffixes like “.s” in “mov.s” work?

这一生的挚爱 提交于 2019-11-26 22:04:41
问题 GNU assembler appears to have some means of controlling the alternative forms of the opcode being emitted for some instructions. E.g. .intel_syntax noprefix mov eax, ecx mov.s eax, ecx Processing the above code with as test.s -o test.o && objdump -d test.o -M intel gives the following disassembly: 0: 89 c8 mov eax,ecx 2: 8b c1 mov eax,ecx We can see that .s suffix appears to switch 89 opcode to the 8b version (and appropriately change the ModRM byte). How does this syntax work in GAS? I can't

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

家住魔仙堡 提交于 2019-11-26 21:21:32
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 .cfi_offset 6, -16 .cfi_def_cfa_register 6 movl %edi, -4(%rbp) movl %esi, %eax movb %al, -8(%rbp) leave

How to use RIP Relative Addressing in a 64-bit assembly program?

拈花ヽ惹草 提交于 2019-11-26 20:29:28
How do I use RIP Relative Addressing in a Linux assembly program for the AMD64 archtitecture? I am looking for a simple example (a Hello world program) that uses the AMD64 RIP relative adressing mode. For example the following 64-bit assembly program would work with normal (absolute addressing): .text .global _start _start: mov $0xd, %rdx mov $msg, %rsi pushq $0x1 pop %rax mov %rax, %rdi syscall xor %rdi, %rdi pushq $0x3c pop %rax syscall .data msg: .ascii "Hello world!\n" I am guessing that the same program using RIP Relative Addressing would be something like: .text .global _start _start:

How to generate plain binaries like nasm -f bin with the GNU GAS assembler?

不想你离开。 提交于 2019-11-26 20:26:35
I have some NASM files that generally have the structure: [BITS 64] [ORG 0x0000000000200000] start: ... ret I'm assembling them like so: nasm -f bin abc.asm I'd like to write some of these using GAS instead. Two questions: What directives should I use in GAS? I've found the '.org' directive but GAS doesn't seem to have a '.bits' directive. What should I pass to gcc or as to generate a plain binary file? I.e. what the -f bin option does with NASM. What directives should I use in GAS? I've found the '.org' directive but GAS doesn't seem to have a '.bits' directive. The assembler defaults to 64-

What does cltq do in assembly?

你。 提交于 2019-11-26 19:06:07
0x0000000000400553 <main+59>: mov -0x4(%rbp),%eax 0x0000000000400556 <main+62>: cltq 0x0000000000400558 <main+64>: shl $0x3,%rax 0x000000000040055c <main+68>: mov %rax,%rdx In fact my programe is as simple as : 5 int main(int argc, char *argv[]) { 6 int i = 0; 7 while(environ[i]) { 8 printf("%s\n", environ[i++]); 9 } 10 return 0; But the assembly output is pretty long: Dump of assembler code for function main: 0x0000000000400518 <main+0>: push %rbp 0x0000000000400519 <main+1>: mov %rsp,%rbp 0x000000000040051c <main+4>: sub $0x20,%rsp 0x0000000000400520 <main+8>: mov %edi,-0x14(%rbp)