You are not logged in.

#1 2013-10-26 12:38:48

Grant
Member
From: Italy
Registered: 2012-12-15
Posts: 246

[SOLVED] Running x86 asm files

Hello,

I need to run some 8086 assembly programs. That's what I've done:
-Installed dosbox and nasm
-compiled and linked my file with
 

 nasm -f elf myfile.asm 
  ld -m elf_i386 prova.o

- set up dosbox (basically setting my keyboard layout and mounting automatically the C virtual drive)
But when I try to run my program, dosbox says:

C:\>a.out
Illegal command: a.out.

I have also moved the exectuable file made by nasm/ld into the dosbox folder (indeed it can find it). But now what I have to do?

Greetings,
Grant.

Last edited by Grant (2013-10-27 17:46:35)

Offline

#2 2013-10-26 18:45:35

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Running x86 asm files

8086 or x86? x86 could technically include 8086, but usually refers to the 32-bit family (80386 and later). If you have assembly code that is intended to run on a computer less than (say) twenty years old, it probably wouldn't work on an 8086.

I'm also not familiar with DOSBox or using it with nasm, but it seems unlikely that it (DOSBox) should support ELF binaries, since most of the programs that one uses with it are in Portable Executable format (*.exe) or COM format (*.com). If you're using an ELF linker, you're probably compiling the wrong kind of executable to use it with DOSBox.

Where did you get the assembly code?

Offline

#3 2013-10-27 09:31:21

Grant
Member
From: Italy
Registered: 2012-12-15
Posts: 246

Re: [SOLVED] Running x86 asm files

Trent wrote:

8086 or x86? x86 could technically include 8086, but usually refers to the 32-bit family (80386 and later). If you have assembly code that is intended to run on a computer less than (say) twenty years old, it probably wouldn't work on an 8086.

I'm also not familiar with DOSBox or using it with nasm, but it seems unlikely that it (DOSBox) should support ELF binaries, since most of the programs that one uses with it are in Portable Executable format (*.exe) or COM format (*.com). If you're using an ELF linker, you're probably compiling the wrong kind of executable to use it with DOSBox.

Where did you get the assembly code?

8086 (which was the first x86 CPU). Which assembler should I use? May I ask you your way, if you have one?
Anyway I wrote the assembly code, it is a simple one to see if DOSbox and nasm can work together.

Offline

#4 2013-10-27 13:14:32

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Running x86 asm files

I don't write assembly code often, but when I do, it doesn't have to run under DOS. Usually I'm just analyzing the output of a C compiler and I use gas if I ever have to actually assemble something. I don't recommend it if you're interested in actually writing assembly code.

Since you want this to work for DOSBox, you need to tell nasm to generate an executable that will run under DOS. Like I said before, COM and PE (.exe) are likely candidates; ELF is only really used on *nixes. I don't have nasm, so I don't know what command-line arguments that would be, but this section of the manual suggests a command that would tell you how to do that, if Arch's version of nasm has support for such formats compiled in.

Offline

#5 2013-10-27 17:46:16

Grant
Member
From: Italy
Registered: 2012-12-15
Posts: 246

Re: [SOLVED] Running x86 asm files

Nasm is a multiplatform assembler and it can compile for both Windows (-f win32) and Linux (-f elf). But neither gcc nor ld are able to link win32 object files (.obj), indeed they say the file is not recognized.
I should use wine and get some Windows linker. But I can't do that each time I want to build an executable. I believe I'll use Windows directly, looks like the best solution.

Actually I don't use assembly to write programs, I do that just for didactic purposes.

Offline

#6 2013-10-27 20:37:57

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Running x86 asm files

Ah, my mistake, I forgot about the linking step... nevertheless, I'm glad you're on the right track now.

So wait, I'm confused. if you don't use assembly to write programs... what do you want to use nasm for?

Offline

#7 2013-10-28 15:14:16

Grant
Member
From: Italy
Registered: 2012-12-15
Posts: 246

Re: [SOLVED] Running x86 asm files

Trent wrote:

So wait, I'm confused. if you don't use assembly to write programs... what do you want to use nasm for?

My bad, I meant that I usually don't use Assembly to write programs, but we're studying it at school (where we, unfortunately, use Windows) and then I've to learn it.
I like Assembly, I'd never use it for everyday programming (like anyone else) though.

Offline

#8 2013-10-28 23:04:22

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Running x86 asm files

Ah! That makes much more sense now smile

Offline

Board footer

Powered by FluxBB