gas

Why doesn't this attempt at using sys_write do anything?

心已入冬 提交于 2019-12-02 04:26:17
Here it is: .SECTION .data msg: .string "AAAA" .SECTION .text .globl _start _start: mov $1, %rax mov $1, %rdi mov msg, %rsi mov $4, %rdx syscall Not only does this code not segfault, it also outputs nothing. According to what I've read, a program should call sys_exit, or it would segfault, but this does not happen. mov msg, %rsi This instruction will interpret the data at "msg" as 64-bit value and load that value into the register rsi . The instruction does NOT load the address of "msg" into register rsi . This could be done by (note the $ ): mov $msg, %rsi According to what I've read, a

Trying to implement strlen in x86 GAS

笑着哭i 提交于 2019-12-02 03:56:52
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: .globl my_strlen my_strlen: pushq %rbp movq %rsp, %rbp pushq %r12 pushq %r13 movq $0, %rax cmp $0, (

How to make local labels in GNU GAS ELF output that GDB can break on but not count as functions?

独自空忆成欢 提交于 2019-12-02 03:47:47
问题 When writing assembly manually with GNU GAS, within a function, I want to set a label such that: GDB won't treat that label as the function name I can use b mylabel to break on the label A similar question for nasm has been asked at: Break at local label using GDB for NASM assembly but I wanted to make it more precise here that I want GNU GAS and ELF output. E.g. if I defined a normal label mylabel as in: main.S .text .global _start _start: /* exit */ mov $60, %rax mylabel: mov $0, %rdi

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

末鹿安然 提交于 2019-12-02 03:13:15
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 GAS (GNU Assembler) syntax, but I can't seem to get it to work (I mostly experienced crashes of one kind

Assembling i386 code on x86_64

柔情痞子 提交于 2019-12-02 02:37:53
The following code does not work as expected: .intel_syntax noprefix .arch i386 .data hello_world: .ascii "Hello world!\n" hello_world_end: .equ hello_world_len, hello_world_end - hello_world .text .global _start _start: mov ebx, 1 mov ecx, hello_world mov edx, hello_world_len mov eax, 4 int 0x80 mov ebx, 0 mov eax, 1 int 0x80 When ran through: as test.s -o test.o ld test.o -o test ./test It outputs nothing. When I change the line: mov ecx, offset hello_world ; added offset It works fine. I tried compiling the original code with --32 -march=i386 and linking with -m elf_i386 but it still

How to make local labels in GNU GAS ELF output that GDB can break on but not count as functions?

柔情痞子 提交于 2019-12-02 02:30:43
When writing assembly manually with GNU GAS, within a function, I want to set a label such that: GDB won't treat that label as the function name I can use b mylabel to break on the label A similar question for nasm has been asked at: Break at local label using GDB for NASM assembly but I wanted to make it more precise here that I want GNU GAS and ELF output. E.g. if I defined a normal label mylabel as in: main.S .text .global _start _start: /* exit */ mov $60, %rax mylabel: mov $0, %rdi syscall that does not satisfy me because when GDB reaches the mov $0, %rdi , bt shows mylabel as the

What does the colon : mean in x86 assembly GAS syntax as in %ds:(%bx)?

霸气de小男生 提交于 2019-12-01 22:32:18
问题 I am new to x86 assembly and I am trying to understand the code in this document : http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf page 3 : movw $0x1234, %ax movw %ax, %ds movw $0x5678, %bx # The following instruction is the same as "movw $0x1337, (%bx)". movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8. # Segment Base: %ds << 4: 12340 # Offset: %bx: + 5678 # ------- # Linear Address: 179b8 But I am not understanding the command : movw $0x1337, %ds:(%bx) # Places 0x1337 into

Is there a difference between equals sign assignment “x = 1” and “.equ x, 1” or “.set x, 1” in GNU Gas assembly?

徘徊边缘 提交于 2019-12-01 21:27:23
E.g.: a = 1 and: .equ a, 1 and: .set a, 1 all produce the same output byte-by-byte upon: as --32 main.S according to cmp . I know that .equ and .set do the same thing according to the documentation of .equ : https://sourceware.org/binutils/docs-2.25/as/Equ.html : It is synonymous with `.set'. and I know what .equ does from Difference between .equ and .word in ARM Assembly? So what about = ? Is it the same as the other two? It is the same. After grepping the documentation source, I've found the section that confirms it https://sourceware.org/binutils/docs-2.25/as/Setting-Symbols.html A symbol

Defining “variables” in assembly language

可紊 提交于 2019-12-01 20:56:58
I underdstand that this is extremely stupid quiestion, but I can't figure an answer for some time How do I correctly declare and define "variables" in GAS AT&T assembly language? For example, I want buffer for 5 bytes, two 1-byte variables (initially with 0 value), 2-byte variable with 0 and 2-byte variable with 10. This code doesn't work correctly, at least debugger says (on the first line of the program, after these declarations, just nop instruction) that b and c are big numbers instead of zeros. .bss .lcomm r, 5 .data a: .byte 0 b: .byte 0 c: .word 0 d: .word 10 Here's what you see in your

What does the colon : mean in x86 assembly GAS syntax as in %ds:(%bx)?

淺唱寂寞╮ 提交于 2019-12-01 20:48:41
I am new to x86 assembly and I am trying to understand the code in this document : http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf page 3 : movw $0x1234, %ax movw %ax, %ds movw $0x5678, %bx # The following instruction is the same as "movw $0x1337, (%bx)". movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8. # Segment Base: %ds << 4: 12340 # Offset: %bx: + 5678 # ------- # Linear Address: 179b8 But I am not understanding the command : movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8. Why concatenating %ds with (%bx) is the same as ((%ds << 4) | %bx) ? As I am in real