(definetree->generator
(lambda(tree)
(let((caller’*))
(letrec
((generate-leaves
(lambda()
(letloop((treetree))
(cond((null?tree)’skip)
((pair?tree)
(loop(cartree))
(loop(cdrtree)))
(else
(call/cc
(lambda(rest-of-tree)
(set!generate-leaves
(lambda()
(rest-of-tree’resume)))
(callertree))))))
(caller’()))))
(lambda()
(call/cc
(lambda(k)
(set!callerk)
(generate-leaves))))))))
When a generator created by tree->generator is called, it will store the continuation
of its call in "caller", so that it can know who send the leaf to when it finds it. It
then calls an internal procedure called generate-leaves which runs a loop traversing the
tree from left sub-tree to right sub-tree. When the loop encounters a leaf, it will use
"caller" to return the leaf as the generator's result, but it will remember to store the
rest of the loop (captured as a call/cc continuation) in the generate-leaves variable.
The next time the generator is called, the loop is resumed where it left off so it can
hunt for the next leaf.
The last thing generate-leaves does, after the loop is done, is to return the empty list
to the caller. Since the empty list is not a vaild leaf value, we can use it to tell that
the generator has no more leaves to generate.
MSR
MSR{condition} CPSR/SPSR_[field], operand
To save the operand into the program status register's specified fields. The operand can
be a register or an immediate value. The [field] represents those bits needs operation.
Bits[31:24] is flag bits, abbreviate for "f";
Bits[23:16] is status bits, abbreviate for "s";
Bits[15:8] is expanding bits, abbreviate for "x";
Bits[7:0] is control bits, abbreviate for "c".
For example:
MSR CPSR, R0
MSR SPSR, R0
MSR CPSR_c, R0
LDM/STM
LDM/STM{condition} {type} base_register{!}, register_list{^}
The "LDM" or "STM" is used to transport a series of data from a block memory to the
registers specified by the list. They usualy can be used to push data to or pop data
from a stack. The {type} is following:
IA increment after transport
IB increment before transport
DA decrement after transport
DB decrement before transport
FD Full Decending stack mode
ED Empty Decending stack mode
FA Full Ascending stack mode
EA Empty Ascending stack mode
If {!} as suffix (postfix), when finish transporting data, the last address is putted
into the "base_register"; otherwise, nothing is changed. The "R15" can not be as the
"base_register".
When {^} as postfix and "LDM" is used and the "register_list" includes R15, except for
transporting data, the content of SPSR is copied into the CPSR. At once the {^} suffix
means the registers as the "usr" mode, not at current mode.
SWP{condition} destination, source1, [source2]
When transporting data from source2 into destination, the data at source1 is also
transportted into source1.
When the destination and source1 is same, it just is to exchange data between the register
and memory.
SWP{condition}B destination, source1, [source2]
It is similar to SWP instruction. It just transport a byte data. The high 24 bits at
the destination all are set 0.