0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CASL2で汎用レジスタどうしの中身を交換する

Last updated at Posted at 2020-12-30

CASL2で汎用レジスタどうしの中身を交換するする方法をまとめます。

下の例はGR2とGR3の中身を交換します。
他の汎用レジスタを使用せず、交換します。
WCASL-IIというシミュレータで確認済みです。

<XORを使う方法>
GR2(GR2)は「GR2の中身はGR2である」ことを表し、
GR3(GR3) は「GR3の中身はGR3である」ことを表すこととする。

(1) XOR GR2,GR3
GR2(GR2^GR3) <- GR2(GR2) ^ GR3(GR3)
GR2には、(GR2^GR3)が格納される。

(2) XOR GR3,GR2
GR3(GR3^(GR2^GR3)) <- GR3(GR3) ^ GR2(GR2^GR3)
GR3^(GR2^GR3) = (GR3^GR3)^GR2 = 0^GR2 = GR2である。
GR3には(GR3^(GR2^GR3))が格納されされるが、GR2のことである。
GR3の中身がGR2に変化した。

(3) XOR GR2,GR3
GR2((GR2^GR3)^GR2) <- GR2(GR2^GR3) ^ GR3(GR2)
(GR2^GR3)^GR2 = (GR2^GR2)^GR3 = 0^GR3 = GR3である。

GR2には((GR2^GR3)^GR2)が格納されるが、GR3のことである。
GR3の中身がGR2に変化し、交換が完了した。

<スタックを使う方法>
GR2,GR3の順番でPUSHし、同じ順番でPOPすれば、中身を交換できる。

MAIN	START
;交換(その1)
	LAD	GR2,2
	LAD	GR3,3
	XOR	GR2,GR3
	XOR	GR3,GR2
	XOR	GR2,GR3
;交換(その2)
	LAD	GR2,2
	LAD	GR3,3
	PUSH	0,GR2
	PUSH	0,GR3
	POP	GR2
	POP	GR3
;
	RET
	END
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?