Author Topic: help make a com file with nasm  (Read 8023 times)

nobody

  • Guest
help make a com file with nasm
« on: April 11, 2005, 09:03:05 PM »
how in the world do I cmake a com file with nasm .

All I want to do is make a simple hello world com programe but I cant find any tutorials on just plain asm without windows or any extra stuff.

Can any one help?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: help make a com file with nasm
« Reply #1 on: April 12, 2005, 03:37:50 AM »
Well... there's a tiny hint in the Friendly Manual...



There's a *very* introductory "tutorial" on my web site... The "Clueless Newbie's Guide to Hello World"...



There really isn't much "to" a .com file... You want Nasm's "-f bin" (flat binary) output format (usually - there are other ways to do it...). That's Nasm's default, so you don't really need to specify "-f bin" on the command line - I like to do it "for clarity". You *do* need to specify an output file name - Nasm will default to "myfile" as an output file name, so "-o myfile.com" (dos cares about the extension, and won't run "myfile"... you could rename it...). In your source code, you need to specify "org 100h" (Nasm defaults to "org 0"). This doesn't "control" where the file is loaded - dos loads a .com file at 100h... in *some* segment... always. We're just informing Nasm of this fact (so Nasm can calculate the right value for "msg" and other labels).

You need to exit your program and return control to dos, some way. If you "just stop", the processor will continue to attempt to execute whatever's in memory next - hardly ever useful :) The "best" way to end is probably "mov ah, 4Ch"/"int 21h" - put whatever value you want to return to the OS in al... usually zero means "no error", non-zero indicates an error has occurred - but you can return any value you want (for use in a batch file, for example). A simple "ret" will also work - dos pushes a zero on the stack before starting your program, so "ret" transfers control to offset zero in "whatever segment". You'll recall that your code is loaded at offset 100h - the first 256 bytes are the "Program Segment Prefix" ("PSP"), and the first two bytes of that are "CD 20" - "int 20h", the "return to dos" interrupt (one of 'em). You can end with "int 20h" in your code, too. I prefer int 21h/4Ch.

For what goes between the beginning and the end, you'll want Ralf Brown's Interrupt List - covers dos (and bios) interrupts, ports, and memory - most of what you'll need for dos programming:



If you haven't heard, it is with great regret that I must inform you that dos is "dead"... well, "obsolete" anyway... or at least it isn't the "currently popular bandwagon". Dos still works, and personally I think it's a great "playground" in which to learn asm, but you probably don't want to spend *too* much time studying dos itself.

When you're ready to tackle 32-bit programming (it's *easier* in many ways!), Dr. Paul Carter's tut should probably be your first stop:



Best,
Frank

; nasm -f bin -o myprog.com myprog.asm

section .text

mov ah, 9
mov dx, msg
int 21h

mov ah, 4Ch
int 21h

section .data
msg db "Hello, World!$"

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: help make a com file with nasm
« Reply #2 on: April 12, 2005, 03:57:37 AM »
Sh*t!

org 100h ; !!!

Sorry,
Frank