gnu-assembler

How to rewrite a files content? Linux x86_64, assembly, GAS

╄→尐↘猪︶ㄣ 提交于 2021-02-11 12:29:31
问题 Hi ive got this exciting task, almost done actually.. but it fails in a funny aspect. The mission is to load a file with integers, sort them and write them to a file. Yay... Well my program is doing that, but it keeps the original content. ie: lets say 45 32 Should get the ordered content 32 45 Well my program is keeping the original content and adds the new: 45 32 32 45. So any sugestions on solving this? Though of deleting the original file and creating a new one in the same name. But thats

What does 1: mean in assembly language?

↘锁芯ラ 提交于 2021-02-07 09:30:50
问题 I was reading the source code of RISC-V test pattern. And there is a macro define in riscv-test.h, I want to know what does 1: means in this code: #define RVTEST_CODE_BEGIN \ .section .text.init; \ .align 6; \ .weak stvec_handler; \ .weak mtvec_handler; \ .globl _start; \ _start: \ /* reset vector */ \ j reset_vector; \ .align 2; \ trap_vector: \ /* test whether the test came from pass/fail */ \ csrr t5, mcause; \ li t6, CAUSE_USER_ECALL; \ beq t5, t6, write_tohost; \ li t6, CAUSE_SUPERVISOR

x86 Assembly (AT&T): How do I dynamically allocate memory to a variable at runtime?

穿精又带淫゛_ 提交于 2021-02-04 08:36:07
问题 I am trying to allocate an amount of space to a variable at runtime. I know that I can allocate a constant amount of space to a variable at compile time, for instance: .data variable: # Allocate 100 bytes for data .space 100 However, how do I allocate a variable amount of space to a variable at runtime? For instance, allocating %eax bytes of space to the variable at runtime? 回答1: You can't dynamically allocate static storage. You need to use the stack, or malloc / mmap / whatever (sometimes

Import constants in x86 with gas

≯℡__Kan透↙ 提交于 2021-01-29 18:25:48
问题 I have the following two files in assembly: # file.s .globl _start _start: mov $10, %edi mov $SYS_EXIT, %eax syscall # utils.s SYS_EXIT = 60 SYS_WRITE = 1 SYS_STDOUT = 1 What is required to be able to link these two files into an executable. To assemble and link I've tried doing: $ as file.s -o file.o $ as utils.s -o utils.o $ ld utils.o file.o -o file # file.o: In function `_start': # (.text+0x8): undefined reference to `SYS_EXIT' Which seems to just mean I'm not properly importing the file

How to call a function in an external assembly file [duplicate]

試著忘記壹切 提交于 2021-01-29 05:38:07
问题 This question already has answers here : calling assembly function from c (4 answers) Calling an assembly function from C (2 answers) Passing parameters from C to GNU Assembly function in 64bit (1 answer) Closed 6 days ago . I am trying to go from a C function to a function with inline-asm to a standalone function in an assembly file. Here is what I have so far: #include <stdio.h> int add_five(int n) { n = n + 5; return n; } int add_five_inline(int n) { asm("lea 5(%1), %0" : "=r" (n) : "r" (n

Can't size instruction

这一生的挚爱 提交于 2021-01-28 02:20:50
问题 I was wondering why some assembly instructions can be inferred, but others cannot. For example, in the following program I have: .globl main main: push %rbp mov %rsp, %rbp mov $8, -8(%rbp) mov -8(%rbp), %rax pop %rbp ret I get the following error: stack.s:5: Error: no instruction mnemonic suffix given and no register operands; can't size instruction However, if I change: the 5th line to: movq $8, -8(%rbp) It runs without error. How can all the other operations infer the size, but that

What is zero in GNU gas?

萝らか妹 提交于 2021-01-27 13:58:40
问题 In the following compiler output: a: .long 4 b: .byte 99 x: .zero 4 c: .byte 12 f: .zero 4 What does the .zero directive mean? It seems to be the only one not listed in the gas directives. Just from looking at the above, long is four bytes, .byte is one byte, and I'm guessing .zero means zero-for-four-bytes (or whatever the number is after the directive). Is that correct? If so, why not just do .long 0 . Does this put it in a different section or something? 回答1: No, it doesn't put it in a

How to get the size of a function in bytes in GNU assembler with Intel syntax?

狂风中的少年 提交于 2020-12-13 04:10:16
问题 I need to compute the size of a function in bytes at assembly time. I've tried various ways, including: .set chk0_sz, offset chk0_e - offset chk0_s and then using mov rcx, offset chk0_sz to get the value. However, it gives the error: error: cannot use more than one symbol in memory operand . Here chk0_e and chk0_s are two labels denoting the end and start of the function, respectively. Any ideas? 回答1: You only need the offset keyword when using an address as an immediate. In other contexts,

How to get the size of a function in bytes in GNU assembler with Intel syntax?

╄→尐↘猪︶ㄣ 提交于 2020-12-13 04:05:11
问题 I need to compute the size of a function in bytes at assembly time. I've tried various ways, including: .set chk0_sz, offset chk0_e - offset chk0_s and then using mov rcx, offset chk0_sz to get the value. However, it gives the error: error: cannot use more than one symbol in memory operand . Here chk0_e and chk0_s are two labels denoting the end and start of the function, respectively. Any ideas? 回答1: You only need the offset keyword when using an address as an immediate. In other contexts,

Macro substituting a constant number in GAS

烈酒焚心 提交于 2020-12-05 04:58:25
问题 What't wrong with that macro on X86 GNU Assembly? It says the symbol S is undefined during linking. .macro S size=40 \size .endm I'm using it like mov %eax, S 回答1: Macros are used to create templates for code you frequently use, not to input a constant number. As such, I do not believe the assembler does macro expansion within an expression. Since you simply want a number, you could use .set to define a constant. .set S, 40 mov %eax, S Also, in case you usually use intel syntax, make sure you