File: it18.asm

package info (click to toggle)
gpsim 0.32.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,644 kB
  • sloc: cpp: 121,258; asm: 54,223; ansic: 13,576; python: 9,708; sh: 4,695; makefile: 1,575; lex: 1,139; yacc: 854; pascal: 511; perl: 93; awk: 44; xml: 41
file content (613 lines) | stat: -rw-r--r-- 5,961 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
	;; it.asm
	;;
	;; The purpose of this program is to test how well gpsim can simulate
	;; a 16bit-core pic (like the 18cxxx family not the 17c family.
	;; Nothing useful is performed - this program is only used to
	;; debug gpsim.

	
include "p18c242.inc"

  cblock  0

	temp,temp1,temp2
  endc
	
	org 0


	clrf	temp1		;Assume clrf works...
				;

start:	
	;; Perform some basic tests on some important instructions

	setc			;set the Carry flag
	skpc			;and verify that it happened
	 bra	$

	clrc			;Now try clearing the carry
	skpnc
	 bra	$

	setz			;set the Zero flag
	skpz			;and verify that it happened
	 bra	$

	clrz			;Now try clearing it
	skpnz
	 bra	$
	
	setdc			;set the Digit Carry flag
	skpdc			;and verify that it happened
	 bra	$

	clrdc			;Now try clearing it
	skpndc
	 bra	$

	setov			;set the Over Flow flag
	skpov			;and verify that it happened
	 bra	$

	clrov			;Now try clearing it
	skpnov
	 bra	$

	setn			;set the negative flag
	skpn			;and verify that it happened
	 bra	$

	clrn			;Now try clearing it
	skpnn
	 bra	$


	movlw	1
	movwf	temp
	movf	temp,f
	skpnz
	 bra	$

	movlw	0
	movwf	temp
	movf	temp,f
	skpz
	 bra   $
	
	clrf	temp		;Clear a register
	skpz			;and verify that the Z bit in the
	 bra	$		;status register was set.

	movf	temp,w		;Read the register that was just
	skpz			;cleared, and again verify that Z
	 bra	$		;was set

	incf	temp,w		;Now this should cause the Z bit to
	skpnz			;get cleared.
	 bra	$

	movlw	0xff
	movwf	temp
	incf	temp

	skpz
	 bra	$

	;;
	;; incfsz
	;;

	movlw	0xff
	movwf	temp
	movf	temp,f		;Should clear Z
	incfsz	temp,w
	 bra	$

	skpnz			;incfsz shouldn't affect Z
	 bra	$

	incfsz	temp,f		;temp should now be zero
	 bra	$

	incfsz	temp,w		;the following inst. shouldn't be skipped
	 skpnz			;Z should be clear from above.
	  bra	$
		
	
	;; 
	;; addwf test:
	;;
	;; The purpose of this test is to a) verify that the addwf instruction
	;; adds correctly and b) that the appropriate status register bits are
	;; set correctly.

	clrw
	clrf	temp
	
	addwf	temp,w		; 0+0
	skpnc
	 bra	$
	skpz
	 bra	$
	skpndc
	 bra	$

	movlw	1		; 0+1
	addwf	temp,w
	
	skpc
	 skpnz
	  bra	$
	skpndc
	 bra	$
	skpn
	 skpnov
	  bra	$

	movlw	8		; 8+8 , test dc
	movwf	temp
	addwf	temp,w
	
	skpc
	 skpnz
	  bra	$
	skpdc
	 bra	$
	skpn
	 skpnov
	  bra	$

	movlw	0x88		; 0x88+0x88
	movwf	temp
	addwf	temp,w
	
	skpnc
	 skpnz
	  bra	$
	skpdc
	 bra	$
	skpn
	 skpov
	  bra	$

	movlw	0x80		; 0x80+0x80
	movwf	temp
	addwf	temp,w
	
	skpnc
	 skpz
	  bra	$
	skpndc
	 bra	$
	skpn
	 skpov
	  bra	$

	clrw
	addwf	temp,w		; 0x80+0
	
	skpc
	 skpnz
	  bra	$
	skpndc
	 bra	$
	skpnn
	 skpov
	  bra	$


	clrf	temp
	addwf	temp,w		; 0+0x80
	
	skpc
	 skpnz
	  bra	$
	skpndc
	 bra	$
	skpnn
	 skpnov
	  bra	$

	movlw	1
	movwf	temp
	movlw	0xff
	addwf	temp,w

	skpc
	 bra	$
	skpz
	 bra	$
	skpdc
	 bra	$


	clrc
	clrdc
		
	;;
	;; andwf test:
	;;
	clrf	temp
	movlw	1
	andwf	temp,f

	skpz
	 bra	$

	skpc
	 skpndc
	  bra  $

	andwf	temp,w

	skpz
	 bra	$

	skpc
	 skpndc
	  bra  $

	movlw	1
	movwf	temp
	andwf	temp,f

	skpnz
	 bra	$

	skpc
	 skpndc
	  bra  $

	movlw	0xff
	andwf	temp,f		;1 & 0xff should = 1

	skpnz
	 bra	$

	skpc
	 skpndc
	  bra  $

	movlw	0xff		;Now add 0xff to see if temp
	addwf	temp,f		;really is 1. (should cause a carry)

	skpnz
	 skpc
	  bra	$

	;;
	;; iorwf
	;;

	movlw	0
	movwf	temp
	iorwf	temp,f
	skpz
	 bra	$

	movlw	1
	iorwf	temp,f
	skpnz
	 bra	$

	movlw	0xff
	addwf	temp,f
	skpnz
	 skpc
	  bra	$


	;;
	;; rlcf
	;;

	clrdc
	clrf	temp
	clrc
	rlcf	temp,w
	
	skpdc
	 skpnc
	  bra	$

	skpz
	 bra	$

	setc
	rlcf	temp,f

	skpdc
	 skpnc
	  bra	$

	skpnz
	 bra	$

	movlw	0xff
	addwf	temp,f
	skpnz
	 skpc
	  bra	$

	rlcf	temp,f
	skpnc
	 bra	$
	
	movlw	0x80
	movwf	temp
	rlcf	temp,w

	skpc
	 bra	$
	movwf	temp
	addwf	temp,w
	skpz
	 bra	$

	;;
	;; rrcf
	;;

	clrdc
	clrf	temp
	clrc
	rrcf	temp,w
	
	skpdc
	 skpnc
	  bra	$

	skpz
	 bra	$

	setc
	rrcf	temp,f

	skpdc
	 skpnc
	  bra	$

	skpnz
	 bra	$

	movlw	0x80
	addwf	temp,f
	skpnz
	 skpc
	  bra	$

	rrcf	temp,f
	skpnc
	 bra	$
	
	movlw	1
	movwf	temp
	rrcf	temp,w

	skpc
	 bra	$
	movwf	temp
	addwf	temp,w
	skpz
	 bra	$


	;; 
	;; subwf test:
	;;

	clrf	wreg
	clrf	temp
	
	subwf	temp,w		; 0-0
	skpc
	 bra	$
	skpz
	 bra	$
	skpdc
	 bra	$

	movlw	1		; 0-1
	subwf	temp,w
	
	skpnc
	 bra	$
	skpnz
	 bra	$
	skpndc
	 bra	$

	movlw	0x10		; 0x10-0x10
	movwf	temp
	subwf	temp,w
	
	skpc
	 bra	$
	skpz
	 bra	$
	skpdc
	 bra	$

	movlw	0x88		; 0x88-0x88
	movwf	temp
	subwf	temp,w
	
	skpc
	 bra	$
	skpz
	 bra	$
	skpdc
	 bra	$

	clrf	temp
	movlw	0x80		; 0 - 0x80
	subwf	temp,f
	
	skpnc
	 bra	$
	skpnz
	 bra	$
	skpdc
	 bra	$

	movlw	0		; 0x80 - 0
	subwf	temp,w

	skpc
	 bra	$
	skpnz
	 bra	$
	skpdc
	 bra	$

	movlw	1		; 0x80 - 1
	subwf	temp,w

	skpc
	 bra	$
	skpnz
	 bra	$
	skpndc
	 bra	$
	

	clrc
	clrdc

	;; 
	;; xorwf
	;;

	clrf	temp
	movlw	0xff
	xorwf	temp,f

	skpc
	 skpndc
	  bra	$

	skpnz
	 bra	$

	xorwf	temp,f

	skpz
	 bra	$

	xorwf	temp,f
	incfsz	temp,f
	 bra	$

	;;
	;; swapf
	;;

	movlw	0x0f
	movwf	temp
	swapf	temp,f
	xorwf	temp,f
	incfsz	temp,f
	 bra	$

	decf	temp1,f
	incfsz	temp1,w
	 goto	done

	;; repeat the test with in the next bank
	
	bsf	status,rp0
	goto	start
	
done:
	bcf	status,rp0
	
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	
	bra	$
	
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
		

	;;
	;; Test indirect branching
	;;
test_pcl:
	
	clrf	temp
	clrf	temp1

tt1:
	movf	temp,w
	call	table_test

	xorwf	temp,w
	skpz
	 bsf	temp1,0

	incf	temp,f
	btfss	temp,4
	 goto	tt1

	goto	test_pcl2
table_test:
	addwf	pcl,f
table:
	retlw	0
	retlw	1
	retlw	2
	retlw	3
	retlw	4
	retlw	5
	retlw	6
	retlw	7
	retlw	8
	retlw	9
	retlw	10
	retlw	11
	retlw	12
	retlw	13
	retlw	14
	retlw	15

test_pcl2:
	
	btfsc	temp2,0
	 goto	test_pcl3
        movlw   0x20
        movwf   fsr0l
	clrf	fsr0h
	
next    clrf    indf0
        incf    fsr0l,1
        btfss   fsr0l,4
        goto    next

	bsf	temp2,0
        clrf    pcl

test_pcl3:

	movlw	ly
	movwf	pcl		; == goto ly
lx
	goto	test_pcl4
ly
	movlw	lx
	movwf	pcl

test_pcl4:
	
	goto	$
	end