我编写了可以编译的汇编代码:
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)上运行,我.code32在power.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) 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)