File copy.sub * By ASM8 v9.00 Win32 [Friday, April 12, 2013 11:00 am] 1 ;******************************************************************************* 2 ;* Module : COPY.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Copy routine(s) 5 ;* Language : Freescale HC08/9S08 Assembly Language (aspisys.com/ASM8 v9.00+) 6 ;* Status : FREEWARE Copyright (c) 2013 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/copy.html 8 ;* Note(s) : Can be placed in any memory (normal or paged). Always use CALL. 9 ;* History : 03.08.14 v1.00 Original 10 ;* CRC $C80E : 10.02.12 Adapted to latest ASM8 11 ;* CRC $141D : 10.06.21 Added macro BlockCopy to simplify subroutine use 12 ;* CRC $CD55 : 10.08.19 Improved macro to allow for ,X indexed parms 13 ;* CRC $CD55 : 11.07.27 Improved macro for ,AX and ,SPX indexed parms 14 ;* CRC $1B43 : 12.11.27 Removed CLC from exit (no errors possible) 15 ;* : Optimized HC08 case by 6 bytes (via SP => SPX) 16 ;******************************************************************************* 17 *** BEGIN INCLUDE FILE: C:\mot\hc08\asm\mcu.inc *** *** BEGIN INCLUDE FILE: C:\mot\hc08\asm\GB60.inc *** *** BEGIN INCLUDE FILE: C:\mot\hc08\asm\macros.inc *** *** END INCLUDE FILE: C:\mot\hc08\asm\macros.inc *** (RESUMING FILE: C:\mot\hc08\asm\GB60.inc) *** BEGIN INCLUDE FILE: C:\mot\hc08\asm\common.inc *** *** END INCLUDE FILE: C:\mot\hc08\asm\common.inc *** (RESUMING FILE: C:\mot\hc08\asm\GB60.inc) *** END INCLUDE FILE: C:\mot\hc08\asm\GB60.inc *** (RESUMING FILE: C:\mot\hc08\asm\mcu.inc) *** END INCLUDE FILE: C:\mot\hc08\asm\mcu.inc *** (RESUMING FILE: C:\mot\hc08\asm\lib\copy.sub) 22 #Cycles 23 #MapOff 24 #HideMacros 26 27 ;******************************************************************************* 28 ; Macro to perform BlockCopy in a single command 29 47 48 ;******************************************************************************* 49 ; Purpose: Copy a block from one memory location to another 50 ; Input : Stack = parameter block [3 words] 51 ; : TOS+4: Number of bytes (sizeof block) 52 ; : TOS+2: Destination pointer 53 ; : TOS : Source pointer 54 ; Output : Parameter block contents destroyed 55 ; Use : #ROM 56 ; : #Include copy.sub 57 ; Call : ldhx #NumberOfBytes ;parameters are pushed 58 ; : pshhx ;on the stack in such 59 ; : ldhx #Destination ;order so as to end up 60 ; : pshx ;correctly offset from 61 ; : ldhx #Source ;the stack pointer as 62 ; : pshhx ;shown in the above 63 ; : call BlockCopy ;make the call 64 ; : ais #6 ;de-allocate parameter bytes 65 ; Size : 41 bytes [9S08], 77 bytes [HC08] 66 ; Cycles : 74 [9S08], 116 [HC08] 67 68 #spauto :ab ;account for RTS/RTC 69 70 182C BlockCopy proc 71 71 71 71 71 71 71 #temp 1 71 0001 .src@@ next :temp,2 71 0003 .dst@@ next :temp,2 71 0005 counter@@ next :temp,2 72 182C:8789 8B [ 6] push 74 182F:9EFE 0A [ 5] ldhx counter@@,sp 75 1832:271C (1850) [ 3] beq Exit@@ ;zero length means exit now 76 77 1834:9EFE 06 [ 5] ldhx .src1,sp 77 1837:F6 [ 3] lda ,x 77 1838:AF01 [ 2] aix #1 77 183A:9EFF 06 [ 5] sthx .src1,sp 78 183D:9EFE 08 [ 5] ldhx .dst1,sp 78 1840:F7 [ 2] sta ,x 78 1841:AF01 [ 2] aix #1 78 1843:9EFF 08 [ 5] sthx .dst1,sp 79 80 1846:9EFE 0A [ 5] ldhx counter@@,sp 81 1849:AFFF [ 2] aix #-1 ;decrement counter 82 184B:9EFF 0A [ 5] sthx counter@@,sp 83 184E:26E4 (1834) [ 3] bne Loop@@ ;repeat until counter = zero 84 ;------------------------------------------------------------------------------- 104 105 1850:8A88 86 [ 9] Exit@@ pull 106 1853:81 [ 6] rtc 107 108 #sp 109 ;******************************************************************************* 110 #Exit 111 ;******************************************************************************* 112 113 #Message BlockCopy Size: {*-BlockCopy} bytes, {:cycles}+ cycles 114 #MapOn 115 116 000B DATASIZE def 11 117 118 #push 118 #RAM 118 #XRAM 118 0100 Destination set * 118 #size Destination,DATASIZE 118 0100+000B rmb DATASIZE 118 #pull 119 120 #spauto 121 122 1854 Start proc 123 1854:4510 80 [ 3] ldhx #STACKTOP 123 1857:94 [ 2] txs 124 1858:4F [ 1] clra ;(keeps simulator happy) 125 126 #push 126 #spauto :sp 126 1859:898B [ 4] pshhx 126 #psp 126 185B:4500 0B [ 3] ldhx #DATASIZE 126 185E:898B [ 4] pshhx 126 1860:4501 00 [ 3] ldhx #Destination 126 1863:898B [ 4] pshhx 126 1865:4518 73 [ 3] ldhx #Source 126 1868:898B [ 4] pshhx 126 186A:CD18 2C [ 6] call BlockCopy 126 186D:A706 [ 2] ais #:psp 126 186F:8A88 [ 6] pulhx 126 #pull 127 ; @BlockCopy, 1,x 2,ax 3,spx ;test X-based indexed modes 128 1871:20FE (1871) [ 3] bra * 129 130 1873.5465 7374 696E Source fcs 'Testing...' 130 672E 2E2E 130 187D.00 131 132 #Push 132 #VECTORS 132 #ppc 132 FFFE org Vreset 132 FFFE.1854 dw Start 132 FFCC org :ppc 132 #Pull ----------------------------------------------------------- S E G M E N T U S A G E R E P O R T Segment Start End Size CodObj DatObj TotObj Lines ------- ----- ----- ----- ------ ------ ------ ----- XRAM $0100 $010A $000B $0000 $0000 $0000 3 ROM $182C $187D $0052 $0047 $000B $0052 4589 DATA $FFBD $FFBF $0003 $0000 $0002 $0002 31 VECTORS $FFFE $FFFF $0002 $0000 $0002 $0002 3 Summary $182C $FFFF $E7D4 $0047 $000F $0056 4626 ----------------------------------------------------------- O V E R A L L M E M O R Y U S A G E Total RAM size: 11 $000B 0.01 KB Total CODE size: 71 $0047 0.07 KB (31 instructions) Total DATA size: 15 $000F 0.01 KB Total IMAGE size: 86 $0056 0.08 KB Lowest address : 6188 $182C Highest address : 65535 $FFFF Address Range : 61250 $EF42 59.81 KB (Used Range: 0.14%) Number of INCLUDE files: 4 Number of MACROs called: 71 Number of [#]PROCs used: 2 Assembled 4635 lines (No Errors, Warnings: 0), CRC: $1B43 *** End of copy.sub listing ***