Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;New tack. Logic. Wed Apr 1 12:38:35 NZDT 202. logicA.asm. Logic rountines using and,or,xor all work below.
- ;Tue Mar 31 14:48:41 NZDT 2020 scartB.asm. Now trying to call a subroutine inside another one.
- START ORG 0
- ; seq
- ; req
- ; seq
- ldi $00
- phi 2 ;R2 is stack pointer
- ldi $ff
- plo 2 ;R2=stack pointer now points to $00ff
- sex 2 ;X now pnts to R2, the stack pointer. 00ff
- ldi $00
- phi 7
- ldi $b0
- plo 7 ;R7 contains aritrary pointer $0b0
- ldi HIGH(main)
- phi 3
- ldi LOW(main)
- plo 3 ;R3 now points to main; becomes main prog counter.
- ldi HIGH(callr)
- phi 4
- ldi LOW(callr)
- plo 4 ;r4 now contains pointer to callr
- ldi HIGH(retr)
- phi 5
- ldi LOW(retr)
- plo 5 ;r5 now contains pointer to callr
- sep 3 ;sp points to main
- nop ;never get here
- main
- ldi $12
- phi 6
- ldi $34
- plo 6 ;just to see something in there,r6, for debugging.
- ldi $f1 ;dummy write just to see we got here ok
- str 6
- sep 4
- dw testLogic
- idl ;stop
- ;-----main code below here not used --------------
- sep 4
- dw sub1 ;call sub1
- ldi $ee ;dummy write just to see we got here ok
- inc 7
- str 7
- sep 4
- dw sub2 ;call sub2
- ldi $dd ;dummy write just to see we got here ok
- inc 7
- str 7
- idl ;finish
- exita
- sep 3
- callr ;code for call routine goes here. r4 is pointer.
- nop ;assume x=2 and r2 is stack pointer
- sex 2 ;in case x was changed by some other code. Point to stack with r2.
- ghi 6
- stxd
- glo 6
- stxd ;r6 now pushed onto stack
- ghi 3
- phi 6
- glo 3
- plo 6 ;r3 now saved in r6. NB r6 ponts just past calling sep
- lda 6 ;get first byte after calling sep
- phi 3
- lda 6
- plo 3 ;now r3 points to called subroutine
- br exita ;branch to entry pnt of callr. So r4 pnts to callr, for other calls. Brilliant.
- ; sep 3 ;jump to new subroutine
- exitr
- sep 3
- retr ;code for return subroutine goes here. r5 is pointer.
- nop ;come here after subroutine over
- ghi 6
- phi 3
- glo 6
- plo 3 ;r6 copied into r3. Soon to be PC
- sex 2 ;point to stack, maybe unnecessary. Put in anyway.
- inc 2 ;to point to old r6
- ldxa ;get stacked low byte
- plo 6
- ldx
- phi 6 ;now old r6 restored and stack pointer ok
- br exitr
- ; sep 3 ;go back to main program.
- ;---------------------------------------New subs go below here--------
- testLogic ;tested or,xor,and. All worked as expected. Next do immediate cases.
- ldi $00
- phi 8
- ldi $C0
- plo 8
- sex 8 ;x now points to r8 = $090
- do_or
- ldi $a5
- or
- str 7
- do_xor
- ldi $a5
- xor
- inc 7
- str 7
- do_and
- ldi $a5
- and
- inc 7
- str 7
- do_ori
- ldi $a5
- ori $93
- inc 7
- str 7
- do_xri
- ldi $a5
- xri $93
- inc 7
- str 7
- do_ani
- ldi $a5
- ani $93
- inc 7
- str 7
- sep 5 ;return with $a5 OR M(RX)
- sub1
- inc 7
- ldi $11
- str 7
- sep 5 ;all returns go via retr that's pointed to by r5
- sub2
- inc 7
- ldi $22
- str 7
- sep 4
- dw sub3
- sep 5
- sub3
- inc 7
- ldi $33
- str 7
- sep 5
- ORG $0C0
- db $93,$b4,$c5,$d6
- ORG $3fb
- nop
- nop
- nop
- nop
- nop
- END
Advertisement
Add Comment
Please, Sign In to add comment