diff options
Diffstat (limited to 'cmpen472hw6_McDonnell/bin/main.dbg')
| -rw-r--r-- | cmpen472hw6_McDonnell/bin/main.dbg | 136 |
1 files changed, 95 insertions, 41 deletions
diff --git a/cmpen472hw6_McDonnell/bin/main.dbg b/cmpen472hw6_McDonnell/bin/main.dbg index eae7f5a..58fa190 100644 --- a/cmpen472hw6_McDonnell/bin/main.dbg +++ b/cmpen472hw6_McDonnell/bin/main.dbg @@ -77,9 +77,13 @@ Counter dc.w $0036 ; X register count number for time Delay LEVEL dc.b $0005 ; Light Level that the LED should be -buffer ds.b $000F ; Array of 16 bytes to read a string - dc.b NULL -lenBuf dc.w $000F ; Length of str array +buffer ds.b $0010 ; Array of 16 bytes to read a string + dc.b NULL ; NULL terminated +lenBuf dc.w $0010 ; Length of buffer array + +buffer2 ds.b $0010 ; Array of 16 bytes for reading and reversal + dc.b NULL ; NULL terminated +lenBuf2 dc.w $0010 ; length of buffer2 * There is a second Data Section at the end of the file. * ************************************************************************** @@ -127,6 +131,9 @@ mainLoop ldaa #LF jsr putchar + ldx #Counter + jsr PrintMem + bra mainLoop ldx #msg ; Load the address of msg into X @@ -172,6 +179,61 @@ twReadLoop jsr getchar ; Read Character from Serial CheckInput rts ; Return to caller + + +PrintMem + pshy ; Save Y to the Stack + pshd ; Save D to the Stack + exg x,d ; Copy Address from X to D to print + ldy #buffer ; Load the address of buffer into Y + jsr PrintHexWord ; Print the Address in Hex + exg d,x ; Copy Address from D to X + ldaa #'=' ; Load the '=' character into A + jsr putchar ; Print the character to the seriel + ldaa #'>' ; Load the '>' character into A + jsr putchar ; Print the character to the seriel + ldd x ; Load data from address in X into D + ldx #buffer ; Load the address of the buffer into X + ldy lenBuf ; Load the length of the buffer into Y + jsr Zeros ; Fill the buffer with Zeros + jsr PrintBinaryWord ; Print the binary word to the seriel + psha ; Save A to the stack + ldaa #' ' ; Load Space character into A + jsr putchar ; Print Space character to the seriel + jsr putchar ; Print Space character to the seriel + pula ; Restore A from the stack + ldy #buffer ; Load the address of the buffer into Y + jsr PrintHexWord ; Prin the hex representation of the word to seriel + psha ; Save A to the stack + ldaa #' ' ; Load Space character into A + jsr putchar ; Print Space character to the seriel + jsr putchar ; Print Space character to the seriel + pula ; Restore A from the stack + ldx #buffer ; Load the address of the buffer into X + ldy lenBuf ; Load the length of the buffer into Y + jsr Zeros ; Fill the buffer with Zeros + ldy #buffer ; Load the address of the buffer into Y + jsr PrintDecimalWord; Prin the decimal representation of the word to seriel + ldaa #CR ; Load the carriage return character into A + jsr putchar ; Print the character to seriel + ldaa #LF ; Load the line feed character into A + jsr putchar ; Print the character to seriel + puld ; Restore D from the stack + puly ; Restore Y from the stack + rts ; Return to caller + +strrev + pshx ; Save X to the stack + pshy ; Save Y to the stack + psha ; Save A to the stack +revLoop ldaa 1,y- ; Load Character from Y into A, decrement Y + beq revDone ; If Character is 0, exit loop + staa 1,x+ ; Save character in address in X, increment X + bra revLoop ; Loop back always +revDone pula ; Restore A from the stack + puly ; Restore Y from the stack + pulx ; Restore X from the stack + rts ; Return to caller ;************************************************************************* ; PrintBinaryWord subroutine @@ -227,47 +289,43 @@ PrintHexWord pshx ; Save X to the stack pshd ; Save D (A:B) to the stack pshy ; Save Y to the stack - iny ; Increment Y by 1 - iny ; Increment Y by 1 - iny ; Increment Y by 1 - iny ; Increment Y by 1 - ldx #5 ; Load 5 into X since we have at most 4 digits -hPrintLoop dex ; Decrement X by 1 - beq hPrintDone ; If X == 0, exit Loop - pshx ; Save X to the stack - ldx #16 ; Load 16 in X for division +hPrintLoop ldx #16 ; Load 16 in X for division idiv ; Divide D / 16 to get Hex Digit - cpd #0 ; Compare D to 0 - beq hPrintDone ; If D == 0, exit loop - cmpb #$0A ; Compare A to $0A + cpx #0 ; Compare X to 0 + beq hCheck ; If X == 0, branch to check D is zero +hDNotZero cmpb #$0A ; Compare A to $0A blt hex10 ; If B < $A, branch to hex10 addb #'A' ; Add 'A' to B to get ASCII Character subb #$0A ; Subtract $A to adjust characters - stab 1,-y ; Save character from B to Y + stab 1,+y ; Save character from B to Y exg X,D ; Swap values in X and D - pulx ; Restore Count from stack to X bra hPrintLoop ; loop to hPrintLoop hex10 addb #'0' ; Add '0' to B to get ASCII Character - stab 1,-y ; Save character from B to Y + stab 1,+y ; Save character from B to Y exg X,D ; Swap values in X and D - pulx ; Restore Count from stack to X bra hPrintLoop ; Loop to hPrintLoop -hPrintDone ldaa #'$' ; Load '$' into A - jsr putchar ; Print '$' to denote Hex Number - exg Y,X ; Move Address from Y to X +hCheck cpd #0 ; Compare D to 0 + bne hDNotZero ; If D != 0, branch back to hDNotZero +hPrintDone ldaa #'$' ; Load '$' into + staa 1,+y ; Save '$' into buffer in Y to denote Hex + ldx #buffer2 ; Load the address of buffer2 in X + jsr strrev ; Reverse string in Y in buffer in X jsr WriteString ; Jump to write string to write the number + ldy lenBuf2 ; Load the length of buffer2 into Y + ldx #buffer2 ; Load the address of buffer2 into X + jsr Zeros ; Fill buffer2 with zeros puly ; Restore Y from the stack puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack rts ; Return to caller ;************************************************************************* -; PrintHexWord subroutine +; PrintDecimalWord subroutine ; ; This subroutine will print a given word of data to the serial in binary. ; ; Input: 1 word of data in register D, Buffer Address in Y -; Output: Hexadecimal representation of the data on the serial console +; Output: Decimal representation of the data on the serial console ; Registers in use: Y for the address of the buffer, X to count the number of bits ; written and for division, D for the input, A for characters. ; Memory locations in use: Memory addresses for serial. @@ -279,26 +337,22 @@ PrintDecimalWord pshx ; Save X to the stack pshd ; Save D (A:B) to the stack pshy ; Save Y to the stack - iny ; Increment Y by 1 - iny ; Increment Y by 1 - iny ; Increment Y by 1 - iny ; Increment Y by 1 - iny ; Increment Y by 1 - ldx #6 ; Load 5 into X since we have at most 5 digits -dPrintLoop dex ; Decrement X by 1 - beq dPrintDone ; If X == 0, exit Loop - pshx ; Save X to the stack - ldx #10 ; Load 10 in X for division - idiv ; Divide D / 16 to get Hex Digit - cpd #0 ; Compare D to 0 - beq dPrintDone ; If D == 0, exit loop - addb #'0' ; Add '0' to B to get ASCII Character - stab 1,-y ; Save character from B to Y +dPrintLoop ldx #10 ; Load 10 in X for division + idiv ; Divide D / 10 to get Hex Digit + cpx #0 ; Compare X to 0 + beq dCheck ; If X == 0, branch to check D is zero +dDNotZero addb #'0' ; Add '0' to B to get ASCII Character + stab 1,+y ; Save character from B to Y exg X,D ; Swap values in X and D - pulx ; Restore Count from stack to X bra dPrintLoop ; Loop to hPrintLoop -dPrintDone exg Y,X ; Move Address from Y to X +dCheck cpd #0 ; Compare D to 0 + bne dDNotZero ; If D != 0, branch back to hDNotZero +dPrintDone ldx #buffer2 ; Load the address of buffer2 in X + jsr strrev ; Reverse string in Y in buffer in X jsr WriteString ; Jump to write string to write the number + ldy lenBuf2 ; Load the length of buffer2 into Y + ldx #buffer2 ; Load the address of buffer2 into X + jsr Zeros ; Fill buffer2 with zeros puly ; Restore Y from the stack puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack |
