URL
https://opencores.org/ocsvn/risc5x/risc5x/trunk
Subversion Repositories risc5x
[/] [risc5x/] [trunk/] [jumptest.asm] - Rev 3
Compare with Previous | Blame | View Log
;LIST p=16C58 ; PIC16C58 is the target processor;; Core Sanity Test;; JUMPTEST.ASM;; test some jumps; NEW in rev 1.1, test indirect addressing; test some inc & decs; sit in loop multiplying port A with a constant; output 16 bit result on ports C & B;CARRY equ H'00' ; Carry bit in STATUS registerDC equ H'01' ; DC bit in STATUS registerZERO equ H'02' ; Zero bit in STATUS registerW equ H'00' ; W indicator for many instruction (not the address!)INDF equ H'00' ; Magic register that uses INDIRECT registerTIMER0 equ H'01' ; Timer registerPC equ H'02' ; PCSTATUS equ H'03' ; STATUS register F3FSR equ H'04' ; INDIRECT Pointer Registerporta equ H'05' ; I/O register F5portb equ H'06' ; I/O register F6portc equ H'07' ; I/O register F7x equ H'09' ; scratchy equ H'0A' ; scratchrh equ H'0B' ; result hrl equ H'0C' ; result lmult MACRO bitbtfsc y,bitaddwf rh,1rrf rh,1rrf rl,1ENDMstart: movlw H'ff'tris porta ; PORTA is Inputclrwtris portb ; PORTB is Outputtris portc ; PORTC is Outputmovwf portb ; PORTB <= 00movlw h'0B'movwf PC ; move to pc (jump1)movlw h'F0' ; fail 0movwf portbgoto failjump1: movlw h'05'addwf PC,f ; jump forward to jump2movlw h'F1' ; fail 1movwf portbgoto failjump3: goto jump4 ; continuenopjump2: movlw h'04'subwf PC, f ; jump back to jump 3movlw h'F2' ; fail 2movwf portbgoto failjump4:movlw h'10' ; set locations 10-1F to xFFmovwf FSRmovlw h'ff'clrlp: movwf INDFincf FSR,Fbtfsc FSR,4goto clrlpmovlw h'10'movwf xmovlw h'20'movwf ymovlw xmovwf FSR ; point FSR at xmovf FSR,wxorlw h'89' ; check its x (note bit 7 set always)btfss STATUS,ZEROgoto failmovf INDF,wxorlw h'10' ; check its 10btfss STATUS,ZEROgoto failmovlw h'15' ; write 15 to x using INDFmovwf INDFmovf x,w ; read xxorlw h'15' ; check its 15btfss STATUS,ZEROgoto failincf FSR,Fmovf INDF,wxorlw h'20' ; check its 20btfss STATUS,ZEROgoto failmovlw h'00'movwf FSRmovlw h'A5' ; paranoid !movf INDF,w ; reading INDR itself should = 0xorlw h'00' ; checkbtfss STATUS,ZEROgoto fail; check banking; locations 20-2F, 40-4F, 60-6F all map to 0-0F; locations 10-1F, 30-3F, 50-5F, 70-7F are realmovlw h'00'movwf FSR ; set bank 0movlw h'1F'movwf h'1F'movlw h'20'movwf FSR ; set bank 1movlw h'3F'movwf h'1F'movlw h'40'movwf FSR ; set bank 2movlw h'5F'movwf h'1F'movlw h'60'movwf FSR ; set bank 3movlw h'7F'movwf h'1F'; checkmovlw h'00'movwf FSR ; set bank 0movf h'1F',wxorlw h'1F'btfss STATUS,ZEROgoto failmovlw h'20'movwf FSR ; set bank 1movf h'1F',wxorlw h'3F'btfss STATUS,ZEROgoto failmovlw h'40'movwf FSR ; set bank 2movf h'1F',wxorlw h'5F'btfss STATUS,ZEROgoto failmovlw h'60'movwf FSR ; set bank 3movf h'1F',wxorlw h'7F'btfss STATUS,ZEROgoto failmovlw h'00'movwf FSR ; set bank 0movlw h'45'movwf h'0F'movlw h'60'movwf FSR ; set bank 3movlw h'54'movwf h'0F'movlw h'40'movwf FSR ; set bank 2movf h'0f',w ; w should contain 54xorlw h'54'btfsc STATUS,ZEROgoto test1movlw h'F3' ; fail 3movwf portbgoto failtest1: movlw h'00'movwf FSR ; set bank 0movlw h'04' ; w <= 04movwf xdecf x,f ; x <= 03decf x,f ; x <= 02decf x,f ; x <= 01decf x,f ; x <= 00decf x,f ; x <= FFmovf x,wxorlw h'FF' ; does w = ff ?btfss STATUS,ZERO ; skip if cleargoto failincf x,f ; x <= 00incf x,f ; x <= 01movf x,wxorlw h'01' ; does w = 01btfss STATUS,ZEROgoto fail; test logicclrf x ; x <= 00movlw h'a5'iorwf x,f ; x <= a5swapf x,f ; x <= 5amovlw h'f0'andwf x,f ; x <= 50comf x,f ; x <= afmovlw h'5a'xorwf x,f ; x <= f5;checkmovfw xxorlw h'f5'btfsc STATUS,ZEROgoto test2movlw h'F4' ; fail 4movwf portbgoto failtest2: movlw h'23'movwf x ; x <= 23movlw h'e1' ; w <= e1addwf x,f ; x <= 04btfss STATUS,CARRYgoto fail ; carry should be setmovlw h'02' ; w <= 02subwf x,f ; x <= 02btfss STATUS,CARRYgoto fail ; borrow should be clearmovlw h'34' ; w <= 34subwf x,f ; x <= cebtfsc STATUS,CARRYgoto fail ; borrow should be setmovf x,wxorlw h'CE'btfss STATUS,ZEROgoto fail ; x /= cetest3: movlw h'34' ; test dc flagmovwf xmovlw h'0F'addwf x,f ; x <= 43btfsc STATUS,CARRYgoto fail ; carry should be clearbtfss STATUS,DCgoto fail ; dc should be setmovlw h'01'subwf x,f ; x <= 42btfss STATUS,CARRYgoto fail ; borrow should be clearbtfss STATUS,DCgoto fail ; dc borrow should be clearmovlw h'FF'subwf x,fbtfsc STATUS,CARRYgoto fail ; borrow should be setbtfsc STATUS,DCgoto fail ; dc borrow should be setmovf x,wxorlw h'43' ; final checkbtfss STATUS,ZEROgoto fail ; x /= 43movlw h'E0' ; okmovwf portbloop1: ; mult x by ymovf porta,Wmovwf xmovlw h'23'movwf yclrf rhclrf rlmovf x,wbcf STATUS,CARRYmult 0mult 1mult 2mult 3mult 4mult 5mult 6mult 7movf rl,wmovwf portb ; on port b low resultmovf rh,wmovwf portc ; on port c high resultgoto loop1fail: goto failend
