相关疑难解决方法(0)

在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 ×2

linux ×2

att ×1

build ×1

c ×1

x86 ×1

x86-64 ×1

yasm ×1