Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:26 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Real programmers use machine code

     Page 1 of 2    
Author Message
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 06:44pm 28 Feb 2013
Copy link to clipboard 
Print this post

Over coffee with aargee the other day I mentioned the attached gem which is a posting on the "Usenet" 23 years ago and I thought that others might be interested in reading it also.

2013-03-01_042242_Real_programmers_program_in_machine_code.p df

It shows just what the early programmers went through to create even a simple game. I know I would not have the patience to program like this, the contrast with today's optimising compilers is huge.

By the way, for the "youngsters" out there. The Usenet was a forerunner to today's Internet. Every night computers would dial up each other (using telephone lines and modems) and transfer a series of messages which could include emails or postings to various newsgroups. Sometimes a message would hop through a dozen or more computers before it reached you.

You can see at the top of the posting the names of the computers that this particular posting travelled through (each separated by an exclamation mark). The big trick was to find someone (usually an university) that would let you dial in to collect your messages. Once you had that privilege, you were connected!

Geoff
Geoff Graham - http://geoffg.net
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 07:17pm 28 Feb 2013
Copy link to clipboard 
Print this post

  Geoff said  
It shows just what the early programmers went through to create even a simple game. I know I would not have the patience to program like this, the contrast with today's optimising compilers is huge.


What a lovely article. I got a lump in my throat reading it. It reminded me very much of some of the Feranti weapons systems computers in the services in the late 70's where at least the opcode was in mnemonics, but all the operands and addresses were in binary. "Fun".

And there was the defence message switch computer for the army comprising aisles (like a supermarket) of "suites" all full of OC44 Ge transistors. If one got it's black paint scratched used to switch at the fluoro rate and give the maintainers a hard time.

Having said all that, I still have a soft spot for my 6800 days when I used to enter all programmes via a hex keypad and 7seg led display - no mnemonics.
David M.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 07:21pm 28 Feb 2013
Copy link to clipboard 
Print this post

The mind boggles! I remember doing a one week course in logic and digital electronics at the Uni of Tas in about 1977. As an exercise we all had to initialise a PIA and a UART in hex. before we got to synchronise a voltage output with the mains in Assembler. The Assembler was a breeze compared to the hex initialisation code - no wonder I stayed with my day job as a metallurgist.

Greg

err...PIA - parallel interface adapter
UART - universal asynchronous receiver transmitter..... sorry kids!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 08:22pm 28 Feb 2013
Copy link to clipboard 
Print this post

  Quote  err...PIA - parallel interface adapter
UART - universal asynchronous receiver transmitter..... sorry kids!


Sounds like a 6820 and 6850 (or the 65 equivalent) Two whole 8 bit addressable ports, wow!
David M.
 
Nick

Guru

Joined: 09/06/2011
Location: Australia
Posts: 512
Posted: 08:44pm 28 Feb 2013
Copy link to clipboard 
Print this post

Completely true. Programming in machine code (assembly language) is an art form.

Not so much the language itself. The commands are actually very simple where most instructions deal with very basic data manipulations. What scares most people is that you have to put so many of them together to create something useful.

Nothing as simple as PRINT"HELLO" in M/L. This is an entire program in itself under M/L... but boy, is it fast!

The "art" side of it has more to do with the fact that computers back then were far more limited in speed and resources as they are today. 1 to 4 Mhz.. not Ghz and the memory constraints were a challenge. Nowadays, you can't write a mouse driver in less than several hundred K. The mouse drivers of today exceed the memory capacity of the Commodore 64!!

I remember trying every trick in the book to look for ways of optimising my Assembly code. Everything from code optimisation, sharing subroutines, unrolling loops to self modifying code just to squeeze every cycle of speed from my 1Mhz 6809.

Tedious, torturous but in the end worthwhile as you sitback and watch your code run... a true work of art.

Just don't expect others to be able to understand the logic easily.

Nick
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:16pm 28 Feb 2013
Copy link to clipboard 
Print this post

  Nick said  Just don't expect others to be able to understand the logic easily.


You could always tell a machine code programme written by an engineer - No b...y documentation! (some of us, excepted). I've had a few to disassemble and trying to get inside someone else's brain nigh on imposible. Often easier to start from scratch and write a new one.

But yes, it is an art form and I think the satisfaction level when it works is way above that of a high level programme. It also forces the writer to comment the programme.

