PICAXE 20X2 - Can I address GP variables as nybbles, rather than bytes and words?

laserhawk64

Senior Member
Hello, all. It's been a while :p As usual, I have a very odd idea that isn't really in the PICAXE's typical line of work, and I'd like to see if I can hammer the round peg into its square hole...

I'm, er, emulating a four bit CPU with a 20X2.

It has a four bit data bus, an eight bit address bus, and four other lines -- clock, I/M, W/R, and IRQ. (I/M = IO/MEM -- L for memory operations, H for I/O ops; W/R = Write/Read -- L for read ops, H for write ops; IRQ is an active-high input.) I can post the pinout map I came up with if it really matters, but I'll leave it out for now.

A local friend of mine started designing the logic and got far enough to lay out commands and states -- which is just enough for me to figure out how to implement it. I've decided that I want to keep it as simple as possible -- the entire computer around the CPU is an SRAM chip (parallel IO, 32k*8 of which half will be used) and the buffer/latch chips needed to read switches and drive LEDs. (This is a ROMless system.) As such, the "clock" is a single-cycle circuit (each press of a button produces a single clock cycle). As the input switches will be DIPs (I want to keep it physically small, too), this will probably result in an overall system speed of less than 1Hz. Whee...

*ahem*

Here's the issue. I want to use the internal RAM to simulate the internal CPU registers. Those registers are laid out like this --

RegA = 4b
RegB = 4b
RegT = 8b (divided into RegTA and RegTB, 4b each)
Flags = 4b (divided into four 1b sections, labeled C E Z M )
PC = 8b

...and during an interrupt condition...

RegIntA = 4b
RegIntB = 4b
RegIntT = 8b (divided into RegIntTA and RegIntTB, 4b each)
IntFlags = 4b (divided into four 1b sections, labeled IC IE IZ IM )
IntPC = 8b

So, if I can address individual nybbles within the 20X2, I only need 28b (3-1/2 bytes). I can split b0 for RegA+RegB, b1 becomes RegT, Flags becomes the first half of b2, and b3 is the PC. b4 is RegIntA+RegIntB, b5 is RegIntT, the first half of b6 acts as IntFlags, and b7 is IntPC.

However, if I have to use whole bytes, it requires 80b (TEN whole bytes... geez louise!) -- one byte for each register. When I don't really need that much space, it's a little silly to take it up.

So, can I address individual nybbles at once in that 20X2 (and if so, how), or do I have to use whole bytes?

Oh -- don't know if it matters but I'm on Linux now so I'm using LinAXEpad to program the chip.

Thanks guys, I know you folks rock ;)
 

laserhawk64

Senior Member
Custom, as described in the initial post. IIRC I wouldn't need 16 IO pins for a 4004, but I could be mistaken as I'm running from memory.
 

srnet

Senior Member
Ah yes, my mistake I missed the relavence of;

the entire computer around the CPU is an SRAM chip (parallel IO, 32k*8 of which half will be used)
Unlikley to be used with a processor of the era of the 4004.
 

Technical

Technical Support
Staff member
No, you cannot address nybbles direct. As you have plenty of RAM spare it's probably just easiest to use a whole byte as if it was a nybble.
 

rossko57

Senior Member
It'd be pretty easy to write a couple of subroutines to address by nibble (using multiply, divide or mod 16). Processing time insignificant at manual clocking, added complexity.
 

laserhawk64

Senior Member
@AllyCat -- my choice was x8 SRAM or no SRAM at all. They don't make x4 SRAM any more :( I wish they did, I feel kind of bad that I'm only using half of it...

@rossko57 -- I'm not really sure how to do that... hmmm... does the PICAXE have a shift-left or shift-right instruction...? (I don't remember and I'm too silly to look right now :p )
 

MPep

Senior Member
Shift Left or Right can also be achieved by multiply and divide, by 16,, as Rossko hints to.
 

AllyCat

Senior Member
Hi,

In that case, you probably ought to write down the FULL Instruction Set (Opcodes) that you're hoping to emulate (and how).

PICaxe Basic doesn't directly support the ubiquitous "Carry" flag so you might find, for example, that coding the nybble in bits 1 - 4 (not 0 - 3) would make emulating right-shifts easier. And/or does the IS support "byte" operations (similar to PICaxe supporting Word instructions)?

Also, if you're trying to be "economical", why an X2? The contiguous 512 bytes of an M2 RAM might actually be easier to code/manage than an X2. Certainly X2s do have (some) bit-shifting operations (whilst M2s don't), but that should be the least of your concerns.

Cheers, Alan.
 

laserhawk64

Senior Member
A friend of mine gave me a fat pile of PICAXE chips, including several 20X2's. I don't think I have 20M2's and I need at least sixteen pins available to do this. I don't have any chips larger than 20X2's either.
 

MPep

Senior Member
Decimal : Binary

1 x 16 = 16: 00000001 x16 = 00010000
2 x 16 = 32: 00000010 x16 = 00100000
3 x 16 = 48: 00000011 x16 = 00110000
...etc

Hope you can understand that :eek:
 

inglewoodpete

Senior Member
A friend of mine gave me a fat pile of PICAXE chips, including several 20X2's. I don't think I have 20M2's and I need at least sixteen pins available to do this. I don't have any chips larger than 20X2's either.
I'd choose the 20X2 over the 20M2 any day. The X2 is a much more powerful chip. The 20X2 is my PICAXE of choice, unless I need more pins. About the only thing that the 20M2 can do that the 20X2 can't are the "Touch" commands.
 

laserhawk64

Senior Member
[...] you probably ought to write down the FULL Instruction Set (Opcodes) that you're hoping to emulate (and how). [...]
Here you go -- pin mapping of the 20X2, instruction set list, and instruction set implementation. I've attached as a *.doc because the post editor doesn't want to format the thing right -- it insists on removing every single line break so that the whole thing is one continuous line of text, and the length of this thing is rather significant. Actually... I seem to have a lot of trouble with this editor... I'm using Chromium 31, and sometimes it accuses me of double-posting when I didn't, and the smilies don't work unless I enter them manually, and I don't even *see* tag buttons above the text-entry box... hmm. Curious.
 

Attachments

hippy

Ex-Staff (retired)
ADD B+A, Store In RegA
> poll IRQ line, execute [INT] if IRQ high
> inc PC
> add B to A [B+A], store in RegTA
> if result>4b, set Carry Flag (Flag_C=1)


Perhaps I am misunderstanding how things are meant to work but ... Shouldn't carry be set when the result is greater than Fb, when the result can no longer be represented in four bits ?

Also related ... XOR, AND and OR usually don't set carry because they can never deliver a result greater than four bits. In which case the carry checks for those instructions can be removed.
 
Top