;Exam2012H24FallX~n
;Exam2012H24秋Ｘのｎ乗プログラム１
;-------------------------
MAIN START
	LD GR1,N
	LD GR2,X
	CALL POLY
	ST GR0,RESULT
	RET
N DC 4
X DC 2
RESULT DS 1
	END
;-------------------
POLY START
	RPUSH
	LD GR4,=0
LP1 LD GR3,GR1
	JMI FIN   ;答え　イ　
	LD GR0,=1
LP2 LD GR3,GR3
	JZE BRK
	CALL MULT
	LAD GR3,-1,GR3
	JUMP LP2
BRK ADDL GR4,GR0
	LAD GR1,-1,GR1
	JUMP LP1
FIN LD GR0,GR4
	RPOP
	RET
	END
;---------------------------
MULT START
	RPUSH
	LD GR1,GR0
	LD GR0,=0    ;
	LD GR2,GR2
LP	JZE FIN
	LD GR3,GR2
	AND GR3,=#0001 ;
	JZE CONT
	ADDL GR0,GR1
CONT SLL GR1,1
	SRL GR2,1
	JUMP LP
FIN RPOP
	RET
	END
;----------------
