December 18, 2009

Why I Learned Assembly Language

Filed under: Main — Dan Gookin @ 12:01 am

Back in the early days of computers, when PCs were called microcomputers, most of the software you used was written by the computer operator. That’s you!

For years, the IBM PC, as well as Compaq PCs, came with the BASIC programming language in ROM. If you bought another PC, then you could use the BASIC programming language that came with DOS.

Including a programming language with the operating system was more-or-less normal back in the early days. The programming language of choice was BASIC.

In fact, the only computer I recall that didn’t come with a programming language was the Macintosh back in 1984.

You needed a programming language to write your own software, and lots of people did just that.

In addition to BASIC, you could buy other language. C wasn’t that popular back then, Pascal was. In fact, the Borland company made its fame and fortune by selling a Pascal compiler for $49. The competition sold their Pascal compiler for $499.

One cheap language you could get into was Assembly.

With Assembly language, you’re programming the processor directly. The code you write translates directly into the binary language used by the processor. Unlike BASIC or other higher level languages, Assembly didn’t need to be translated or compiled down to the machine code.

The advantages of programming in Assembly were that the code you wrote was very tiny and ran very fast. For example, a program in BASIC may occupy 48K of memory. The same program in Assembly may run in at 2K.

Back in the early 1980s, memory and speed were issues. Some software couldn’t run because of “Out of memory” errors. So it paid to write the code in Assembly, plus you got the advantage of speed.

The drawbacks to Assembly were many. Primarily Assembly takes a long time to code. You have to write all the functions yourself. So if I wrote an Assembly language program that displayed text on the screen, I had to write the function that displayed the text. That takes time.

Further, Assembly is not the easiest thing to learn. It’s time-consuming and intricate. Mistakes are extremely difficult to hunt down. A good debugger goes hand-in-hand with an assembler. In fact, I couldn’t have learned Assembly if it weren’t for a top-notch debugger I used. It really opened my eyes as to what was going on inside the computer.

Then again, I loved programming in Assembly. Doing so really made me feel like I was in charge of the computer.

I wouldn’t recommend learning Assembly today. Sure, it’s still fun and all that, but over it’s impractical for developing today’s larger programs. Yeah, I’ve done Assembly on the PC, and it’s fun to reminisce. But otherwise, it was an interesting expedition for me back in the early days of PC history.

