gas

Calculating padding length with GAS AT&T directives for a boot sector?

♀尐吖头ヾ 提交于 2019-11-28 02:03:36
So I want to add padding in the bootsector. Let's say, there is currently just an endless loop in there: jmp . . The sector needs to be 512 bytes long. Also, the magic num 0xaa55 is needed which is added at the end. jmp . .skip 508, 0 .word 0xaa55 But what if I want to print something but don't want to count all the bytes to pad it into the right size? In Intel/NASM syntax would it be: ; print something times 510-($-$$) db 0 dw 0xaa55 But in AT&T syntax? Well a loop ( .rept ) doesn't work here because . doesn't give an absolute value which is needed here. We have the same problem with .skip /

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

烈酒焚心 提交于 2019-11-28 01:59:05
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 find any relevant documentation. As of Binutils 2.29 the instruction suffixes are now deprecated in

Is there a symbol that represents the current address in GNU GAS assembly?

大憨熊 提交于 2019-11-27 17:36:05
问题 I am curious to know is there any special GAS syntax to achieve the same like in NASM example: SECTION .data msg: db "Hello World",10,0 ; the 0-terminated string. len: equ $-msg ; "$" means current address. Especially I'm interested in the symbol $ representing the current address. 回答1: There is a useful comparison between gas and NASM here: http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html See in particular this part, which I think addresses your question: Listing 2 also

How do RIP-relative variable references like “[RIP + _a]” in x86-64 GAS Intel-syntax work?

最后都变了- 提交于 2019-11-27 16:18:18
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 incorrect address of a ? Conversely, if I use x86 syntax (which is very intuitive): mov eax, dword ptr [

x86 Linux assembler get program parameters from _start

微笑、不失礼 提交于 2019-11-27 15:20:00
I'm trying to create a program to just write the param on the screen. I created some programs to get the C function parameter, or i used C to send the parameter to my asm program. Is there a way to get the program parameter using only assembler EX: ./Program "text" I'm using as (Gnu Assembler) Usually i get those parameters using [esp+4] Because the esp is the program/function call pointer, but in pure asm it don't get the command line parameter. Is there a way to do that? I googled it, but i wans't able to find much information scottt On Linux, the familiar argc and argv variables from C are

How to produce a minimal BIOS hello world boot sector with GCC that works from a USB stick on real hardware?

人走茶凉 提交于 2019-11-27 14:44:22
I have managed to produce a minimal boot sector that works with QEMU 2.0.0 Ubuntu 14.04: .code16 .global _start _start: cli mov $msg, %si mov $0x0e, %ah loop: lodsb or %al, %al jz halt int $0x10 jmp loop halt: hlt msg: .asciz "hello world" .org 510 .word 0xaa55 Compiled with: as -o main.o main.S ld --oformat binary -o main.img -Ttext 0x7C00 main.o The example is available on this repo: https://github.com/cirosantilli/x86-bare-metal-examples/tree/2b79ac21df801fbf4619d009411be6b9cd10e6e0/no-ld-script Upon: qemu -hda main.img it shows hello world on the emulator screen as expected. But if I try

How to get the size of a C function from inside a C program or with inline assembly?

醉酒当歌 提交于 2019-11-27 14:29:42
Suppose I have a function like below: # cat 003.c int foo(int a, int b) { return a+b; } And compile it like this: gcc -S 003.c The gets the following assembly result: .file "003.c" .text .globl foo .type foo, @function foo: .LFB2: pushq %rbp .LCFI0: movq %rsp, %rbp .LCFI1: movl %edi, -4(%rbp) movl %esi, -8(%rbp) movl -8(%rbp), %edx movl -4(%rbp), %eax addl %edx, %eax leave ret .LFE2: .size foo, .-foo /* size of the function foo, how to get it?*/ The last line above do get the size of the function. Where does the compiler store the size? Can I get the function's size in some way in my origin C

gas: too many memory reference

空扰寡人 提交于 2019-11-27 09:45:20
When compiling the following instruction: movl 4(%ebp), 8(%ebp) I got: too many memory reference . What's wrong with it? 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) It is not a legal instruction. For most instructions that reference memory you must move it to/from a register. movl doesn't to memory-memory moves, you have to go by way of a register (thus with two movl instructions). 来源: https:/

What does the bracket in `movl (%eax), %eax` mean?

有些话、适合烂在心里 提交于 2019-11-27 08:57:30
I have googled enough but could not figure out what the bracket () means. Also, I see some syntax as movl 8(%ebp), %eax Could some someone suggest me some good reference? I have not been able to find any in the top 20 results from Google. LaC %eax is register EAX; (%eax) is the memory location whose address is contained in the register EAX; 8(%eax) is the memory location whose address is the value of EAX plus 8. osgx http://web.archive.org/web/20080215230650/http://sig9.com/articles/att-syntax is quick introduction into Unix (AT&T) asm syntax. Googled by at&t asm syntax . The post is "AT&T

GCC: Prohibit use of some registers

蹲街弑〆低调 提交于 2019-11-27 08:37:33
This is a strange request but I have a feeling that it could be possible. What I would like is to insert some pragmas or directives into areas of my code (written in C) so that GCC's register allocator will not use them. I understand that I can do something like this, which might set aside this register for this variable register int var1 asm ("EBX") = 1984; register int var2 asm ("r9") = 101; The problem is that I'm inserting new instructions (for a hardware simulator) directly and GCC and GAS don't recognise these yet. My new instructions can use the existing general purpose registers and I