Sunday, November 29, 2009

Life changing magazines #1





I guess every programmer has a genesis moment. One where everything starts to make sense and it's the true begining of their love of programming. This was mine. I was 14 and must have had my ZX81 for about 6 months or so when I bought this magazine. I was at my grans in reading this and suddenly all those HEX numbers I'd been typing in made sense. There in front of me was a true assembler listing. I suddenly realised what all the codes at the back of the manual meant, and how you used them. I poured over this article for days, playing with it, trying new values, changing little bits to see what would happen. Up until now I'd been doing ZX81 BASIC and was getting on okay. However when I got this article I saw the routine that drew the border and called it directly.

BANG!

Unlike Basic, it popped up instantly. I was gob-smacked! It was SO quick. Basic would have taken over second to print that much! I played around with it, changing the character it drew and so on.

This showed me just what computers were capable of, and how these games I bought actually managed to do what they did. Now I could see how it all worked, I started to learn it all...

Put it simply... this is what got me hooked.

3 comments:

PypeBros said...

Do I understand it right ? the trick is to know the base address of your BASIC program and to have fill the largest-sized REMs with the opcodes of the "piggy-backed" assembly code, that will be invoked by USR instruction ?

Can you explain the meaning of "RAND USR xxx" and "IF USR xxx THEN ..." constructs ?

Mike said...

This was an old trick. Since BASIC always started at the same point on these old machines (ZX81, Spectrum, C64, Plus4 etc...) you could "attach" machine code to your BASIC program by storing it inside a REM statement. REMs were ignored by BASIC so you could store ANYTHING there. This let you save Basic+MachineCode together in one file, and you could then easily call directly into it as the start address never changed.

RAND USR xxxx was the command you used to execute a machine code program. There was also PRINT USR xxx which used to print the return value.

IF USR xxx would simply be checking the return code from assembler to see if you wanted to QUIT the game or not ("F" ended the game - acording to the instructions)

Steve said...

I remember having an epiphany moment too. I was about 10 and had a VIC-20. I was on holiday in spain and had taken the Programmers reference manual to read (ubernerd?) - it had a listing of all the 6502 opcodes, but it didn't have a lot in the way of introductory stuff (especially for a 10 yr old).

Over a period of an hour or so, things just started to click, and I put 2+2 together, and then put together my first machine code program by hand - something like A9 08 8D 90 0F. So, I converted it all to decimal and wrote down all the 'pokes'. But, I couldn't try it out until I got back from holiday. It didn't work - I had to write the address as little-endian. When I tried that, the screen turned black - it worked! (But crashed). Didn't take me long to figured out the RTS opcode though.

Such a shame that it's such a long complicated journey for new programmers to do assembly on the PC these days.