linux nasm helloworld

1:setup Nasm in linux

1:下载源码包 nasm-x.xx.tar.gz

2: tar -zxf nasm-x.xx.tar.gz

3:cd nasm directory

4:./configure

5:make install

6: nasm --vesion


2:

;  hello.asm  a first program for nasm for Linux, Intel, gcc
;
; assemble:    nasm -f elf hello.asm -o hello.o
; link:        gcc -o hello  hello.o
; run:            hello
; output is:    Hello World

    SECTION .data        ; data section
msg:    db "Hello World",10    ; the string to print, 10=cr
len:    equ $-msg        ; "$" means "here"
                ; len is a value, not an address

    SECTION .text        ; code section
        global main        ; make label available to linker
main:                ; standard  gcc  entry point
    
    mov    edx,len        ; arg3, length of string to print
    mov    ecx,msg        ; arg2, pointer to string
    mov    ebx,1        ; arg1, where to write, screen
    mov    eax,4        ; write command to int 80 hex
    int    0x80        ; interrupt 80 hex, call kernel
    
    mov    ebx,0        ; exit code, 0=normal
    mov    eax,1        ; exit command to kernel
    int    0x80        ; interrupt 80 hex, call kernel

2:nasm -f elf64 helloworld.asm -o hellowold.o

3:ld  hellowold.o -o hello

4:./hello


$nasm -f elf exit.asm

$ld exit.o -o exit

出现下面的结果:


在网上搜了一下解决方案:


之后再执行链接就不会报错了。。。。

 


Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om elf_k1om i386pep i386pe

我之前写的命令行是:ld -o eatsyscall eatsyscall.o

报错后我改了一下:    ld -m elf_i386 -o eatsyscall eatsyscall.o 

然后就可以了




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Farmwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值