• Please review our updated Terms and Rules here

Please take a look at my i4004 source - any improvement suggestions?

alank2

Veteran Member
Joined
Aug 3, 2016
Messages
2,264
Location
USA
This is the very beginning of my Enigma M4 simulator that I want to run on the Intel 4004. For anyone with experience programming the i4004, let me know what tricks or improvements I can add to do what I am doing in a better way.

The ONLY thing implemented at this time is the code that acquires a line from the terminal. The line is saved to data register memory and its length is kept in a register pair (E/F). It supports backspace, ctrl-z to backspace an entire line, only allows 78 characters, makes sure the character is in the range of $20-$7F, and converts lowercase to uppercase. This doesn't sound like a lot, but it has taken some work on a 4 bit CPU when characters are 8 bits!

There is no command processing and absolutely no Enigma cipher operation at this point. I suppose it is a race to see if I can fit all of that within 4K!

The HEX file is included if you want to try running it in my emulator posted in the other thread.
 

Attachments

  • enigmam4.zip
    6.9 KB · Views: 2
There was one thing that you might want to include. I saw this in a printer driver code I disassemble a while back. The conditional jump instruction can be used for what I call as a SKIP instruction ( that is what I put in my disassembler ).
What this is is the set the condition bits so that it always skips over the instruction( normally the address ). Where it was used is where there was an input to the print routine and there were common bytes that were used multiple times. It can be used to reduce total code. The SKIP instruction would be followed with the LDM.
Each SKIP instruction would be before a labeled line that is intended to be executed. The next line would also have a label and the LDM Value.
For several constants that one would want to use one could have a string of these in front of the routine to use common input values. I suspect one would arrange them in an order that is most likely to be used as closer to the routine.
If you look at the conditional jump, you'll see two condition combinations that are not typically used. One set of conditions is to always jumps and the other is to always not jump.
The always jump is no different than doing a regular jump, so I don't see a purpose but you might have it just in case.
The always don't jump, is the SKIP instruction. This instruction means that in the regular flow, it can hid another instruction to replace of where the address would normally go.
I think, for SKIP, the CN bits are the number 0000b, if I recall right, and 1000b for always jump.
There are some combination jumps as well but I don't know how they might be used. Something like: Jump if Carry=1 or ACC=0 is possible.
I hope this makes sense.
Like:

L1 LDM Dh
SKIP
L2 LDM Ah
PRINT_NIBL code

Dwight
 
That is indeed clever; I'll have to keep that in mind to see if it will be useful somewhere.

Probably one of the biggest constraints of coding for 4004 is that lack of a real stack, but maybe it is also a blessing in disguise because there is so little room anyway and you don't want to litter the code with setting up parameters for a subroutine call. A couple of the subroutines I've made have had to be be duplicated because it takes up less room than swapping around register pairs. For example, I compare rp0 with rp1, but then needed to later compare rp1 and rpF.
 
Back
Top