VOGONS


Assembler 3.01 for DOS

Topic actions

First post, by JShone2025

User metadata
Rank Newbie
Rank
Newbie

Hi all.

I asked ChatGPT to code me hello world in assembler then I have tried various versions of MASM and TASM to get the thing compiled but it always errs out!
Can anyone spot any obvious problems causing it not to compile?

; ---------------------------------
; HELLO.ASM
; Clean MASM/TASM DOS .EXE
; ---------------------------------

.MODEL SMALL
.STACK 100h

.DATA
msg DB 'Hello World',13,10,'$'

.CODE
MAIN PROC
mov ax, @DATA
mov ds, ax

mov dx, OFFSET msg
mov ah, 09h
int 21h

mov ax, 4C00h
int 21h
MAIN ENDP

END MAIN

Appreciate it if this is not the right place to post this, but thought I would give it a shot!

Reply 1 of 7, by Thandor

User metadata
Rank Member
Rank
Member

It would help if you write which error you get exactly 😉.

In my opinion you’d better ditch AI and watch videos like this or check out the videos and website of ChibiAkumas (also on YouTube); he has great information on coding in assembly. Bonus of these videos is that they explain what happens so it has more educational value opposed to copy/pasting stuff from AI 😀.

thandor.net - hardware
And the rest of us would be carousing the aisles, stuffing baloney.

Reply 2 of 7, by DaveDDS

User metadata
Rank Oldbie
Rank
Oldbie

I never cared for MicroSofts way of doing assembly/directives etc., assembly shouild be SIMPLE as close as possible to the actual code being generated...
Here is your program converted to build a .COM with my own ASM86 embedded assembler:

        ORG     100h
MOV DX,#MSG
MOV AH,#09h
INT 21h
MOV AX,4C00h
INT 21h
MSG: STR 'Hello World'
DB $0A,$0D,'$'

I only have a fairly old version of MASM which chokes on your original code.
R:\> masm t;

Microsoft (R) Macro Assembler  Version 4.00
Copyright (C) Microsoft Corp 1981, 1983, 1984, 1985. All rights reserved.


51016 Bytes symbol space free

0 Warning Errors
13 Severe Errors

But.. TurboAssembler handles it fine!

R:\> tasm t;

Turbo Assembler  Version 1.0  Copyright (c) 1988 by Borland International

Assembling file: T.ASM
Error messages: None
Warning messages: None
Remaining memory: 499k

R:\> link t;

Microsoft (R) 8086 Object Linker  Version 3.05
Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved.

R:\> t

Hello World

Here is with my own ASM86 on the above converted code:
R:\> asm86 t1 -t

Pass 1... Pass 2... 0 error(s).

R:\> hexfmt t1.hex -bt w=t1.com

Base address is 0100, Load address is 0100
Total of 26 bytes loaded, Image size is 26
ROM checksum is CEBE

R:\> t1

Hello World

R:\>

Dave ::: https://dunfield.themindfactory.com ::: "Daves Old Computers"->Personal

Reply 3 of 7, by DaveDDS

User metadata
Rank Oldbie
Rank
Oldbie
Thandor wrote on Today, 10:27:

... In my opinion you’d better ditch AI ...

Agreed completely - assembly is most suitable now-a-days for either 1) tricky stuff that you can't easily do otherwise or 2) super-efficent operations

If you want a comouter to code for you - why not just use a high-level languaeg?

There's still lots of good ways to learn assembly - Videos can help, but I don't trust all "content creators" to be decent coders...

To start, get a good book on 8086 asembly.

And look-at/work-through examples - here's what I suggest:

Grab my Micro-C compiler - I've recently published source code, it's PC86 library source has LOTS of examples of 8086 assembly language ranging from very simple to fairly complex.

Also, if you happen to be famlier with C, make use of the compiler itself to compile stuff - you can use the -A option to generate a .ASM of the code the compiler generates. You can try doing various things, and how the compiler coded it!

Dave ::: https://dunfield.themindfactory.com ::: "Daves Old Computers"->Personal

Reply 4 of 7, by Baron von Riedesel

User metadata
Rank Member
Rank
Member
JShone2025 wrote on Today, 10:13:

Hi all.

I asked ChatGPT to code me hello world in assembler then I have tried various versions of MASM and TASM to get the thing compiled but it always errs out!
Can anyone spot any obvious problems causing it not to compile?

Code looks ok, but requires a Masm version that understands the so-called "simplified segment directives". IIRC, that means it must be at least Masm v5 ( or perhaps v5.1 ). OTOH, in case you're using a Masm version >= v8.00, you'll have to specify the -omf cmdline option, because Masm's default output format has been changed to COFF with this version, and 16-bit code cannot be handled properly with COFF.

Reply 5 of 7, by RetroPCCupboard

User metadata
Rank Oldbie
Rank
Oldbie
DaveDDS wrote on Today, 11:28:

Agreed completely - assembly is most suitable now-a-days for either 1) tricky stuff that you can't easily do otherwise or 2) super-efficent operations

And 3) learning how a computer actually works. These days most people don't know, or care, how a computer actually works. I find it super-interesting.

I have an 8088 machine that I bought specifically for this purpose. OK, I could have used an emulator, but it's not the same. I know modern CPUs are ridiculously more complicated, which is why I prefer to learn about a basic CPU.

I think you will never write ASM better than a compiler for a modern CPU. Branch prediction, pipeline behaviour, cache behavior, multiple cores, workarounds for CPU flaws and characteristics etc. Just too much to wrap my head around. Haha.

Reply 6 of 7, by DaveDDS

User metadata
Rank Oldbie
Rank
Oldbie
RetroPCCupboard wrote on Today, 17:46:

And 3) learning how a computer actually works ...

Yes, and I agree that most compilers will do a better job than a casual to moderate .ASM programmer on modern CPUs, but I have done jobs where some section timing was critical down the individual cycle accuracy, and you just can't beat assembler in cases like that...

I suspect that the word "DOS" in subject might indicate not trying to code .ASM for later generation architectures.

For people interested in learning how a "computer" actually works, don't need specifically to learn about "Pee-Cee" ... and want to start with something simple (The best .ASM programmers I've known started on simple 8-bit processors where there wasn't much else - unless you were happy with interreted BASIC in some cases)

You could use some of my vintage 8-bit system emulatords:

MOD8 = 8008
Altair = 8080
Horizon/Vector = Z80
D6809 = 6809

These have full "inside the CPU" debuggers (you can watch it run)- and all of them come with lots of working .ASM programs you can look at.

And I think they are pretty good/accurate = I've been building a 6809 based controller for part of my "Home Control" system and often when writing/testing, rather than go "fire up the real thing", I just load the code under D6809.

These are available (free) on my site - I'll warn you that they were written many years ago and run under DOS - but they do work very well in DosBox.

Dave ::: https://dunfield.themindfactory.com ::: "Daves Old Computers"->Personal

Reply 7 of 7, by bartonxp

User metadata
Rank Member
Rank
Member

And when you're compiling code for 16-bit operating systems, a little ASM makes sense. I think old programming books are the best source, there's pages of code to transpose like a recipes in a cookbook.

I love that you mentioned 'learn how the computer works'. One of my interview questions for high-level programmers is about general registers and their purpose.