相关疑难解决方法(0)

如果我要在程序集中编写程序,那么这个HelloWorld汇编代码的哪些部分是必不可少的?

我有这个简短的你好世界计划:

#include <stdio.h>

static const char* msg = "Hello world";

int main(){
    printf("%s\n", msg);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我用gcc将它编译成以下汇编代码:

    .file   "hello_world.c"
    .section    .rodata
.LC0:
    .string "Hello world"
    .data
    .align 4
    .type   msg, @object
    .size   msg, 4
msg:
    .long   .LC0
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    andl    $-16, %esp
    subl    $16, %esp
    movl    msg, %eax
    movl    %eax, (%esp)
    call    puts
    movl    $0, %eax
    leave
    .cfi_restore 5
    .cfi_def_cfa …
Run Code Online (Sandbox Code Playgroud)

c linux x86 assembly

10
推荐指数
1
解决办法
1149
查看次数

在64位系统上组装32位二进制文​​件(GNU工具链)

我编写了可以编译的汇编代码:

as power.s -o power.o
Run Code Online (Sandbox Code Playgroud)

当我链接power.o目标文件时出现问题:

ld power.o -o power
Run Code Online (Sandbox Code Playgroud)

为了在64位操作系统(Ubuntu 14.04)上运行,我.code32power.s文件的开头添加了,但是我仍然得到错误:

分段故障(核心转储)

power.s:

.code32
.section .data
.section .text
.global _start
_start:
pushl $3
pushl $2 
call power 
addl $8, %esp
pushl %eax 

pushl $2
pushl $5
call power
addl $8, %esp

popl %ebx
addl %eax, %ebx

movl $1, %eax
int $0x80



.type power, @function
power:
pushl %ebp  
movl %esp, %ebp 
subl $4, %esp 
movl 8(%ebp), %ebx 
movl 12(%ebp), %ecx 
movl %ebx, -4(%ebp) 

power_loop_start:
cmpl …
Run Code Online (Sandbox Code Playgroud)

linux x86 assembly build att

9
推荐指数
2
解决办法
3853
查看次数

Can't call C standard library function on 64-bit Linux from assembly (yasm) code

I have a function foo written in assembly and compiled with yasm and GCC on Linux (Ubuntu) 64-bit. It simply prints a message to stdout using puts(), here is how it looks:

bits 64

extern puts
global foo

section .data

message:
  db 'foo() called', 0

section .text

foo:
  push rbp
  mov rbp, rsp
  lea rdi, [rel message]
  call puts
  pop rbp
  ret
Run Code Online (Sandbox Code Playgroud)

It is called by a C program compiled with GCC:

extern void foo();

int main() {
    foo(); …
Run Code Online (Sandbox Code Playgroud)

c linux assembly x86-64 yasm

7
推荐指数
2
解决办法
276
查看次数

标签 统计

assembly ×3

linux ×3

c ×2

x86 ×2

att ×1

build ×1

x86-64 ×1

yasm ×1