标签: gnu-assembler

如何使 ELF 格式的 .section 在 GNU GAS 中只读?

据我了解,这些是.section指令:

awxMSGT
Run Code Online (Sandbox Code Playgroud)

如果使用 COFF 格式,“旧”指令具有“只读”。

如何将 ELF 格式的 .section 设置为只读?根本没有说明符吗?

assembly gnu-assembler elf

3
推荐指数
1
解决办法
4618
查看次数

用于 2007 年的英特尔语法代码上的 GNU 汇编程序错误

我终于回到了我的 colorforth 项目,几年前当 binutils 的更新破坏了我的所有资源时,我放弃了这个项目。这是正在发生的事情的一个例子:

jcomeau@aspire:~$ cat /tmp/test.as
    .intel_syntax
    .arch i386
    .code32
    mov eax,[foo + eax*4]
    lea    ecx,[ecx*4+0x9e0]
    mov    edx,DWORD PTR [edi*4-0x4]
    jmp    DWORD PTR [ecx*4+0x12cc]
    lea    edx,[ecx+edx*1]
Run Code Online (Sandbox Code Playgroud)

第一个非指令行来自手册中的示例:https : //sourceware.org/binutils/docs/as/i386_002dMemory.html#i386_002dMemory,其余来自 objdump 反汇编--disassembler-options=intel。每一个都无法组装:

