gas

assembly .set directive gives error invalid operands (.data and *UND* sections)

旧城冷巷雨未停 提交于 2019-12-12 02:35:35
问题 I am learning to write a bootloader. As a part of experiment, I want to be able to print hexadecimal values as strings. I wrote following assembly code which doesn't entirely implement hex to string functionality. However, I expected following code to at least assemble correctly. $ cat print_bios.S .file "print_bios.S" .section .data .hex_str: .ascii "xxxxxxxxxxxxxxxx" .set hex_size, .-hex_str .section .text .global .hex_to_string hex_to_string: push %rbp mov %rsp, %rbp /* * leave speace for

GNU Assembler (Mac OS X 64-bit): Illegal instruction: 4 [duplicate]

北慕城南 提交于 2019-12-11 20:39:26
问题 This question already has an answer here : basic assembly not working on Mac (x86_64+Lion)? (1 answer) Closed 5 months ago . I am new to GNU Assembler and I'm trying to execute this piece of code: .globl _main _main: movl $1, %eax movl $0, %ebx int $0x80 This programm should exit by the system call exit ( 1 ). Compiled it (no warnings): gcc test.s But running it gives me the error: Illegal instruction: 4 Thanks for help! 回答1: If you're compiling a 64-bit executable, then you should write

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

白昼怎懂夜的黑 提交于 2019-12-11 18:32:09
问题 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

How to create local variables inside the main function?

元气小坏坏 提交于 2019-12-11 14:57:47
问题 I know how to pass parameters to a user-defined function and how to create local variables inside such function. But what I want is to create local variables for the main function. So the main function is the first thing that executes when the program starts, but what is the initial value of esp when main starts executing? i.e what is on top of the stack when main starts executing, is it the command line arguments? If I want to create local variables inside main, should I save the value of

How to specify ELF section alignment in GNU as?

空扰寡人 提交于 2019-12-11 13:09:16
问题 I'm trying to use GNU as as a generic assembler similar in use as nasm . I make a template source like this: .section .text .globl _start .intel_syntax noprefix _start: call 0xb77431c0 # the instruction I want to assemble And then I run the assemble command like this: as --32 -o test.o test.s ld -m elf_i386 -Ttext 0xb77431d9 --oformat binary -o test.bin test.o All works well with binutils 2.24. But it appears that as from binutils 2.22 (the one in Ubuntu Precise) aligns .text section to the 4

sys_read syscall vs. int 0x80 in GNU Assembler [duplicate]

房东的猫 提交于 2019-12-11 08:42:32
问题 This question already has an answer here : What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? (1 answer) Closed 2 years ago . I'm attempting to write a simple program which grabs a number of characters from stdin. For the sake of brevity, the relevant code is: mov $3, %rax # sys_read = 3 mov $0, %rbx # stdin fd = 0 mov $b, %rcx # '.lcomm b, 32' declared in .bss section mov $32,%rdx # size_t # syscall int $0x80 When I use int $0x80 the program functions as intended, however

How to direct gas use a specified encoding form of instructions, for example, MOV?

£可爱£侵袭症+ 提交于 2019-12-11 06:28:37
问题 The MOV have the two form to move an imm to r64: | Opcode | Instruction | Op/En | 64-Bit Mode | Compat/Leg Mode | Description | | REX.W + B8+ rd | MOV r64, imm64 | E | Valid | N.E. | Move imm64 to r64. | | REX.W + C7 /0 | MOV r/m64,imm32 | F | Valid | N.E. | Move imm32 sign extended to 64-bits to r/m64. | In the example bellow, Line 6(Line 5,7 are not so important, we ignore it.) use the 2nd form. So the problem is, if we link the object file with '-Ttext=' to specify a address that can be

How do function calls work in x86 32-bit assembly on Linux?

a 夏天 提交于 2019-12-11 05:52:22
问题 I am learning GNU assembly from Jonathan Bartlett's "Programming from ground up" book. While going through the topic of a function call and stack, I'm unable to understand its working. Below is what's written in the book: Before executing a function, a program pushes all of the parameters for the function onto the stack in the reverse order that they are documented. Then the program issues a call instruction indicating which function it wishes to start. The call instruction does two things.

Calling equ'd symbols in GAS

天涯浪子 提交于 2019-12-11 05:06:20
问题 Here's a small NASM program: [BITS 64] [ORG 0x0000000000200000] b_print_newline equ 0x0000000000100040 start: call b_print_newline ret Assemble it: $ nasm -f bin pr-nl-a.asm -o pr-nl-a.app Disassemble it: $ objdump -D -b binary -m i386:x86-64 pr-nl-a.app pr-nl-a.app: file format binary Disassembly of section .data: 0000000000000000 <.data>: 0: e8 3b 00 f0 ff callq 0xfffffffffff00040 5: c3 retq Here's a GAS version: .set b_print_newline , 0x0000000000100040 .text .global _start _start: call b

How to use hexadecimal floating point literals in GNU GAS?

雨燕双飞 提交于 2019-12-11 02:21:24
问题 C99 introduced hexadecimal floating point literals as a new code obfuscation technique, e.g.: assert(0x1.8p0 == 1.5); Can I achieve the same level of obfuscation in my GNU GAS assembly code, or do I have to resort to .byte + manual labor? You may use this as a testing base: .data float_1_5: .double 1.5 float_2_5: .double 2.5 float_4_0: .double 4.0 .text .global _start _start: /* 1.5 + 2.5 == 4.0 */ fldl float_1_5 fldl float_2_5 faddp %st, %st(1) fldl float_4_0 fcomip %st(1) /* Exit syscall. *