Author Topic: Looking for .COM program sources in NASM Assembly  (Read 13553 times)

Offline amoroso

  • Jr. Member
  • *
  • Posts: 3
Looking for .COM program sources in NASM Assembly
« on: September 05, 2022, 01:22:56 PM »
I'm looking for source code of MS-DOS .COM programs in real-mode 8086 Assembly written in NASM syntax. Any repositories or recommendations?

I'm learning Assembly programming under MS-DOS (and MikeOS) and cross-developing on Linux with NASM. To avoid the complexity of x86 segmentation, for the time being I prefer to focus on single-segment programs, as I plan to write small programs anyway. So I'd like to study examples of how such systems organize and reference data and code. I searched a bit but found remarkably little .COM code.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Looking for .COM program sources in NASM Assembly
« Reply #1 on: September 05, 2022, 02:38:16 PM »
Hi Paolo,

Welcome to the forum.

Have you looked in Example Code? It is not well indexed, but there should be at least some DOS .com code there.

I'll try to get back to you with more tips.

To others... Paolo Amoroso was sent here from clax86.

Best,
Frank


Offline amoroso

  • Jr. Member
  • *
  • Posts: 3
Re: Looking for .COM program sources in NASM Assembly
« Reply #2 on: September 05, 2022, 03:41:31 PM »
Thanks Frank, it didn't occur to me to check NASM's source tree as I assumed it would contain at most some test code like that.

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 373
  • Country: br
Re: Looking for .COM program sources in NASM Assembly
« Reply #3 on: September 05, 2022, 05:08:23 PM »
MS-DOS COM files are nothing more than a single binary with only ONE segment. All selectors points to the same segment (CS = DS = ES = SS) and there are no additional sections.

COM files are inherited from the old CP/M and not used anymore (it's not even supported on Win10 anymore!).

The first 256 bytes of this segment is reserved to PSP (Program Segment Prefix), where you can get the command line, and other things. The source code structure is very simple on NASM:
Code: [Select]
  bits 16

  org  0x100    ; skip the PSP

  ; Your program start here
_start:
  ...
Here a simple 'Hello, World' in COM format:
Code: [Select]
  bits  16

  org   0x100

  ; start here
  lea   dx,[msg]
  mov   ah,9        ; PrintStr (DOS service).
  int   0x21

  mov   ax,0x4c00   ; Exit (DOS service)
  int   0x21

msg:
  db    `Hello, world\r\n$`

Offline amoroso

  • Jr. Member
  • *
  • Posts: 3
Re: Looking for .COM program sources in NASM Assembly
« Reply #4 on: September 05, 2022, 07:48:49 PM »
Thanks Frederico, .COM files not being used anymore isn't an issue as I'm learning 8086 Assembly mostly for my interest in retrocomputing.

I see an interesting differences between your hello world code and the similar demo in Wikipedia's NASM entry: your code doesn't declare sectons.

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 373
  • Country: br
Re: Looking for .COM program sources in NASM Assembly
« Reply #5 on: September 06, 2022, 12:15:41 PM »
Thanks Frederico, .COM files not being used anymore isn't an issue as I'm learning 8086 Assembly mostly for my interest in retrocomputing.

I see an interesting differences between your hello world code and the similar demo in Wikipedia's NASM entry: your code doesn't declare sectons.
As I said before: COM files don't have sections.
You CAN use sections, but `.text` (or _TEXT) must be the first one, and ORG 0x100 must be there. AND all the sections must be mapped in a single segment.
« Last Edit: September 06, 2022, 01:20:58 PM by fredericopissarra »

Offline alCoPaUL

  • Jr. Member
  • *
  • Posts: 74
  • Country: ph
    • Webpage
Re: Looking for .COM program sources in NASM Assembly
« Reply #6 on: December 29, 2022, 09:53:55 PM »
there's this old asm book that was released and the 386 chips were already in the market and this book had examples in real mode that has e(letter)x registers being used. idk what assembler was used but it was like doing some unreal programming..

i totally photocopied it from our university library.. it's titled "ibm pc assembly (and other words)" or somehow like that.

imma find my book stash and list the title..

update: sadly, the cover and the copyright page were lost. it just listed the e(letter)x registers associated or to be used with double word "dd" values as data definitions.
« Last Edit: December 29, 2022, 09:59:54 PM by alCoPaUL »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Looking for .COM program sources in NASM Assembly
« Reply #7 on: December 30, 2022, 05:10:44 AM »
Kip Irvine, perhaps?

Best,
Frank