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?
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.
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:
1 ORG 100h 2 MOV DX,#MSG 3 MOV AH,#09h 4 INT 21h 5 MOV AX,4C00h 6 INT 21h 7MSG: STR 'Hello World' 8 DB $0A,$0D,'$'
I only have a fairly old version of MASM which chokes on your original code.
R:\> masm t;
1Microsoft (R) Macro Assembler Version 4.00 2Copyright (C) Microsoft Corp 1981, 1983, 1984, 1985. All rights reserved. 3 4 5 51016 Bytes symbol space free 6 7 0 Warning Errors 8 13 Severe Errors
But.. TurboAssembler handles it fine!
R:\> tasm t;
1Turbo Assembler Version 1.0 Copyright (c) 1988 by Borland International 2 3Assembling file: T.ASM 4Error messages: None 5Warning messages: None 6Remaining memory: 499k
R:\> link t;
1Microsoft (R) 8086 Object Linker Version 3.05 2Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved.
R:\> t
1Hello World
Here is with my own ASM86 on the above converted code:
R:\> asm86 t1 -t
1Pass 1... Pass 2... 0 error(s).
R:\> hexfmt t1.hex -bt w=t1.com
1Base address is 0100, Load address is 0100 2Total of 26 bytes loaded, Image size is 26 3ROM checksum is CEBE
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!
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.
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.
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:
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.
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.