URL
https://opencores.org/ocsvn/zipcpu/zipcpu/trunk
Subversion Repositories zipcpu
[/] [zipcpu/] [trunk/] [sw/] [zasm/] [test.S] - Rev 3
Go to most recent revision | Compare with Previous | Blame | View Log
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Filename: test.S;; Project: Zip CPU -- a small, lightweight, RISC CPU soft core;; Purpose: A disorganized test, just showing some initial operation of; the CPU. As a disorganized test, it doesn't prove anything; beyond the generic operation of the CPU.;; Status: As of July, 2015, the assembler isn't sophisticated enough; to handle the address resolution needed to assemble this file.;; Creator: Dan Gisselquist, Ph.D.; Gisselquist Tecnology, LLC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Copyright (C) 2015, Gisselquist Technology, LLC;; This program is free software (firmware): you can redistribute it and/or; modify it under the terms of the GNU General Public License as published; by the Free Software Foundation, either version 3 of the License, or (at; your option) any later version.;; This program is distributed in the hope that it will be useful, but WITHOUT; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License; for more details.;; License: GPL, v3, as defined and found on www.gnu.org,; http://www.gnu.org/licenses/gpl.html;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;test:clr r0mov r0,r1mov $1+r0,r2mov $2+r0,r3mov $22h+r0,r4mov $377h+r0,ur5noopnopadd r2,r0add $32,r0add $-33,r0not.z r0clrf r0ldi $5,r1cmp $0+r0,r1not.lt r0not.ge r1lod $-7+pc,r2ldihi $deadh,r3ldihi $beefh,r3testbench:// Let's build a software test bench.clr r12 ; R12 will point to our peripheralsldihi $c000h,r12mov r12,ur12mov test_start,upcldihi $8001,r0ldilo $-1,r0sto r0,$1+r12rtulod r12,r0cmp $0,r0bnz $1haltbusy; Now for a series of tests. If the test fails, call the trap; interrupt with the test number that failed. Upon completion,; call the trap with #0.; Now for a series of tests. If the test fails, call the trap; interrupt with the test number that failed. Upon completion,; call the trap with #0.; Test LDI to PC; Some data registers.dat __here__+5test_start:ldi $2,r11lod $-3+pc,pcclr r11noopcmp $0,r11sto.z r11,(r12)add $1,r0add $1,r0// Let's test whether overflow worksldi $3,r11ldi $-1,r0lsr $1,r0add $1,r0bv $1sto r11,(r12)// Overflow set from subtractionldi $4,r11ldi $1,r0.dat 0x5000001f ; rol $31,r0sub $1,r0bv $1sto r11,(r12)// Overflow set from LSRldi $5,r11ldi $1,r0.dat 0x5000001f ; rol $31,r0lsr $1,r0bv $1sto r11,(r12)// Overflow set from LSLldi $6,r11ldi $1,r0.dat 0x5000001elsl $1,r0bv $1sto r11,(r12)// Overflow set from LSL, negative to positiveldi $7,r11ldi $1,r0.dat 0x5000001f; // E: ROL $30,R0lsl $1,r0bv $1sto r11,(r12)// Test carryldi $0x010,r11ldi $-1,r0add $1,r0tst $2,ccsto.z r11,(r12)// and carry from subtractionldi $17,r11sub $1,r0tst $2,ccsto.z r11,(r12)// Let's try a loop: for i=0; i<5; i++)// We'll use R0=i, Immediates for 5for_loop:ldi $18,r11clr r0noopadd $1,r0cmp $5,r0blt for_loop//// Let's try a reverse loop. Such loops are usually cheaper to// implement, and this one is no different: 2 loop instructions// (minus setup instructions) vs 3 from before.// R0 = 5; (from before)// do {// } while (R0 > 0);bgt_loop:ldi $19,r11noopsub $1,r0bgt bgt_loop// How about the same thing with a >= comparison?// R1 = 5; // Need to do this explicitly// do {// } while(R1 >= 0);ldi $20,r00ldi $5,r1bge_loop:noopsub $1,r1bge bge_loop// Let's try the reverse loop again, only this time we'll store our// loop variable in memory.// R0 = 5; (from before)// do {// } while (R0 > 0);ldi $21,r11bra $1loop_var:.dat 0mem_loop:mov $-2+pc,r1clr r2ldi $5,r0sto r1,(r0)add $1,r2add $14,r0lod (r1),r0sub $1,r0bgt $-6cmp $5,r2sto.ne r11,(r12)// Return success / Test the trap interruptclr r11sto r11,(r12)noopnoop// Go into an infinite loop if the trap fails// Permanent loop instruction -- a busy halt if you willbusy// And, in case we miss a halt ...halt
Go to most recent revision | Compare with Previous | Blame | View Log
