Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; All arith instructions, 12 of them, all tested in simulator and on rfeal 1802. Working well Mon Apr 613:51:10 NZST 202
- ;Now looking at last lot of 4 subtraction instructions where d<-d-MRX. Mon Apr 6 13:27:18 NZST 202
- ;Tested first set of subtractions. Had some problems with SDBI but worked them out, I think.
- ;Tested all the additions, add, adi, adc and adci various ways with 8 bits Worked.
- ; ..Sat Apr 4 15:45:07 NZDT 2020
- ;Tested all shifts. Simulation worked. Tested some in real 1802.Worked.Fri Apr 3 13:57:52 NZDT 202
- ;shiftloop worked well for shr. Fri Apr 3 13:17:44 NZDT 2020. next, in shiftsC.asm will try RSHR. Fri Apr 3 13:30:40 NZDT 2020 Worked.
- ;Now trying left shifts.
- ;Thu Apr 2 12:37:43 NZDT 2020. Now trying with shiftsA.asm to practice shifts and first loops.
- ;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.
- buf equ 007
- buf0 equ 007
- ctr equ 008
- buf1 equ 008
- buf2 equ 009
- START ORG 0
- ; seq
- ; req
- ; seq
- ldi $03 ;careful, we have some nops up there.
- 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 $03 ;note, this pointer gets changed by different routines below.
- phi 7 ;R7 is buf0 and buf
- ldi $40
- plo 7 ;R7 contains arbitrary pointer $340
- ldi $03 ;note, this pointer gets changed by different routines below.
- phi 8 ;R8 is buf1 and ctr
- ldi $50
- plo 8 ;R8 contains arbitrary pointer $350
- ldi $03 ;changes.
- phi 9 ;buf2
- ldi $60
- plo 9 ;R9 contains aritrary pointer $360
- 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 $02
- 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
- ;88888888888888888888888888888888888888888888888888888888888888888888888888888888888
- sep 4 ;************main prog*********
- dw arithSM
- ; dw arithSDBI
- ; dw arithSDB
- ; dw arithSDI
- ; dw arithSD
- ; dw arithADCI
- ; dw arithADC
- ; dw arithADI
- ; dw arithADD ;FIRST routine in arith adds below.
- ; dw tryDF
- ; dw shiftloopSHLC
- ; dw shiftloopSHL ;worked Fri Apr 3 13:43:11 NZDT 2020
- ; dw shiftloopSHRC ;works OK Fri Apr 3 13:30:40 NZDT 2020
- ; dw shiftloop
- ; dw do_shr2 ;play with shift right and loops
- ; dw do_shr ;play with shift right
- idl
- ; dw shifts
- ; 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
- ;-----now start on shifts-----------------------
- shifts
- ldi $04 ;going to loop 4 times
- plo 8 ;r8 = ctr
- up
- glo 8 ;D=acc gets ctr
- str 7 ;write ctr to mem
- inc 7 ;for next write
- dec 8 ;ctr = ctr-1
- glo 8 ;check if ctr is 0
- bnz up ;no loop again
- idl ;loop finished
- do_shr
- ldi $5a
- shr
- str 7
- shr
- inc 7
- str 7
- stxd
- nop
- ldxa ;trying to play with stack. Leave tidy.
- sep 5 ;return
- do_shr2 ;trying to use counter.
- ldi $08
- plo 8 ;r8 is counter
- ldi $a5 ;arbitrary value
- stxd ;save it
- loop1
- ldxa ;get acc back
- shr
- str 7
- inc 7 ;put copy into memeory to inspect
- stxd ;put back onto stack new, shifted, value.
- dec 8 ;dec counter
- glo 8 ;check on ctr
- bnz loop1
- sep 5 ;all over after 8 loops
- ; idl
- ;Better go, hopefully, with shifts and loops.
- shiftloop
- ldi $08
- plo ctr
- ldi $a5 ;arbitrary
- str buf
- inc buf ;for next insertion
- up0 shr ;**testing this, really**
- str buf
- ldi $80 ;proxy for zero
- bnf down0 ;if DF=0 print it
- ldi $81 ;proxy for one. Come here if DF=1
- down0
- str buf2 ;store DF flag in buf2, either 1=81 or 0=80
- inc buf2
- dec ctr
- glo ctr
- bz getout
- lda buf ;get shifted byte back from storage
- br up0 ;repeat 8 times. Then inspect bufs in memory
- getout
- sep 5 ;all over
- ;````````````````````````````````````````````same as above but for SHRC=RSHR``````
- shiftloopSHRC ;testing "shift right with carry", page 24 RCA book.
- ldi $08
- plo ctr
- ldi $f0 ;arbitrary
- str buf
- inc buf ;for next insertion
- up1
- shrc
- ; shr ;**testing this, really**
- str buf
- ldi $80 ;proxy for zero
- bnf down1 ;if DF=0 print it
- ldi $81 ;proxy for one. Come here if DF=1
- down1
- str buf2 ;store DF flag in buf2, either 1=81 or 0=80
- inc buf2
- dec ctr
- glo ctr
- bz getout1
- lda buf ;get shifted byte back from storage
- br up1 ;repeat 8 times. Then inspect bufs in memory
- getout1
- sep 5 ;all over
- ;````````````````````````````````````````````same as above but for SHL``````
- PAGE
- shiftloopSHL ;testing "shift left", page 24 RCA book.
- ldi $08
- plo ctr
- ldi $a5 ;arbitrary
- str buf
- inc buf ;for next insertion
- up2
- shl
- ; shrc
- ; shr ;**testing this, really**
- str buf
- ldi $80 ;proxy for zero
- bnf down2 ;if DF=0 print it
- ldi $81 ;proxy for one. Come here if DF=1
- down2
- str buf2 ;store DF flag in buf2, either 1=81 or 0=80
- inc buf2
- dec ctr
- glo ctr
- bz getout2
- lda buf ;get shifted byte back from storage
- br up2 ;repeat 8 times. Then inspect bufs in memory
- getout2
- sep 5 ;all over
- shiftloopSHLC ;testing "shift left with carry ", page 25 RCA book.
- ldi $08
- plo ctr
- ldi $a5 ;arbitrary
- str buf
- inc buf ;for next insertion
- up3
- shlc
- ; shl
- ; shrc
- ; shr ;**testing this, really**
- str buf
- ldi $80 ;proxy for zero
- bnf down3 ;if DF=0 print it
- ldi $81 ;proxy for one. Come here if DF=1
- down3
- str buf2 ;store DF flag in buf2, either 1=81 or 0=80
- inc buf2
- dec ctr
- glo ctr
- bz getout3
- lda buf ;get shifted byte back from storage
- br up3 ;repeat 8 times. Then inspect bufs in memory
- getout3
- sep 5
- ;======================================arith routines=====.Useful.
- ;one big routine for four instructions============
- arithADD ;for this r7,8,9 at $340,50,60 resp
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- add ;(buf0)+(buf0+1) -> DF
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downADD ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downADD
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithADI
- sex 7
- ldxa ;get byte in $340
- adi $84 ;add arbitrary immediate
- str 9
- inc 9
- ldi $80
- bnf downADI
- ldi $81
- downADI
- str 9
- inc 9
- arithADC
- testCarry
- ldi $ff
- shr
- ; ldi $00
- shr
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- adc ;(buf0)+(buf0+1) -> DF
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downADDc ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downADDc
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithADCI
- testCarryADCI
- ldi $ff
- shr
- ; ldi $00
- shr
- sex 7
- ldxa ;get byte in $340
- adci $04 ;add arbitrary immediate
- str 9
- inc 9
- ldi $80
- bnf downADcI
- ldi $81
- downADcI
- str 9
- inc 9
- ;-------------------------------------------------------------------
- ;Now doing subtractions. Sun Apr 5 13:40:19 NZST 202
- arithSD ;for this r7,8,9 at $340,50,60 resp
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- sd ;(buf0+1)-(buf0) -> DF
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downSD ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downSD
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithSDI
- sex 7
- ldxa ;get byte in $340
- sdi $84 ;subtract D from arbitrary immediate
- str 9
- inc 9
- ldi $80
- bnf downSDI
- ldi $81
- downSDI
- str 9
- inc 9
- arithSDB
- testCarrySDB
- ldi $ff
- shr
- ldi $00
- shr
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- sdb ;
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downsdb ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downsdb
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithSDBI ;seems not to work on simulator
- testCarrySDBI
- ldi $ff
- shr
- ldi $00
- shr
- sex 7
- ldxa ;get byte in $340
- sdbi $34 ;subtract arbitrary immediate from D - NOT(DF)
- str 9
- inc 9
- ldi $80
- bnf downSDBI
- ldi $81
- downSDBI
- str 9
- inc 9
- ;ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
- ;Now doing second set of subtractions. Mon Apr 6 13:27:18 NZST 2020
- arithSM ;for this r7,8,9 at $340,50,60 resp
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- sm ;(buf0)-(buf0+1) -> DF
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downSM ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downSM
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithSMI
- sex 7
- ldxa ;get byte in $340
- smi $84 ;subtract arbitrary immediate from D
- str 9
- inc 9
- ldi $80
- bnf downSMI
- ldi $81
- downSMI
- str 9
- inc 9
- arithSMB
- testCarrySMB
- ldi $ff
- shr
- ldi $00
- shr
- sex 7 ;x pints to r7=$340
- ldxa ;get byte stored in $340
- smb ;
- str 9
- inc 9 ;for next store
- ldi $80 ;proxy for zero in DF
- bnf downsmb ;DF =0?, go down0
- ldi $81 ;pretend one=DF
- downsmb
- str 9 ;put DF flag = carry beside sum
- inc 9
- arithSMBI
- testCarrySMBI
- ldi $ff
- shr
- ldi $00
- shr
- sex 7
- ldxa ;get byte in $340
- smbi $34 ;subtract arbitrary immediate from D - NOT(DF)
- str 9
- inc 9
- ldi $80
- bnf downSMBI
- ldi $81
- downSMBI
- str 9
- inc 9
- sep 5
- ORG $340
- db $82,$96,$c5,$a1,$0c
- ;-------keep these nops for 1802 simulator and Arduino serial-------------
- ORG $3fb
- nop
- nop
- nop
- nop
- nop
- END
Advertisement
Add Comment
Please, Sign In to add comment