如何使用nasm和gcc在linux下编译此asm代码? [英] How to compile this asm code under linux with nasm and gcc?

查看:91
本文介绍了如何使用nasm和gcc在linux下编译此asm代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读的书中包含以下源代码片段.因此,我创建了一个asm文件并精确键入.然后使用nasm命令( nasm -f elf test.asm ),然后尝试使用 gcc ( gcc test.o -o test ),然后出现以下错误.

I have the following source snippet from a book that I'm reading now. So I created an asm file and typed exactly. Then used nasm command (nasm -f elf test.asm) then tried to compile into an executable file by using gcc (gcc test.o -o test) then I get the following error.

错误:

ld:警告:忽略文件test.o,该文件是为不受支持的文件格式(不是要链接的体系结构(x86_64))构建的

ld: warning: ignoring file test.o, file was built for unsupported file format which is not the architecture being linked (x86_64)

源代码:

[BITS 16]

[SECTION .text]

START:
    mov dx, eatmsg
    mov ah, 9
    int 21H

    mov ax, 04C00H
    int 21H

[SECTION .data]

eatmsg  db "Eat at Joe's!", 13, 10, "$"

我想源代码与当前的CPU版本不兼容(这本书很旧...).

I guess the source code is not compatible with current generation of CPUs (the book is old...).

如何修复此源代码以在x86_64 CPU下运行?

How do I fix this source code to run under x86_64 CPUs ?

推荐答案

如果您想继续使用那本旧书来学习基础知识(这很好,在继续学习现代知识之前学习基础知识/旧方法没什么问题.OS),则可以在DOSBox或FreeDOS VM中运行它.

If you want to continue using that old book to learn the basics (which is just fine, nothing wrong with learning the basics/old way before moving on to modern OS), you can run it in DOSBox, or a FreeDOS VM.

这篇关于如何使用nasm和gcc在linux下编译此asm代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