The speed difference is like writing a picaxe programme and then writing the same thing in pic assy especially when doing math. Faster than lightning.
David M.
 
Nick

Guru

Joined: 09/06/2011
Location: Australia
Posts: 512
Posted: 09:48pm 28 Feb 2013
Copy link to clipboard 
Print this post

I guess it depends on what market your working for.

Games, don't need to be read by others. It's a closed product.
Other applications need to be clear for others to modify or debug.

Nick
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 09:54pm 28 Feb 2013
Copy link to clipboard 
Print this post

GOOD code should always be easy to read.
Even closed-source programs should be well commented, laid-out and organised,
even if you are the only one likely to see the source.
High performing programs and well written code are not mutually exclusive concepts.
Software engineering should not be a lost art.

If you had to use some unusual code trick/technique to achieve something impressive, all the more reason to document and comment it. You may need that same technique in a different program.


Edited by djuqa 2013-03-02
VK4MU MicroController Units

 
Nick

Guru

Joined: 09/06/2011
Location: Australia
Posts: 512
Posted: 10:27pm 28 Feb 2013
Copy link to clipboard 
Print this post

Agreed, but how much documentation? Some document every line of code.

I prefer to document each functional module, listing variables in/out. I can pickup any of my code from 20 years ago and fully work it out. I guess it helps when you have a certain programming style. It's hard to explain but I can do it easily.

I must stress, that my games are not designed for anyone else but me anyway so this approach works. I would add more documentation if it were for others to interprete.

I once knew a guy who programmed M/L using a disk zapper (sector editor). No assembler just raw hexadecimal values right on the disk. It was on a TRS-80 model 3 (Z-80) and he could read the hex numbers in the proper symbolic meaning as if he were reading a book. Freakish!

I know others who coud look at a block of assembly, do a mental count of the cycles used and pinpoint areas where code be needs to be altered just to save a few cycles.

Nowadays, who cares. Computers are so fast, it doesn't matter. Wait for Intel to release a faster CPU and the next GPU. We can be as sloppy as we like.

These are guys who probably leave dirty socks and clothes on the floor but their M/L code is the cleanest you'll find.

Nick






 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 10:40pm 28 Feb 2013
Copy link to clipboard 
Print this post

Documentation and comments ARE NOT the same.
All programs should have a few relevant comments (Not every line), but the full documentation should be a separate document as you describe.
It should be similiar to the excellent documentation that Geoofg has done for MMBasic.
Setout every function, statement, constant, quirks, tips as separate pages or at least a paragraph.

I fall in the category of messy house, but beautiful code.

Edited by djuqa 2013-03-02
VK4MU MicroController Units

 
wizged
Newbie

Joined: 05/02/2013
Location: Australia
Posts: 13
Posted: 12:34am 01 Mar 2013
Copy link to clipboard 
Print this post

I find that there is something special about programming in the language that the chip itself understands. However, there comes a point where it simply becomes a pain and its better to use a higher language to just get the job done. I reached that point in my current project yesterday actually and realised I need to keep the machine language component (Z80) to the essentials and shift all the tricky bits to MMBasic.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 12:57am 01 Mar 2013
Copy link to clipboard 
Print this post

I still know/remember what "3E00", or "C35080" means in Z80 machine code.
I could read hex dumps easy as i just saw them in my mind as mnenomics.
The TRS-80 model 1 level II basic roms was disassembled using Rodnay Zaks book, after a while somewhere half way the book was not needed anymore. :)
Changing the ROM was one of my goals, to have a few more basic commands and have some routines added.
At that time i was about 15, now at 48 i get this same feeling when i try to design the smallest possible pcbs.
My daily work is in C# and javascript. Both reasonable enjoyable to use.
C is ok, it is a reasonable thin layer (compiler) and it allows to inject assembly code.
When i got my first PC i build small computers with a z80, i used the Microprofessor roms as a start to have single stepping and debugging, all through a serial port.





Edited by TZAdvantage 2013-03-02
Microblocks. Build with logic.
 
wizged
Newbie

Joined: 05/02/2013
Location: Australia
Posts: 13
Posted: 01:20am 01 Mar 2013
Copy link to clipboard 
Print this post

