Memory related instructions - CodeAbbey/intel4004-emu GitHub Wiki
Since we have learned many useful instructions to deal with internal registers and control the flow of the execution - we may wonder: how can this tiny chip work with external memory?
Though Intel 4004 CPU can work without external RAM at all thanks to its 16 registers - but they are not enough for more complicated tasks. So one or more memory chips could be wired to the processor. In this case special commands are used to deal with data stored outside.
###Setting data pointer
SRC
command ("send register control" - or as for me just "source") copies8
bit from supplied register pair to special data pointer (i.e.src r2
- set data pointer to value ofr2:r3
)
All further instructions will work with Accumulator and data cell pointed by this data pointer. So if you
want to move to another cell, you'll need to call SRC
once more.
Each memory cell is 4-bits
large and we can address 256
of them.
###Working with memory cell
WRM
sends data from accumulator to the chosen memory cell (i.e.memory[dp] = acc
)RDM
reads data from memory cell to accumulator (i.e. `acc = memory[dp])ADM
adds memory cell to accumulator (similar toADD
)SBM
subtracts memory cell from accumulator (similar toSUB
)
Arithmetic instructions ADM
and SBM
treat the Carry flag in exactly the same way as ADD
and SUB
.