diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-10 17:35:01 -0500 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-10 17:35:01 -0500 |
| commit | db27faf84654f0084542536e538044a0458bb554 (patch) | |
| tree | 9df700cc7bc02dd2c80006306e5fd8d24ba908c1 /examprep/Sources | |
| parent | bdb2965d02e8e8fa8f1fdf00e27718f6b048fb06 (diff) | |
HW4 Initial
Diffstat (limited to 'examprep/Sources')
| -rw-r--r-- | examprep/Sources/derivative.inc | 10 | ||||
| -rw-r--r-- | examprep/Sources/main.asm | 86 |
2 files changed, 96 insertions, 0 deletions
diff --git a/examprep/Sources/derivative.inc b/examprep/Sources/derivative.inc new file mode 100644 index 0000000..988343b --- /dev/null +++ b/examprep/Sources/derivative.inc @@ -0,0 +1,10 @@ + + ; Note: This file is recreated by the project wizard whenever the MCU is + ; changed and should not be edited by hand + ; + + ; include derivative specific macros + INCLUDE 'mc9s12c32.inc' + + + diff --git a/examprep/Sources/main.asm b/examprep/Sources/main.asm new file mode 100644 index 0000000..ee2c3e1 --- /dev/null +++ b/examprep/Sources/main.asm @@ -0,0 +1,86 @@ +************************************************************************** +* Parameter Declearation Section +* +* Export Symbols + xdef pgstart ; export 'pgstart' symbol + absentry pgstart ; for assembly entry point + +* Symbols and Macros +PORTA equ $0000 ; i/o port A addresses +DDRA equ $0002 ; data direction register for PORTA +PORTB equ $0001 ; i/o port B addresses +DDRB equ $0003 ; data direction register for PORTB + +************************************************************************** +* Data Section: address used [ $3000 to $30FF ] RAM Memory +* + org $3000 ; Reserved RAM memory starting address + ; for Data for CMPEN 472 class +SOURCE ds.b $000C ; 12 Byte source array + +LENSRC dc.w $000C ; Length of the Source Array + +DEST ds.b $000C ; 12 Byte destination array + +LENDST dc.w $000C ; Length of the destination array + +StackSP dc.w $3100 ; Address of the stack + +* +************************************************************************** +* Program Section: address used [ $3100 to $3FFF ] RAM Memory +* + org $3100 ; Program start address, in RAM +pgstart lds StackSP ; initialize the stack pointer + ldaa #1 ; Load 1 into A + ldx #SOURCE ; Load the address of SOURCE into X + ldy LENSRC ; Load the length of SOURCE into Y +fillLoop tbeq Y,doneLoop ; If Y==0, jump to done loop + staa 1,X+ ; Copy A into address of X, add 1 to X + inca ; Increment A by 1 + dey ; Decrement Y by 1 + bra fillLoop ; Jump to fillLoop +doneLoop jsr memcpy ; Call memcpy + bra done + + +************************************************************************** +* Subroutine Section: address used [ $3100 to $3FFF ] RAM Memory +* + +;************************************************************************* +; memcpy subroutine +; +; This subroutine will copy LENSRC bytes from SOURCE to DEST. +; +; Input: Two addresses, SOURCE and DEST, 1 word length LENSRC +; Output: LENSRC bytes copied from SOURCE to DEST +; Registers in use: D to count the number of bytes copied +; Y to hold the address of the current byte in SOURCE +; X to hold the address of the current byte in DEST +; Memory locations in use: One word, LENSRC, for the length of bytes to copy +; Two arrays, SOURCE & DEST, to copy from SOURCE to DEST +; +memcpy + pshy ; Save Y to the stack + pshx ; Save X to the stack + pshd ; Save D to the stack + ldy #SOURCE ; Load the address of the source array into Y + ldx #DEST ; Load the address of the destination array into X + ldd LENSRC ; Load the length of the source array into D +loop tbeq D,EXIT ; If d==0, jump to EXIT + movb Y,X ; Copy data from address in Y to address in X + inx ; Increment X by 1 + iny ; Increment Y by 1 + subd #1 ; Decrement D by 1 + bra loop ; Branch always to loop +EXIT puld ; Restore D from the stack + pulx ; Restore X from the stack + puly ; Restore Y from the stack + rts ; Return to caller + +* +************************************************************************** + +done + end ; Last line of the file
\ No newline at end of file |
