Assumptions:
Choices:
Assumptions:
Code:
input length
for (m=0; m<length; m++)
{ input content
mailbox[m] = content
}
ORG 80
** input length
IN
STO length
** for (m=0; ...
LDA zero
STO m
** for (...; m<length; ...
** - we require a flag setting which will distinquish
** the case m<length from all other cases
** - comparisons are done using SUBtract but we
** have two options: (m-length) and (length-m)
**
** | m<length || m==length m>length
** -----------|---------------||---------------|-------------
** (m-length) | N:1 Z:0 Pz:0 || N:0 Z:1 Pz:1 | N:0 Z:0 Pz:1
** -----------|---------------||---------------|-------------
** (length-m) | N:0 Z:0 Pz:1 || N:0 Z:1 Pz:1 | N:1 Z:0 Pz:0
**
** observe that (m<length) is separated from the other two cases
** if we subtract (m-length) and check the N(egative) indicator
forloop:LDA m
SUB length
SKN
JMP exitfor
** input content
IN
STO content
** mailbox[m] = content
** -----------THIS IS THE UGLY PIECE-------
LDA m ** mailbox address to assign content to
ADD store ** a STO instruction with a zero address
STO assign ** a STO with the address m
LDA content
assign: DAT 000 ** this will be replaced with a STO [m]
** for (...; ...; m++)
LDA m
ADD one
STO m
JMP forloop
** end of bootstrap load
exitfor:JMP 00 ** execute the code just loaded
**
** ----------------------
**
zero DAT 000
one DAT 001
store STO 00
length DAT
m DAT
content DAT
Notice there are a few problems with this code:
The second problem helps reduce the first. The last 3 "variables" must be stored in the area before ROM:
ORG 77 ## force next mailbox to be reset to 77
length DAT
m DAT
content DAT
But we still need to "make up" 3 more locations in order for our bootstrap code to fit in the allocated ROM.
Thus we can successfully reduce our bootstrap code size to fit in the available ROM. However, this type of "optimization" reduces the readability of the code and should only be done in extreme situations (like this particular case). Most programmers never need to concern themselves with "optimizing" at this level.