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.

CASLⅡで再帰を実行する

Posted at

CASLⅡで再帰を実行する

CASLⅡにおける再帰の例を挙げる。

'Hi!'と3回繰り返す。

; 'Hi!'と3回表示する
MAIN	START
		LAD  GR0,3
		CALL HI
		RET
;		
;GR0回、'Hi!'と表示する
HI		START   
		LD GR0,GR0
		JZE FIN
;
		OUT  HIMSG,LEN
		SUBA GR0,=1
		CALL HI
FIN		RET 
;
HIMSG   DC   'Hi! '
LEN     DC   4
		END

フィボナッチ数列をGR1とGR2に求める

; フィボナッチ数列をGR1とGR2に求める
; 0, 1, 1, 2, 3, 5 ……
MAIN	START
		LAD  GR0,4		; GR1=0, GR2=1から数えて、4回目のGR1=3,GR2=5を求める
		LAD  GR1,0
		LAD  GR2,1 
		CALL FIB
		RET
;
FIB		START  
		LD GR0,GR0
		JZE FIN
;
		XOR   GR1,GR2	; GR1とGR2を交換する
		XOR   GR2,GR1
		XOR   GR1,GR2
;
		ADDA  GR2,GR1
;
		SUBA GR0,=1
		CALL FIB
FIN  	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?