9 Comments

  1. Dan- I guess in the early 80s most assembly was for the 68000 processor as that was the main processor used by most home computers, right? Than after that I guess when the PC came out that the 8086 assembly became popular and than that lead to the MASM vs TASM war. Was the debugger you used similar to debug that you still find in the Windows console today? I do want to learn assembly. I recall you mentioned before you like Randall Hyde’s “Art of Assembly”. I read some of that book but it was too long and I didnt have confidence I could learn assembly from HLA. I think assembly is good to learn, I just havent found a beginning assembly book where I dont get lost.

    Comment by BradC — December 18, 2009 @ 8:41 pm

  2. I guess in the early 80s most assembly was for the 68000 processor as that was the main processor used by most home computers, right?

    Not really. The 68000 was very expensive and rare in a microcomputer. I learned assembly on the Z80, which was an 8080 knock-off. It was a popular chip back then. I also learned some 65C02 for the Apple IIGS system. The IBM PC came with an 8088, which was the 8/16 bit version of the 8086. It was also a cousin of the Z80, so learning Assembly on the PC was a snap for me.

    …the MASM vs TASM war

    Very real. Borland undercut Microsoft drastically with the price of their compilers. TASM, the Turbo Assembler, was my favorite. MASM was sluggish and awkward. It actually wouldn’t do some things that the processor could, which was really frustrating. The one story I like to tell is of an assembler used by a developer friend of mine. It was light and fast and they enjoyed it. But they were beta testing it. Turns out, Microsoft offered that assembler’s developers one million dollars for their code. They were just two guys “in a garage,” so they took it. Microsoft quickly destroyed the buried the code, never to be seen again. And then Microsoft continued to sell the sluggish and gross MASM.

    Was the debugger you used similar to debug that you still find in the Windows console today?

    No. It was beautiful. It was full screen, showing registers and memory, and would let you page in and out of it to see your program run. I was amazed by the code. I’ve not found anything as beautiful and as precise as it ever since.

    No Starch Press came out with an Assembly Language book a while back. I think I link to it on the C programming site, http://www.c-for-dummies.com. It’s the best I’ve seen in a long time, very well-written.

    Comment by admin — December 18, 2009 @ 10:43 pm

  3. Now if I sat you down in front of a Z80 computer with TASM and whatever debugger you used, would you be able to create a decent program?

    In offtopic news, my 8086 computer can VNC into a computer.

    Comment by linuxlove — December 19, 2009 @ 7:31 am

  4. TASM was an 8088/8086 program/debugger. But to answer your question, I could easily pick up Z80 or 8088 again. I have all my old references (because I love books). Creating a decent program, however, would be problematic; the development time is just so huge with Assembly that “decent program” becomes a major obstacle.

    For example, in Assembly you have to do all the math. I was just reviewing some of my older code and it took several lines simply to multiple a value by 10. That’s because you’re dealing with processor registers and binary math. Of course, once you have the code, you can re-use it. I had many, many Assembly modules I’d use over and over but yet it still took a while to cobble together a program.

    Here is a sample from a modem program I wrote in 1987. This code is part of a larger Date and Time module. All this code does is get the current date of the year:

    assy-sample

    That all had to be debugged and tested before it found its way into the final program. A lot of work!

    Comment by admin — December 19, 2009 @ 8:54 am

  5. I heard back in the 80s there were some guys too cheap to even get an assembler and would code everything in binary. I imagine they would copy/paste binary instructions from a text file that they kept. And then probably they would debug everything with printf statements, or whatever the assembler they use in assembler for print statements.

    Comment by BradC — December 19, 2009 @ 11:21 am

  6. There were lots of cheapskates! You could use — and still can use — the DEBUG program to write Assembly on a PC. In essence, DEBUG is the cheap Assembler for the PC. You can also debug with it, but it’s a serial (stream-oriented) debugger, which is awkward.

    I talk about using DEBUG in this post. The techniques I use there are the same you write of, when you talk about using a text file to create binary.

    Comment by admin — December 19, 2009 @ 11:25 am

  7. The first language I started to learn was BASIC, in high school. My first exposure to assembly language was a few years later in college.

    Using a dummy terminal connected to a mainframe that I never saw, I ran assembly language on an emulator for an 8 bit processor. There was an H register and an L register (high and low), an A register (accumulator), a C register (counter), and so forth, each an 8 bit register that could only count as high as 255. Unlike the 8086 capability to group, for example, the AL and AH as AX, there was no inherent 16 bit capability. Anything shifted left out of the L register had to be moved to the H register manually.

    Also, the only commands we learned in class were the processor instruction set. System and BIOS calls, if they existed on the emulator, were never mentioned. And the processor instruction set was relatively limited; there was no MUL (multiply), instead you had to count a number of ADDs to accumulate a result. The assignment for the semester was to write a crude operating system. No small task.

    I never learned if this software emulated an actual processor that existed in the real world, or if it was intentionally stultified to be a teaching tool. Either way, I saw no practical application.

    About two years later I saw MS-DOS for the first time and became aware of the 8086 and its assembler capabilities. 16 bit registers and INTs opened up a vast array of possibilities compared to what I previously knew.

    Comment by sean bernard — December 20, 2009 @ 1:15 pm

  8. Yes, that was fun stuff back then. I never used an emulator, and never worked on a mainframe, other than toying around in college. Thanks for sharing your memories!

    Comment by admin — December 20, 2009 @ 1:19 pm

  9. sean- You actually only need about 3 registers to program in assembly because each machine instruction can only handle up to 3 address parameters at a time. And I dont think there were hardly any system calls on home computers back then since, everything ran in 1mb of memory, everything including the OS, the program (only one program at a time that controlled all of the CPU) and program data all fit in that 1mb.

    Comment by BradC — December 20, 2009 @ 6:43 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress