// ================================
// Nihonium
//		jall, rtnl, pushcl, popcl instruction test
//		(c) 2023	1YEN Toru
// ================================
asm		"mcoc_irom.mem"
incl	"mcoc115.incl"
# ================================


// nh=1
sesr	sreg_b_nh
movfc	r0,sr
lsfti	r0,-sreg_b_nh
andi	r0,0x01
beq		tstfail

// initialize
ldc		sp,ramtop+0x0400
ldli	r0,0x1234_5678
movtc	tr,r0

// jump and link long word stack
movfc	r2,sp
jallr7	test_sub
movfc	r1,sp
cmp		r1,r2
bne		tstfail
movfc	r0,tr
subi	r0,2
cmp		r0,r7
bne		tstfail

bra		tstpass

// sub routine
test_sub:
pushcl	pc
popcl	tr
rtnl


// ================================
tstpass:
ldwi	r0,simpass						// pass: LED=blue
bra		tstfnsh
tstfail:
ldwi	r0,simfail						// fail: LED=red
tstfnsh:
ldwi	r7,simfnsh
stw		[r7],r0
bra		pcnt-2
nop
// ================================

