Xで出題した問題の解答と解説です。 Xのポスト
問題
Xレジスタが0に初期化されている場合、以下の命令の実行結果を述べよ。
STX 0,X++
解答
0番地と1番地の2バイトのメモリに"2"が格納される。Xレジスタの値は"2"となる。
解説
命令を素直に解釈すれば、「0番地と1番地の2バイトのメモリに"0"が格納される」のが期待動作ですが、実際の動作は異なります。これはCPUの設計に起因する内部処理の順序によるものです。
この挙動については、MC6809のデータシートに以下のように注意書きがあります。
Care should be taken in performing operations on 16-bit pointer registers (X, Y, U, S) where the same register is used to calculate the effective address.
Consider the following instruction:
STX 0,X++ (X initialized to 0)
The desired result is to store a zero in locations $0000 and $0001, then increment X to point to $0002. In reality, the following occurs:
0 -> temp calculate the EA; temp is a holding register
X+2 -> X perform auto increment
X -> (temp) do store operation
( 8-BIT MICROPROCESSOR & PERIPHERAL DATA, Motorola Inc., pp.3-250)
私の知る限り、6809のプログラミングの解説書である"MC68009-MC6809E : Microprocessor Programming Manual, Motorola Semiconductor Products Inc., c1981."でも説明されていないので、データシートを読んだ人でないと正解がわからないかもしれません。
この問題は、6809のプログラミングについてどれだけ詳しいかを判別するために使っていました。
0 件のコメント:
コメントを投稿