• 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,396
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

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.
 
Hi Alank2, how is going your Enigma for 4004 project ?

I am working with Erturk Kocalar on the Teensy version of Retroshield 4004 ( http 8bitforce.com/projects/4004/ )
.... and I would be delighted to run ENIGMA on it !!
I am newbie in 4004 asm, but if I can help, for testing in the beginning for example, it is with pleasure
 
Thank you
Excuse me I did no introduce myself, I am french and interested in Intel 4004
I have two chips and a working Retroshield board, and now trying to run programs with it
 
Cartonibus - thanks for checking in - the project stalled and I got busy working on something else... This *often* is how it goes for me with projects. I work on it and then something else seems more fun for a bit. I'd still like to code this, I recall being stuck on trying to figure out the best way to use the registers. I'll look at my notes and see if I can present some of where I was getting stuck in case you have any tips or ideas when I get a chance!
 
Thank you Alank2 for your response.
Do not hesitate to tell us what is the issue, some people may be able to answer, and I should be familiar with 4004 registers and asm in a few months

Also I am working in cybersecurity, and I would be delighted to show a 4004 Enigma to my newbie engineers !!
 
As a special note: Erturk's retroshield may not work with all 4004's. I don't know if he has found away to increase his execution speed. The problem is that the 4004 has dynamic registers and if one doesn't keep the clock speed high enough, it can loose state. Of my two, confirmed good, 4004's, one works with his board and one doesn't. They are both older white ceramic chips, so if you have newer plastic parts you may not have issues.
The clock period is specified to be 1.35 to 2 us, for the 4004 and associated parts. The data rate of his retroshield violates the 2 us spec.
I made a 4040 adapter connector that got smashed at one of the VCF's. It fell off the cart while bringing it in and got ran over by a car. Erturk's retroshield stayed on the cart but my 4040 processor and adpater was totaled.
Anyway, test some code to make sure it runs at slower than 2 us. I forget what his rate was.
Dwight
 
Back
Top