jcomeau@aspire:~$ as /tmp/test.as
/tmp/test.as: Assembler messages:
/tmp/test.as:4: Error: too many memory references for `mov'
/tmp/test.as:5: Error: too many memory references for `lea'
/tmp/test.as:6: Error: too many memory references for `mov'
/tmp/test.as:8: Error: too many memory references for `lea'
/tmp/test.as:7: Error: invalid operands (*UND* …
Run Code Online (Sandbox Code Playgroud)

x86 assembly gnu-assembler intel-syntax

3
推荐指数
1
解决办法
351
查看次数

为什么GCC程序集输出不为printf生成.GLOBAL

我有一个简单的C程序示例: -

#include <stdio.h>
int main()
{
    printf("hello world!");
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

我使用以下命令编译它并生成程序集: -

riscv32-unknown-elf-gcc -S hello.c -o hello.asm
Run Code Online (Sandbox Code Playgroud)

其中生成以下程序集: -

    .file   "hello.c"
    .option nopic
    .section    .rodata
    .align  2
.LC0:
    .string "hello world!"
    .text
    .align  2
    .globl  main
    .type   main, @function
main:
    addi    sp,sp,-16
    sw  ra,12(sp)
    sw  s0,8(sp)
    addi    s0,sp,16
    lui a5,%hi(.LC0)
    addi    a0,a5,%lo(.LC0)
    call    printf
    li  a5,1
    mv  a0,a5
    lw  ra,12(sp)
    lw  s0,8(sp)
    addi    sp,sp,16
    jr  ra
    .size   main, .-main
    .ident  "GCC: (GNU) 7.2.0"
Run Code Online (Sandbox Code Playgroud)

有一个预期的call printf行,但因为在这个程序集文件中没有printf的实现,我本来希望看到它请求外部实现这样的东西......

.global …
Run Code Online (Sandbox Code Playgroud)

assembly gcc gnu-assembler riscv

3
推荐指数
1
解决办法
519
查看次数

GAS 汇编器不使用 2 字节相对 JMP 位移编码(仅 1 字节或 4 字节)

我正在尝试为不允许 0x00 字节的 CTF 挑战编写 shellcode(它将被解释为终止符)。由于挑战的限制,我必须做这样的事情:

[shellcode bulk]
[(0x514 - sizeof(shellcode bulk)) filler bytes]
[fixed constant data to overwrite global symbols]
[shellcode data]
Run Code Online (Sandbox Code Playgroud)

它看起来像这样

.intel_syntax noprefix
.code32

shellcode:
    jmp sc_data

shellcode_main:
    #open
    xor eax, eax
    pop ebx         //file string
    xor ecx, ecx    //flags
    xor edx, edx    //mode
    mov al, 5       //sys_OPEN
    int 0x80

    ...  // more shellcode

.org 514, 0x41     // filler bytes
.long 0xffffffff   // bss constant overwrite

sc_data:
    call shellcode_main
    .asciz "/path/to/fs/file"
Run Code Online (Sandbox Code Playgroud)

如果sc_datashellcode. 在这种情况下,汇编器 …

x86 assembly gnu-assembler machine-code shellcode

3
推荐指数
1
解决办法
898
查看次数

在 x86 实模式汇编中编写中断处理程序

我正在使用汇编学习 x86 实模式下的中断处理。我正在遵循从这里获取的以下示例:

.include "common.h"
BEGIN
    CLEAR
    /* Set address of the handler for interrupt 0. */
    movw $handler, 0x00
    /* Set code segment of the handler for interrupt 0. */
    mov %cs, 0x02
    int $0
    PUTC $'b
    hlt
handler:
    PUTC $'a
    iret
Run Code Online (Sandbox Code Playgroud)

但是当我编译并运行上面的代码时,

$ as --32 -o main.o main.S -g
$ ld -T linker.ld -o main.img --oformat binary -m elf_i386 -nostdlib main.o
$ qemu-system-i386 -hda main.img
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

qemu-system-i386: Trying to execute code outside RAM or ROM at …
Run Code Online (Sandbox Code Playgroud)

x86 assembly interrupt gnu-assembler x86-16

3
推荐指数
1
解决办法
1208
查看次数

GCC 上 x86 intel asm 中方括号前的偏移量

从我发现的所有文档中,没有提到像offset[var+offset2]Intel x86 语法那样的语法,但是 GCC 有以下标志

gcc -S hello.c -o - -masm=intel

对于这个程序

#include<stdio.h>
int main(){
    char c = 'h';
    putchar(c);
    return 0;
}

Run Code Online (Sandbox Code Playgroud)

产生

    .file   "hello.c"
    .intel_syntax noprefix
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    push    rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    mov rbp, rsp
    .cfi_def_cfa_register 6
    sub rsp, 16
    mov BYTE PTR -1[rbp], 104
    movsx   eax, BYTE PTR -1[rbp]
    mov edi, eax
    call    putchar@PLT
    mov eax, 0
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size …
Run Code Online (Sandbox Code Playgroud)

x86 assembly gcc gnu-assembler intel-syntax

3
推荐指数
1
解决办法
243
查看次数

如何在 GNU 汇编器中使用字符串文字作为立即操作数(并将其移动到地址)?

我的意思是我在 NASM 中这样写的东西:

mov dword [0xA0BF17C], ' : )'
Run Code Online (Sandbox Code Playgroud)

我在 GNU 汇编程序中尝试过这样的事情:

movd " : )", 0xB8000

movd $" : )", 0xB8000

movd ' : )', 0xB8000

movd " : )", $0xB8000
Run Code Online (Sandbox Code Playgroud)

但是......他们都导致了这个错误:

Error: unbalanced parenthesis in operand 1.
Run Code Online (Sandbox Code Playgroud)

x86 assembly gnu-assembler att

3
推荐指数
1
解决办法
595
查看次数

为什么我要使用 NASM 而不是 GNU Assembler (GAS)?

当 GAS 支持多种架构而 NASM 只支持 x86 架构时,为什么我要在 GNU 汇编器 (GAS) 上使用 NASM?我知道存在句法差异,但这并没有让我太困扰。

assembly gnu gnu-assembler nasm

3
推荐指数
1
解决办法
421
查看次数

什么是 GNU gas 中的零?

在以下编译器输出中:

a:
        .long   4
b:
        .byte   99
x:
        .zero   4
c:
        .byte   12
f:
        .zero   4
Run Code Online (Sandbox Code Playgroud)

.zero指令是什么意思?它似乎是唯一未在gas directives. 只是从上面看,long是四个字节,.byte是一个字节,我猜是四个字节的.zero零(或指令后面的任何数字)。那是对的吗?

如果是这样,为什么不这样做.long 0。这是否将其放在不同的部分或其他内容中?

assembly gnu-assembler

3
推荐指数
1
解决办法
144
查看次数

堆栈参数正在使用 C 调用约定在汇编中消失

我目前正在编写一些 x86 汇编代码,并使用as和将其与 glibc 链接ld

    .section .data

str1:
    .asciz "\n"

str3:
    .asciz "Hello"

str4:
    .asciz "Goodbye"

str5:
    .asciz "Guten Tag!"

str6:
    .asciz "Guten Morgen!"


    .section .bss
    .section .text
    .globl _start

_start:
    call main
    movl %eax, %ebx
    movl $1, %eax
    int $0x80

# void writeLine(char*);

    .type writeLine, @function
writeLine:
    pushl %ebp
    movl %esp, %ebp
    movl $str1, %ecx
    pushl %ecx
    movl 8(%ebp), %ecx
    pushl %ecx
    call strcat
    movl %eax, %ecx
    pushl %ecx
    call puts
    popl %ebx
    .leaver1:
    movl …
Run Code Online (Sandbox Code Playgroud)

x86 assembly gnu-assembler libc calling-convention

3
推荐指数
1
解决办法
54
查看次数