gas

gas vs. nasm: which assembler produces the best code?

折月煮酒 提交于 2019-12-03 12:48:27
Both tools translate assembly instructions directly into machine code, but is it possible to determine which one produces the fastest and cleanest code? When you're writing in assembler, you are precisely describing the instructions to generate so it doesn't depend on the assembler. It depends on you. There's a one-to-one correspondence between the mnemonics you write and actual instructions in machine code. I don't know about these two specific tools, but there are some instructions that can be encoded differently: ADD AX,1 is either 05 01 or 81 c0 01 or fe c0 INT 3 is either cc or cd 03 New

1b and 1f in GNU assembly

末鹿安然 提交于 2019-12-03 07:37:50
I am analyzing a linux exception code. By the way I can't understand gnu assembly syntax. svc_preempt: mov r8, lr 1: bl preempt_schedule_irq @ irq en/disable is done inside ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS tst r0, #_TIF_NEED_RESCHED moveq pc, r8 @ go again b 1b In this code, I can see "b 1b", but I can't find "1b" label anywhere. And, #ifdef CONFIG_NEON adr r6, .LCneon_thumb_opcodes b 2f #endif call_fpe: #ifdef CONFIG_NEON adr r6, .LCneon_arm_opcodes 2: ldr r7, [r6], #4 @ mask value cmp r7, #0 @ end mask? beq 1f and r8, r0, r7 ldr r7, [r6], #4 @ opcode bits matching in mask

GCC's assembly output of an empty program on x86, win32

故事扮演 提交于 2019-12-03 01:43:32
问题 I write empty programs to annoy the hell out of stackoverflow coders, NOT. I am just exploring the gnu toolchain. Now the following might be too deep for me, but to continuie the empty program saga I have started to examine the output of the C compiler, the stuff GNU as consumes. gcc version 4.4.0 (TDM-1 mingw32) test.c: int main() { return 0; } gcc -S test.c .file "test.c" .def ___main; .scl 2; .type 32; .endef .text .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp movl

Gnu assembler .data section value corrupted after syscall

血红的双手。 提交于 2019-12-02 12:34:48
问题 I have following code .data result: .byte 1 .lcomm input 1 .lcomm cha 2 .text (some other code, syscalls) At first everything is fine. When a syscall (eg. read) is called, the value at label 'result' changed to some random trash value. Anyone know what's wrong? P.S. Environment Debian x86_64 latest Running in virtualbox Using as -g ld emacs make latest -----edit----- (continue) .global _start _start: mov $3,%rax mov $0,%rbx mov $input,%rcx mov $1,%rdx int $0x80 (sys_exit) The value of 'input'

Trying to implement strlen in x86 GAS

巧了我就是萌 提交于 2019-12-02 12:34:38
问题 so I am very new (extremely new) to assembly programming and am trying to write a function that can calculate the length of a string. I feel I have some issue with clearing out values in registers, or with the incrementation of the pointer, because the value that is getting returned is always "4571 + length" for me. Basically, if I have string length 0, I get 4571 as the return value. If I have string length 6, I get 4577 as the return value, etc. Here's my code, any help will be appreciated:

Replacing the Timer Interrupt Handler in DOS With GNU (GCC and GAS)

你离开我真会死。 提交于 2019-12-02 10:53:00
问题 As the title suggests, I'm trying to replace the existing handler for the Timer interrupt in DOS with one of my own. After searching far and wide for a variety of solutions, I found some Assembly code which does exactly that, and I have even managed to compile and test it, and saw that it works. The problem now is that the code I found (see further down) is written for TASM, and I wish to use it with some C code that I'm writing, which I compile with GCC. I've tried to convert the code into

Calling C function in assembly code (gas)

寵の児 提交于 2019-12-02 10:08:06
问题 I found an example and was editing it for gas. extern printf .global _start .data hello: db "Hello", 0xa, 0 .text _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret But it doesn't work. What's wrong? What does this mean: hello: db "Hello", 0xa, 0 I understand what it scope of memory, but I don't understand this string db "Hello", 0xa, 0 And here _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret os: linux (debian). intel 64-bit 回答1: It's is the null-byte-terminattor.

Gnu assembler .data section value corrupted after syscall

╄→гoц情女王★ 提交于 2019-12-02 06:26:54
I have following code .data result: .byte 1 .lcomm input 1 .lcomm cha 2 .text (some other code, syscalls) At first everything is fine. When a syscall (eg. read) is called, the value at label 'result' changed to some random trash value. Anyone know what's wrong? P.S. Environment Debian x86_64 latest Running in virtualbox Using as -g ld emacs make latest -----edit----- (continue) .global _start _start: mov $3,%rax mov $0,%rbx mov $input,%rcx mov $1,%rdx int $0x80 (sys_exit) The value of 'input' was changed properly, but the value of 'result' changed to random value as well after int $0x80 You're

Distinguishing memory from constant in GNU as .intel_syntax

ε祈祈猫儿з 提交于 2019-12-02 06:26:14
问题 I have an instruction written in Intel syntax (using gas as my assembler) that looks like this: mov rdx, msg_size ... msg: .ascii "Hello, world!\n" .set msg_size, . - msg but that mov instruction is being assembled to mov 0xe,%rdx , rather than mov $0xe,%rdx , as I would expect. How should I write the first instruction (or the definition of msg_size ) to get the expected behavior? 回答1: In GAS .intel_syntax noprefix mode: OFFSET symbol works like AT&T $symbol . This is somewhat like MASM.

Calling C function in assembly code (gas)

社会主义新天地 提交于 2019-12-02 06:12:04
I found an example and was editing it for gas. extern printf .global _start .data hello: db "Hello", 0xa, 0 .text _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret But it doesn't work. What's wrong? What does this mean: hello: db "Hello", 0xa, 0 I understand what it scope of memory, but I don't understand this string db "Hello", 0xa, 0 And here _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret os: linux (debian). intel 64-bit It's is the null-byte-terminattor . Well-know as C-string.Such byte at end-of-string say where the string ends. For example,you pass the