相关疑难解决方法(0)

从C执行二进制机器代码

按照这个说明,我设法只产生528字节的大小a.out(当gcc main.c最初给我8539字节的大文件时).

main.c是:

int main(int argc, char** argv) {

    return 42;
}
Run Code Online (Sandbox Code Playgroud)

但我已经从这个汇编文件中构建了一个a.out:

电源:

; tiny.asm
  BITS 64
  GLOBAL _start
  SECTION .text
  _start:
                mov     eax, 1
                mov     ebx, 42  
                int     0x80
Run Code Online (Sandbox Code Playgroud)

有:

me@comp# nasm -f elf64 tiny.s
me@comp# gcc -Wall -s -nostartfiles -nostdlib tiny.o
me@comp# ./a.out ; echo $?
42
me@comp# wc -c a.out
528 a.out
Run Code Online (Sandbox Code Playgroud)

因为我需要机器码:

objdump -d a.out

a.out:     file format elf64-x86-64


Disassembly of section .text:

00000000004000e0 <.text>:
  4000e0:   b8 01 00 00 00          mov    $0x1,%eax …
Run Code Online (Sandbox Code Playgroud)

c assembly gcc nasm opcode

16
推荐指数
1
解决办法
8535
查看次数

标签 统计

assembly ×1

c ×1

gcc ×1

nasm ×1

opcode ×1