I am trying to learn assembler on the various retro machines I own, or am about to buy.
Today I tried converting this 8080 routine (which worked, repeatedly):
| START: | MVI A,0 | 8000 | 3e |
| | | 8001 | 00 |
| LOOP: | INR A | 8002 | 3c |
| | CPI 10 | 8003 | fe |
| | | 8004 | 0a |
| | JZ HALT | 8005 | ca |
| | | 8006 | 0b |
| | | 8007 | 80 |
| | JMP LOOP | 8008 | c3 |
| | | 8009 | 02 |
| | | 800a | 80 |
| HALT: | HLT | 800b | 76 |
to run on my Epson HX-20, which has two Hitachi 6301 chips, using the datasheet available at vintagecomputer.net. It was a lot of guesswork on my part with the mnemonics, but I came up with this:
| START: | LDA A 0 | 1000 | 86 |
| | | 1001 | 00 |
| LOOP: | INC A | 1002 | 4c |
| | CMP A 10 | 1003 | b1 |
| | | 1004 | 0a |
| | BEO | 1005 | 27 | #Branch if = zero
| | | 1006 | 0b |
| | | 1007 | 10 |
| | JMP LOOP | 1008 | 6e |
| | | 1009 | 02 |
| | | 100a | 10 |
| HALT: | SWI | 100b | 3f | #Software interrupt
To my surprise, this worked first time, and I could see the A accumulator* now held 0a. To my greater surprise, it hasn't worked since, when I have changed the value of 1004. I tried turning the machine on and off, but due to the way the HX-20 works, this does not clear RAM.
Why did this routine only work once? My guess is that branch is not quite the same as jump, and it is waiting to come back, or maybe I need to reset the zero flag?
In any case, I can set the value of the A accumulator manually using LDA A, or the HX-20 Monitor x command, so it would not appear to be a malfunctioning RAM issue.
I'm now wondering if I'm going mad, and it didn't work the first time after all...
* The HX-20 also has a B accumulator.