Hmm, LD A,0 and JP 8050 I see. I admit having to look the first one up in Rodnay's book (which has sadly fallen apart a bit now) but the second was still there after 30 odd years. Egad, I'm a bit worried now - maybe I should get out more
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 01:53am 01 Mar 2013
Copy link to clipboard 
Print this post

  MOBI said  
You could always tell a machine code programme written by an engineer - No b...y documentation! (some of us, excepted). I've had a few to disassemble and trying to get inside someone else's brain nigh on imposible. Often easier to start from scratch and write a new one.

True, but often we 'engineers' were busy putting out fires, sometimes literally at the smelter, and to do things quickly there was so much redundant code that it just made everything harder to figure out. We'd have loved to have one of the 'real' programmers working on our projects but they lived up with the accounts and general ledger stuff with the IBM 370 and the girls on the 2780 punch machines - bliss! Trying to get something working better down in the areas that made the money was impossible.

Speaking of documentation - it used to amaze me how many yards (sorry, meters) of documentation was required for DEC's RT11 O/S that we used quite a lot. Now that was an O/S - can't remember how much room it took up but it was just a few K and stayed that way for a long time. Every couple of years a few bytes would be changed and those three yards of white backed 'D' ring folders would all be updated.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:55am 01 Mar 2013
Copy link to clipboard 
Print this post

I had to look up egad.
The first description says it all.

http://www.urbandictionary.com/define.php?term=egad

Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:04am 01 Mar 2013
Copy link to clipboard 
Print this post

Maybe 'Alors' - or from your old neighbours 'Mein Gott' would have been better for you TZ. That urban dictionary looks pretty handy - mind you I'm not impressed with some of the spelling prowess. The No.2 respondent can't spell 'exclamation or 'excitement' and No. 4 can't spell 'convenient'. No. 3 looks pretty good though - obviously older than 60!

Greg
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 03:10am 01 Mar 2013
Copy link to clipboard 
Print this post

RT11 had a "famous" (well, it probably wasn't!) line of code (with a prominent warning):
JSR SP, @(SP)+

5-hole paper tape anyone?

John
--- And do real programmers eat quiche or not?Edited by JohnS 2013-03-02
 
donmck

Guru

Joined: 09/06/2011
Location: Australia
Posts: 1313
Posted: 09:15am 01 Mar 2013
Copy link to clipboard 
Print this post


Loved the Z80 and machine code:

PBUFF was a Z80 printer buffer I designed that could be configured from 8K to 4Mb of DRAM. Hardware Interfacing was done with only a single 74LS00 and a 74LS04. The magic was achieved with software and no hardware multiplexing was used. Used many undocumented op codes.

Full source code with comments at:
http://www.dontronics.com/z80.html

Yes 4Mb running on a Z80. Sold it all over the world in the days well before the internet as we know it.

Also recompiled 8080 Basic into my own version of z8Tbasic, which is included in this above archive.

Today my brain is scrambled, and my get up and go has got up and went, so I don't see me doing anything like this in future.

Don...
https://www.dontronics.com
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 11:58am 01 Mar 2013
Copy link to clipboard 
Print this post

When my early efforts at writing in PL/1 failed and I couldn't work out what had gone wrong, I would take the core dump to my friend Reg in the Systems Group and he could read it like a novel. I was overawed by such prowess.

My own expertise with machine language came with Jim Rowe's Educ8. All 128 bytes of memory had to be entered with switches - set the 8 switches and press the Load switch. The one nice feature, implemented in hardware, was that the address was automatically incremented after Load was pressed. Bliss!! The downside was that each time you turned on the computer, you needed to reload the program by hand, that is until I got it to read from a tape, but even then I had to hand enter a short loader first. After that experience I was happy to rely on Assemblers, Compilers and Interpreters, but the sense of achievement was never quite the same.

HughEdited by shoebuckle 2013-03-02
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 12:20pm 01 Mar 2013
Copy link to clipboard 
Print this post

The PDP-11 had such sensible hardware you could (and did) (*) boot it from disk by toggling the bootstrap in using the console switches.

Hardware has got worse and worse ever since :(

Imagine keying in the PIC32 bits needed to read an SD card to boot up!!

(*) well, the core-based machines could just be turned off and then next day on again and they carried on where they left off - bliss :)

JohnEdited by JohnS 2013-03-02
 
     Page 1 of 2    
Print this page
© JAQ Software 2024