gas

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

南笙酒味 提交于 2019-11-28 14:38:16
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 previous stack frame pointer movl %esp, %ebp # the stack frame pointer for sum function # beginning

GAS: Explanation of .cfi_def_cfa_offset

夙愿已清 提交于 2019-11-28 14:35:58
问题 I would like an explanation for the values used with the .cfi_def_cfa_offset directives in assembly generated by GCC. I know vaguely that the .cfi directives are involved in call frames and stack unwinding, but I would like a more detailed explanation of why, for example, the values 16 and 8 are used in the assembly outputted by GCC in compiling the following C program on my 64-bit Ubuntu machine. The C program: #include <stdio.h> int main(int argc, char** argv) { printf("%d", 0); return 0; }

Gas altmacro macro with a percent sign in a default parameter fails with “% operator needs absolute expression”

不问归期 提交于 2019-11-28 10:43:33
问题 I want to create a macro like the following: .altmacro .macro assert_eq a, b=%eax LOCAL ok #... .endm To be used as: assert_eq $1 assert_eq $1, %eax I want .altmacro for LOCAL (I see the other possibility of using \@ , but I want LOCAL ). But when I try to compile this I get: Error: % operator needs absolute expression I am guessing that this problem is created by the fact that b=%eax is attempting to use another feature enabled by .altmacro : Expression results as strings, since without

x86_64 Assembly Linux System Call Confusion

早过忘川 提交于 2019-11-28 08:25:37
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 _start _start: movq $1, %rax movq $2, %rbx int $0x80 it works. Clearly the problem is the value I move

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

拜拜、爱过 提交于 2019-11-28 06:25:05
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 I track down this missing instruction error? It appears the compiler is correct but the linker simply

Bootloader works in emulators but not on real hardware

烈酒焚心 提交于 2019-11-28 05:56:29
问题 I am writing a bootloader in assembly and it seems to work fine on qemu, bochs and virtualbox. However, it is not loading the kernel on real hardware (it seems). The bootloader starts off by writing a character to the video memory (for debugging), it then reads sector 2 off the drive and far jumps to the kernel. The kernel is then writing some characters to video memory. On a real machine, I see the character from the bootloader on the screen, and there it hangs (blinking caret). I have tried

What is register %eiz?

廉价感情. 提交于 2019-11-28 05:12:29
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? 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 instruction takes one byte, so you would think that you could just add as many as needed. But according to

Generating assembly code from C# code?

亡梦爱人 提交于 2019-11-28 04:09:25
问题 Is there any way to generate assembly code from C# code? I know that it is possible with C code with GAS, but does anybody know if it's possible with C#? 回答1: C# is normally compiled to the .NET bytecode (called CIL or MSIL) and then JIT ("Just In Time") compiled to native code when the program is actually run. There exist ahead of time compilers for C# like Mono's AOT, so you could possibly compile a C# program through one of those and then disassemble it. The result is likely to be very

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

人走茶凉 提交于 2019-11-28 03:28:52
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 the system running in kernel-space. The point I want to make is this: I'm currently implementing a

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

寵の児 提交于 2019-11-28 03:24:28
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 assembly code from c source code on Linux? Babken Vardanyan I find it's a better approach to disassemble the