问题描述
这code是非常简单的,我让我的x86_64的Linux系统上赛格故障。这是困扰我很多东西。刚开始使用ASM所以请有耐心!
组装NASM NASM -f ELF64 TEST.ASM
带有链接 LD -o测试test.o
.text段
GLOBAL _start _开始:
;打印名称
MOV EAX,4; SYS_WRITE
MOV EBX,1;标准输出
MOV ECX,名称;开始的名称地址
MOV EDX,1;长度
INT 80H;系统调用 ;出口程序
MOV EAX,1; sys_exit
MOV EBX,0;成功
INT 80H; sys_call段.data
命名DB'R'
我的机器:Gentoo的x86_64的nomultilib!我编我自己的内核,而不IA32仿真。我应该说,我的系统是64位的系统。请问这个属性来我收到错误?
$的uname -a
Linux的rcepeda 4.4.1-2拱#1 SMP preEMPT周三2月3日13点十二分33秒UTC 2016年x86_64的GNU / Linux的
解决方案
使用64位寄存器和64位的Linux调度
使用系统调用(不是int 80H)。
谢谢Nate和迈克尔
.text段
GLOBAL _start _开始:
;打印名称
MOV RAX,1; SYS_WRITE
MOV RDI,1;标准输出
MOV RSI,名称;开始的名称地址
MOV RDX,7;长度
系统调用 ;出口程序
MOV RAX,60; sys_exit
MOV RDI,0;成功
系统调用段.data
命名DB拉斐尔,10
拉斐尔@ rcepeda〜/ ASM $ ./a.out
拉斐尔
您是在64位模式下运行,但是这是32位code。如果你想64位code,你就必须重写。
您应该使用64位的寄存器 RAX,RBX
等,而在64位Linux,系统调用不再与 INT 80H 但随着新系统调用
指令。请参见 http://cs.lmu.edu/~ray/notes/linuxsyscalls/为例(注意这里使用AT& T公司汇编语法,而不是英特尔)。
另外,你可以保持code一样的,组装和32位模式下,将其链接使用 NASM -f ELF32
和 LD -m elf_i386
。但此时你学习(相对而言)过时的技术。 (编辑:其实,看来32位兼容性不特定的系统上启用,所以这不会为你在所有的工作)
This code is really simple and I am getting a seg fault on my x86_64 linux system. It is bothering me a lot. Just getting started with asm so please have patience!
Assembled with NASMnasm -f elf64 test.asm
linked withld -o test test.o
SECTION .text
GLOBAL _start
_start:
; print name
mov eax,4 ; sys_write
mov ebx,1 ; stdout
mov ecx,name ; start address of name
mov edx,1 ; length
int 80H ; syscall
; exit program
mov eax,1 ; sys_exit
mov ebx,0 ; success
int 80H ; sys_call
SECTION .data
name DB 'R'
My machine: Gentoo x86_64 nomultilib! I compiled my own kernel without IA32 emulation. I should have stated that my system is a 64 bit only system. Would this attribute to the errors I am receiving?
$ uname -a
Linux rcepeda 4.4.1-2-ARCH #1 SMP PREEMPT Wed Feb 3 13:12:33 UTC 2016 x86_64 GNU/Linux
Solution
use 64 bit registers and 64bit linux dispatcher
use syscall (not int 80H).
Thank you Nate and Michael
SECTION .text
GLOBAL _start
_start:
; print name
mov rax,1 ; sys_write
mov rdi,1 ; stdout
mov rsi,name ; start address of name
mov rdx,7 ; length
syscall
; exit program
mov rax,60 ; sys_exit
mov rdi,0 ; success
syscall
SECTION .data
name DB "Rafael",10
.
rafael@rcepeda ~/asm $ ./a.out
Rafael
You're running in 64-bit mode but this is 32-bit code. If you want 64-bit code, you'll have to rewrite it.
You should be using the 64-bit registers rax, rbx
, etc. And in 64-bit Linux, system calls are no longer made with int 80h
but with the new syscall
instruction. See http://cs.lmu.edu/~ray/notes/linuxsyscalls/ for an example (note this uses AT&T assembler syntax instead of Intel).
Alternatively, you can keep the code the same, and assemble and link it in 32-bit mode, using nasm -f elf32
and ld -m elf_i386
. But then you're learning (relatively) obsolete technology. (Edit: Actually, it appears 32-bit compatibility is not enabled on your particular system, so this won't work at all for you.)
这篇关于赛格故障......在Hello world的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!