diff options
Diffstat (limited to 'cmpen472hw12_McDonnell/Sources')
| -rw-r--r-- | cmpen472hw12_McDonnell/Sources/main.asm | 119 |
1 files changed, 113 insertions, 6 deletions
diff --git a/cmpen472hw12_McDonnell/Sources/main.asm b/cmpen472hw12_McDonnell/Sources/main.asm index b2b5d0d..2e2b5e6 100644 --- a/cmpen472hw12_McDonnell/Sources/main.asm +++ b/cmpen472hw12_McDonnell/Sources/main.asm @@ -2,11 +2,11 @@ * * Title: Memory Monitor * -* Objective: CMPEN 472 Homework 6 +* Objective: CMPEN 472 Homework 12 * * Revision: V1.0 * -* Date: Feb. 28, 2025 +* Date: APR. 25, 2025 * * Programmer: Jacob McDonnell * @@ -29,8 +29,10 @@ * * Observation: This program will prompt the user to print the contents of a * memory location and to modify the location with hexadecimal or -* decimal data. If the user wishes, they can type 'QUIT' to exit -* the memory monitor and enter the type writer program. +* decimal data. The user can also load in chunks of data and +* print chunks of memory. If the user wishes, they can type +* 'QUIT' to exit the memory monitor and enter the type writer +* program. * * Note: ON CSM-12C128 board, * @@ -61,6 +63,7 @@ CR equ $0d ; carriage return, ASCII 'Return' key LF equ $0a ; line feed, ASCII 'next line' character NULL equ $00 ; NULL Terminator character +* ************************************************************************** * Data Section: address used [ $3000 to $30FF ] RAM Memory * @@ -77,6 +80,8 @@ buffer2 ds.b $0010 ; Array of 16 bytes for reading and reve dc.b NULL ; NULL terminated lenBuf2 dc.w $0010 ; length of buffer2 +charCount dc.b $00 ; Number of characters read by ReadHex + * * There is a section Data Section at the end of the file ************************************************************************** @@ -311,9 +316,15 @@ ReadHex pshd ; Save D to the stack ldy #0 ; Clear Y register ldab 1,x+ ; Read character from X into B, add 1 to X + clra ; clear A accumulator + staa charCount ; Clear charCount cmpb #'$' ; Compare B to '$' bne rHError ; If B != '$', jump to error, not hex data -rHLoop ldab 1,x+ ; Read Next character from X +rHLoop inc charCount ; Increment charCount by 1 + ldab charCount ; Load charCount into B + cmpb #5 ; At most 4 hex digits to read + bhi rHError ; If charCount > 5, error + ldab 1,x+ ; Read Next character from X beq rHDone ; If B == 0, exit loop cmpb #' ' ; Compare B to space character beq rHDone ; If B == ' ', exit loop @@ -343,6 +354,7 @@ rHAlpha cmpb #'A' ; Compare B to 'A' character aby ; Add B to Y bra rHLoop ; Branch always to rHLoop rHDone clra ; clear A accumulator + staa charCount ; Clear charCount tap ; Transfer A into CCR to clear zero bit puld ; Restore D from the stack rts ; Return to caller @@ -351,6 +363,23 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR puld ; Restore D from the stack rts ; Return to caller +;************************************************************************* +; MDCommand subroutine +; +; This subroutine is the MD command for the user. This subroutine will take in +; a memory address and a length of bytes, and will print the bytes starting at +; that memory location in 16 byte line segments. +; +; Input: A memory address in register X & a length of bytes in Y +; Output: The data in memory starting at the address in X in 16 +; byte line segments on the serial console. +; Registers in use: X for the address of the contents and for a buffer while printing, +; D for multiplication, B for the character, Y for output value. +; Memory locations in use: Memory Address for serial line, address of the string +; +; Comments: This subroutine Requires PrintHexWord & PrintHexByte. +; + MDCommand pshx ; Save X to the stack pshy ; Save Y to the stack @@ -407,6 +436,25 @@ MDDone ldaa #CR ; Load CR into A pulx ; Restore X from the stack rts ; Return +;************************************************************************* +; LDCommand subroutine +; +; This subroutine is the LD command for the user. This subroutine will take in +; a memory address and a length of bytes, and will take bytes entered by the +; user and write them to memory. +; +; Input: A memory address in register X & a length of bytes in Y +; Bytes of data entered by the user on the serial console. +; Output: The data inputted into memory starting at the address in X. +; Registers in use: X for the address of the contents and for a buffer while printing, +; D for multiplication, B for the character, Y for output value. +; Memory locations in use: Memory Address for serial line, address of the string +; +; Comments: This subroutine Requires PrintHexWord, ReadHexByte, & PrintHexByte. +; This subroutine will stop reading once the inputted number of bytes +; is read. +; + LDCommand pshx ; Save X to the stack pshy ; Save Y to the stack @@ -467,11 +515,38 @@ LDInvalid ldaa #CR ; Load CR into A pulx ; Restore X from the stack rts ; Return +;************************************************************************* +; GetCharLoop subroutine +; +; This subroutine will read a byte from input and will block until there is data +; to read. +; +; Input: A byte entered on the serial console. +; Output: That byte in register A. +; Registers in use: A for the byte inputted by the user. +; Memory locations in use: Memory Address for serial line +; +; Comments: This subroutine will block until the user inputs data. +; + GetCharLoop jsr getchar ; Read character from serial beq GetCharLoop ; If 0, loop rts ; Return +;************************************************************************* +; IsValidHex subroutine +; +; This subroutine set the zero bit if the given character is not valid hex. +; +; Input: An ASCII character in register A. +; Output: Zero bit set if invalid hex. (Valid if '0' <= A <= '9' or 'A' <= A <= 'F') +; Registers in use: A for the given character, CCR for output. +; Memory locations in use: No memory locations used. +; +; Comments: This subroutine only validates upper case hex. +; + IsValidHex cmpa #'0' ; Compare A to '0' blo InvalidHex ; A < '0', invalid @@ -506,7 +581,13 @@ InvalidHex orcc #%00000100 ; Set the Zero Bit ReadDecimal pshd ; Save D to the stack ldy #0 ; Clear Y register -dHLoop ldab 1,x+ ; Read Next character from X + clrb ; Clear B + stab charCount ; Clear charCount +dHLoop inc charCount ; Increment charCount by 1 + ldab charCount ; Load charCount into B + cmpb #6 ; Compare to B to 6 + bhi dHError ; B > 6, bad too many characters. + ldab 1,x+ ; Read Next character from X beq dHDone ; If B == 0, exit loop cmpb #' ' ; Compare B to space character beq dHDone ; If B == ' ', exit loop @@ -655,6 +736,19 @@ bPrintDone puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack rts ; Return to caller +;************************************************************************* +; PrintHexByte subroutine +; +; This subroutine will print a given byte to serial in Hex format. +; +; Input: 1 byte of data in B +; Output: Hex representation in ASCII on serial console +; Registers in use: X for division, A and B for characters. +; Memory locations in use: Memory addresses for serial. +; +; Comments: This subroutine requires serial to be setup and putchar subroutine. +; + PrintHexByte pshd ; Save D to the stack pshy ; Save Y to the stack @@ -685,6 +779,19 @@ PrintDone jsr putchar ; Print character to serial puld ; Restore D from the stack rts ; Return +;************************************************************************* +; ReadHexByte subroutine +; +; This subroutine will read a hex byte from serial console into A. +; +; Input: 2 ASCII characters of Hex format on serial console. +; Output: The data in register A. +; Registers in use: A for characters and B for multiplication. +; Memory locations in use: Memory addresses for serial. +; +; Comments: This subroutine requires serial to be setup and putchar subroutine. +; + ReadHexByte cmpa #'A' ; Compare A to 'A' blo RHBNotHex ; If A < 'A', decimal number |
