Some Assemblance of Order
I don't do any machine or assembly language coding any more, but I still have tender feelings in that direction. Assembler is fun: you have total control of the machine, and it runs so darn fast you can't blink or you'll miss it. You can write programs that are smaller and faster than is ever possible with any other language. Although it looks horribly daunting at first, there are really only a dozen or so basic instructions that you use over and over again. I think there is something quite pretty about listings of assembler code, and I truly miss seeing them in magazines.
Some of the fun things I've done with Assembler language include:
- Locking up the machine
- Turning on every light on the keyboard
- Having the machine reboot
- Locking up the machine totally
- Making awful noises come from the speaker
- Wiping out sections of my hard drive
- Filling up the screen with junk
- Damaging BIOS data
- Locking up the machine totally and completely.
- Locking up the machine totally and completely and without recourse.
- Locking up the machine so totally and completely that I wondered if it would ever work again.
- And every now and then, creating a useful program.
My experience with machine language goes back to TRS-80 days, when I was the proud owner of a Radio Shack Model I, a 4K fire-breathing 2 MHz Z-80. Yes, that's two, not twenty, and certainly not 200. Two. And it was FAST! You may think I'm joking, but this was the days of slide rules and mechanical adding machines. This puppy was a whole lot faster than any of that, The 4K memory was a bit of a lie : it was really 1.9K because more than half of it was BASIC-In-Rom (a mantra from the early days: basicinrom, basicinrom, basicin..). Basic was fun. but I wanted more power.
Radio Shack tempted me with ads:
With T-Bug, it is possible to program in machine language on a level I BASIC TRS-80
That was a 1978 blurb for a $14.95 tape you could load into your TRS-80. Although fifteen bucks was worth a lot more then then it is now, it was still cheap enough that I popped for it. I also bought myself a copy of the The Z-80 Microcomputer Handbook by William Barden. I still have that: it's dig eared and falling apart but still here. It makes me smile to look at it.
Look carefully at the phrasing of that ad. It said that it's "possible" to program in machine language. Indeed it is. If you agree that entering "ED 00" for a "LOAD BC" instruction is covered under the "possible" umbrella, then indeed it was possible to write programs. Painful, slow, frustrating, error-prone, but certainly possible. I think it could single-step, but that's about it. I gave up on T-Bug and wrote ac really awful assembler in Basic. It didn't do much, but it let me use mnemonic codes like "LOAD BC, STUFF" and it would figure out where STUFF was.
My next brush with bare metal programming was Radio Shack Model II's. Big, 64K 4 MHz Z-80's. The OS had a limited batch file language, but you had to type "DO" ahead of every batch file you wanted to run. I found that annoying, so I figured out how to write simple little programs that could run these without having to type "DO". These had a debugger that was just enough better than T-BUG that I could do this kind of thing fairly easily. I did a fair amount of little programs; to this day when I see a hex C9, I think "RET" (Return).
Then came IBM. Man, when I first ran IBM's DEBUG, I was in seventh heaven! Imagine: you could disassemble other peoples programs and you could enter mnemonics rather than hex instructions. A good thing that was, because RET was now C3!
Eventually, I outgrew DEBUG and needed to buy a real assembler. I bought Microsoft's MASM, which wasn't all that great at first, but later versions kept getting better and better. Eventually you didn't even have to worry abouut pushing and popping your registers: you's just say your subroutine "USES BX" and the MASM took care of the details. Neat.
But times change. As fun as all that is (and it really is fun, and mentally stimulating too), it's also fun to write in Perl, and for the very few times when that is too slow, C is as close as I get to the bare metal. I don't have the time to code machine language.
Still, someday, when things slow down and I don't need to do so much, I'd like to take it up again. Just for fun. Just because the listings with their perfect columns of repetitive instrictions are comforting. The alluring simplicity of the instructions melds with the intense concentration and attention to detail and is almost hypnotic. I remember a conversation with a friend who said "It changes your brain". I think it does. It can be both relaxing and incredibly stimulating. I've programmed in Basic, C, Perl, Cobol: those can be challenging too, but nothing quite has the same kick as raw assembly language.
Here's one of the last bits of assembler I ever wrote. It was part of an MSDOS C program (An alternative to DOS "dir"):
pusha call setdta mov ah,0x4e mov dx,Wild mov cx,val int 0x21 jb no_more d_loop: mov si,pd mov ax,[si+30] cmp al,'.' jz jfnext cmp show,1 jz doshow mov si,pd mov ax,[si+21] and ax,Dir_Mask jz noshow add si,30 push si mov ax,Wild push ax call savewild call makename pop ax pop ax push 0 push Any_Mask push pd call do_dir pop pd pop ax pop ax call setdta call getwild jmp noshow no_more: jmp outahere jfnext: jmp fnext doshow: push pd call showit pop pd call setdta jmp fnext noshow: mov si,pd mov ax,[si+21] and ax,Dir_Mask jnz isadir add word ptr Total_files,1 adc word ptr Total_files+2,0 mov ax,[si+26] mov cx,[si+28] add word ptr Total_bytes,ax; adc word ptr Total_bytes+2,cx; jmp fnext isadir: add word ptr Total_subs,1 adc word ptr Total_subs+2,0 fnext: mov ah,0x4f int 0x21 jb no_more jmp d_loop setdta: mov dx,pd mov ah,0x1a int 0x21 ret showit: push pd call s_print pop pd ret outahere: popa
Isn't that pretty? Never mind what it does: I can't remember that now. But it's still pretty.
I miss it.
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
Increase ad revenue 50-250% with Ezoic