June 26th Tuesday (六月 二十六日 火曜日)

本文介绍了一个使用Scheme语言实现的树形数据结构遍历生成器,该生成器能够有效地遍历树的叶子节点。此外,还详细解析了ARM架构下特定指令的功能与用法,包括MSR/MSR、LDM/STM和SWP等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(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.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值