summaryrefslogtreecommitdiff
path: root/cmpen472hw6_McDonnell/bin/main.dbg
diff options
context:
space:
mode:
Diffstat (limited to 'cmpen472hw6_McDonnell/bin/main.dbg')
-rw-r--r--cmpen472hw6_McDonnell/bin/main.dbg242
1 files changed, 144 insertions, 98 deletions
diff --git a/cmpen472hw6_McDonnell/bin/main.dbg b/cmpen472hw6_McDonnell/bin/main.dbg
index 34c58c5..066f6eb 100644
--- a/cmpen472hw6_McDonnell/bin/main.dbg
+++ b/cmpen472hw6_McDonnell/bin/main.dbg
@@ -1,42 +1,38 @@
**************************************************************************
*
-* Title: Hardware Controller
+* Title: Memory Monitor
*
-* Objective: CMPEN 472 Homework 5
+* Objective: CMPEN 472 Homework 6
*
* Revision: V1.0
*
-* Date: Feb. 21, 2025
+* Date: Mar. 1, 2025
*
* Programmer: Jacob McDonnell
*
* Company: The Pennsylvania State University
* Department of Computer Science and Engineering
*
-* Algorithm: Simple Serial I/O, Parallel I/O use, time delay-loop, and PWM control
+* Algorithm: Simple Serial I/O, address poking and modifying
*
-* Register Use: A & B to control LEDS initially, Light Level, current byte, etc
-* X & Y to hold the counter in the loop and address of strings and length of string.
+* Register Use: A & B to current byte, etc,
+* X & Y holds address of strings and length of string,
+* D to hold data and address of the memory location to work on.
*
* Memory Use: RAM Locations from $3000 for data,
* RAM Locations from $3100 for program
*
-* Input: Parameters hard-coded in the program - PORTB
-* Serial Port for User Input
+* Input: Serial Port for User Input
*
-* Output: LED 1 at PORTB bit 4
-* LED 2 at PORTB bit 5
-* LED 3 at PORTB bit 6
-* LED 4 at PORTB bit 7
-* Serial Port for String Output
+* Output: Serial Port for String Output
+* Memory locations changed if modified by user
*
-* Observation: This program will respond to user input to turn on and off LEDs 1, 2, & 3,
-* Dim LED 4 from 100% to 0%, Dim LED 4 from 0% to 100%, and echo user input
-* back to the terminal in Type Writer Mode.
+* 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.
*
* Note: ON CSM-12C128 board,
-* Switch 1 is at PORTB bit 0, and
-* LED 4 is at PORTB bit 7.
*
* Comments: This program is developed and simulated using CodeWarrior
* development software and targeted for Axion
@@ -70,12 +66,8 @@ NULL equ $00 ; NULL Terminator character
*
org $3000 ; Reserved RAM memory starting address
; for Data for CMPEN 472 class
-Counter dc.w $0036 ; X register count number for time Delay
- ; loop for 10 useconds
- ; The work to calculate this number is in
- ; the comments for the delay10usec subroutine.
-
-LEVEL dc.b $0005 ; Light Level that the LED should be
+TESTER dc.w $0005 ; Memory location to test showing data
+ ; and writing data.
buffer ds.b $0010 ; Array of 16 bytes to read a string
dc.b NULL ; NULL terminated
@@ -85,14 +77,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
-badAddr dc.b 'invalid input, address',CR,LF,NULL ; Error message for bad address
-
-badData dc.b 'invalid input, data',CR,LF,NULL ; Error message for bad data
-
-badCom dc.b 'invalid input, command',CR,LF,NULL ; Error message for bad command
-
-* There is a second Data Section at the end of the file.
*
+* There is a section Data Section at the end of the file
**************************************************************************
* Program Section: address used [ $3100 to $3FFF ] RAM Memory
*
@@ -107,24 +93,26 @@ pgstart lds #$3100 ; initialize the stack pointer
ldd #$0001 ; Set SCI Baud Register = $0001 => 1.5M baud at 24MHz (for simulation)
std SCIBDH ; SCI port baud rate change
-
+
+ ldx #msg ; Load the address of the welcome message into X
+ jsr WriteString ; Write the string to the serial console
mainLoop
- ldx #buffer
- ldy lenBuf
- jsr Zeros
+ 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
ldaa #'>' ; Load '>' into A
jsr putchar ; Jump to putchar to write to console
ldaa #' ' ; Load space character into A
jsr putchar ; Jump to putchar to write to console
-
- ldx #buffer
- ldy lenBuf
- jsr ReadString
-
- ldx #buffer
- jsr CheckInput
+
+ ldx #buffer ; Load the address of the buffer into X
+ ldy lenBuf ; Load the length of the buffer into Y
+ jsr ReadString ; Read a line from the serial console
+
+ ldx #buffer ; Load the address of the buffer into X
+ jsr CheckInput ; Jump to CheckInput to parse the user input
bra mainLoop ; Loop back to mainLoop always
TypeWriter ldx #twMsg ; Load Type Writer welcome message address
jsr WriteString ; Jump to WriteString to write message to serial
@@ -168,20 +156,19 @@ CheckInput
cmpa #'$' ; Compare A to '$'
bne cUnknownCMD ; If A != '$', branch to unknown command
jsr ReadHex ; ReadHex to Read the memory Address
- beq cBadAddr ; If Z == 1, branch to cBadAddr
+ beq cBadAddr ; If Z == 1, branch to cBadAddr
exg Y,X ; Exchange Y for X
pshx ; Save X to the stack
ldx #buffer ; Load address of buffer into X
ldy lenBuf ; Loadd length of the buffer into Y
jsr Zeros ; Fill buffer with Zeros
pulx ; Restore X from the stack
- jsr PrintMem ; Print the data at the memory address
bra cDone ; branch always to cDone
cWrite ldaa 0,x ; Load next character but don't increment
cmpa #'$' ; Compare A to '$'
bne cUnknownCMD ; If A != '$', branch to unknown command
jsr ReadHex ; ReadHex to Read the memory Address
- beq cBadAddr ; If Z == 1, branch to cBadAddr
+ beq cBadAddr ; If Z == 1, branch to cBadAddr
exg Y,D ; Exchange Y and D
pshd ; Save D to the stack
skipSpaces ldaa 1,x+ ; Load next character into A
@@ -192,25 +179,25 @@ skipSpaces ldaa 1,x+ ; Load next character into A
beq cHexData ; If A == '$', branch to cHexData
dex ; Decrement X by 1
jsr ReadDecimal ; Jump to ReadDecimal
- beq cBadData ; If Z == 1, branch to cBadData
+ beq cBadData ; If Z == 1, branch to cBadData
bra cWriteData ; Branch always to cWriteData
cHexData dex ; Decrement X by 1
jsr ReadHex ; Jump to ReadHex to read hex data
- beq cBadData ; If Z == 1, branch to cBadData
+ beq cBadData ; If Z == 1, branch to cBadData
cWriteData puld ; Restore D from the stack
exg D,X ; Exchange D and X
sty x ; Write data in Y to memory in X
- bra cDone ; Branch always to cDone
-cDone puld ; Restore D from the stack
+cDone jsr PrintMem ; Jump to PrintMem to print the contents of the location
+ puld ; Restore D from the stack
pulx ; Restore X from the stack
rts ; Return to caller
cBadAddr ldx #badAddr ; Load the address of badAddr into X
- jsr WriteString ; Write badAddr to seriel console
+ jsr WriteString ; Write badAddr to serial console
puld ; Restore D from the stack
pulx ; Restore X from the stack
rts ; Return to caller
cBadData ldx #badData ; Load the address of badData into X
- jsr WriteString ; Write badData to seriel console
+ jsr WriteString ; Write badData to serial console
puld ; Restore D from the stack
puld ; Restore D from the stack
pulx ; Restore X from the stack
@@ -232,7 +219,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X
ldaa 1,x+ ; Load next character from X
bne cUnknownCMD ; If A != 0, branch to unknown command
jmp TypeWriter ; Jump to TypeWriter
-
+
;*************************************************************************
; ReadHex subroutine
;
@@ -241,7 +228,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X
;
; Input: A memory address in register X.
; Output: The value of the hex number in the Y register, and any errors printed
-; to the seriel line. Zero bit is set if error occurs.
+; to the serial line. Zero bit is set if error occurs.
; 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
@@ -249,7 +236,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X
; Comments: This subroutine will return the value in the Y register, and if an error occurs,
; the Zero bit in the CCR will be set.
;
-
+
ReadHex
pshd ; Save D to the stack
ldy #0 ; Clear Y register
@@ -293,7 +280,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR
tap ; Transfer A into CCR to set zero bit and warn error
puld ; Restore D from the stack
rts ; Return to caller
-
+
;*************************************************************************
; ReadDecimal subroutine
;
@@ -302,7 +289,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR
;
; Input: A memory address in register X.
; Output: The value of the number in the Y register, and any errors printed
-; to the seriel line. Zero bit is set if error occurs.
+; to the serial line. Zero bit is set if error occurs.
; 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
@@ -310,7 +297,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR
; Comments: This subroutine will return the value in the Y register, and if an error occurs,
; the Zero bit in the CCR will be set.
;
-
+
ReadDecimal
pshd ; Save D to the stack
ldy #0 ; Clear Y register
@@ -338,7 +325,7 @@ dHError ldaa #4 ; Load 4 into A to set zero bit in CCR
tap ; Transfer A into CCR to set zero bit and warn error
puld ; Restore D from the stack
rts ; Return to caller
-
+
;*************************************************************************
; PrintMem subroutine
;
@@ -346,15 +333,15 @@ dHError ldaa #4 ; Load 4 into A to set zero bit in CCR
;
; Input: A memory address in register X.
; Output: The memory address in Hex and the contents in binary, hex, & decimal
-; on the seriel output.
+; on the serial output.
; Registers in use: X for the address of the contents and for a buffer while printing,
; D for the contents of the location, Y for another buffer address while
; reversing strings and printing.
; Memory locations in use: Memory Address for serial line, address of the string
;
-; Comments: This subroutine requires the seriel console to be setup before calling.
+; Comments: This subroutine requires the serial console to be setup before calling.
;
-
+
PrintMem
pshy ; Save Y to the Stack
pshd ; Save D to the Stack
@@ -363,39 +350,39 @@ PrintMem
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
+ jsr putchar ; Print the character to the serial
ldaa #'>' ; Load the '>' character into A
- jsr putchar ; Print the character to the seriel
+ jsr putchar ; Print the character to the serial
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
+ jsr PrintBinaryWord ; Print the binary word to the serial
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
+ jsr putchar ; Print Space character to the serial
+ jsr putchar ; Print Space character to the serial
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
+ jsr PrintHexWord ; Prin the hex representation of the word to serial
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
+ jsr putchar ; Print Space character to the serial
+ jsr putchar ; Print Space character to the serial
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
+ jsr PrintDecimalWord; Prin the decimal representation of the word to serial
ldaa #CR ; Load the carriage return character into A
- jsr putchar ; Print the character to seriel
+ jsr putchar ; Print the character to serial
ldaa #LF ; Load the line feed character into A
- jsr putchar ; Print the character to seriel
+ jsr putchar ; Print the character to serial
puld ; Restore D from the stack
puly ; Restore Y from the stack
rts ; Return to caller
-
+
;*************************************************************************
; strrev subroutine
;
@@ -411,7 +398,7 @@ PrintMem
; Comments: This subroutine will not check that the output buffer is large enough, that
; is the job of the caller.
;
-
+
strrev
pshx ; Save X to the stack
pshy ; Save Y to the stack
@@ -420,7 +407,9 @@ revLoop ldaa 1,y- ; Load Character from Y into A, decremen
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
+ clra ; Set A to Zero
+revDone staa 1,x+ ; Copy Null terminator into new string
+ pula ; Restore A from the stack
puly ; Restore Y from the stack
pulx ; Restore X from the stack
rts ; Return to caller
@@ -439,7 +428,7 @@ revDone pula ; Restore A from the stack
; Comments: This subroutine requires serial to be setup and putchar subroutine.
;
-PrintBinaryWord
+PrintBinaryWord
pshx ; Save X to the stack
pshd ; Save D (A:B) to the stack
pshb ; Save B to the stack (we want these bits again later)
@@ -460,7 +449,7 @@ bPrintLoop rolb ; Rotate MSB of B into C of CCR
bPrintDone puld ; Restore D (A:B) from the stack
pulx ; Restore X from the stack
rts ; Return to caller
-
+
;*************************************************************************
; PrintHexWord subroutine
;
@@ -468,17 +457,31 @@ bPrintDone puld ; Restore D (A:B) from the stack
;
; Input: 1 word of data in register D, Buffer Address in Y
; Output: Hexadecimal 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
+; 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.
;
; Comments: This subroutine requires serial to be setup and putchar subroutine.
;
-
+
PrintHexWord
pshx ; Save X to the stack
pshd ; Save D (A:B) to the stack
pshy ; Save Y to the stack
+ cpd #0 ; Compare D to zero
+ beq hIsZero ; Branch to hIsZero
+ psha ; Save A to the stack
+ pshy ; Save Y to the stack
+ pshx ; Save x to the stack
+ ldaa #'0' ; Load the '0' character into A
+ ldx #buffer2 ; Load the address of buffer2 into X
+ ldy #5 ; Load 5 into Y
+ jsr memset ; Write '0' to the first 5 bytes in buffer2
+ pulx ; Restore X from the stack
+ puly ; Restore Y from the stack
+ clra ; Set A to zero
+ staa 0,y ; Load Zero into Y for Null Terminator
+ pula ; Restore A from the stack
hPrintLoop ldx #16 ; Load 16 in X for division
idiv ; Divide D / 16 to get Hex Digit
cpx #0 ; Compare X to 0
@@ -496,7 +499,7 @@ hex10 addb #'0' ; Add '0' to B to get ASCII Character
bra hPrintLoop ; Loop to hPrintLoop
hCheck cpd #0 ; Compare D to 0
bne hDNotZero ; If D != 0, branch back to hDNotZero
-hPrintDone ldaa #'$' ; Load '$' into
+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
@@ -508,7 +511,15 @@ hPrintDone ldaa #'$' ; Load '$' into
puld ; Restore D (A:B) from the stack
pulx ; Restore X from the stack
rts ; Return to caller
-
+hIsZero ldaa #'$' ; Load '$' character into A
+ jsr putchar ; Print character to the screen
+ ldaa #'0' ; Load '0' character into A
+ jsr putchar ; Print character to the screen
+ puly ; Restore Y from the stack
+ puld ; Restore D (A:B) from the stack
+ pulx ; Restore X from the stack
+ rts ; Return to caller
+
;*************************************************************************
; PrintDecimalWord subroutine
;
@@ -516,17 +527,31 @@ hPrintDone ldaa #'$' ; Load '$' into
;
; Input: 1 word of data in register D, Buffer Address in Y
; 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
+; 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.
;
; Comments: This subroutine requires serial to be setup and putchar subroutine.
;
-
+
PrintDecimalWord
pshx ; Save X to the stack
pshd ; Save D (A:B) to the stack
pshy ; Save Y to the stack
+ cpd #0 ; Compare D to zero
+ beq dIsZero ; Branch to hIsZero
+ psha ; Save A to the stack
+ pshy ; Save Y to the stack
+ pshx ; Save x to the stack
+ ldaa #'0' ; Load the '0' character into A
+ ldx #buffer2 ; Load the address of buffer2 into X
+ ldy #5 ; Load 5 into Y
+ jsr memset ; Write '0' to the first 5 bytes in buffer2
+ pulx ; Restore X from the stack
+ puly ; Restore Y from the stack
+ clra ; Set A to zero
+ staa 0,y ; Load Zero into Y for Null Terminator
+ pula ; Restore A from the stack
dPrintLoop ldx #10 ; Load 10 in X for division
idiv ; Divide D / 10 to get Hex Digit
cpx #0 ; Compare X to 0
@@ -547,7 +572,13 @@ dPrintDone ldx #buffer2 ; Load the address of buffer2 in X
puld ; Restore D (A:B) from the stack
pulx ; Restore X from the stack
rts ; Return to caller
-
+dIsZero ldaa #'0' ; Load '0' character into A
+ jsr putchar ; Print character to the screen
+ puly ; Restore Y from the stack
+ puld ; Restore D (A:B) from the stack
+ pulx ; Restore X from the stack
+ rts ; Return to caller
+
;*************************************************************************
; Zeros subroutine
;
@@ -570,6 +601,24 @@ zerosLoop staa 1,x+ ; Load A into byte at X
rts ; Return to caller
;*************************************************************************
+; memset subroutine
+;
+; This subroutine will write a given byte to every byte in a given array.
+;
+; Input: Address of an array in X and its length in Y, the byte in A
+; Output: The given byte in every byte of an array.
+; Registers in use: X for the address of the array, Y for the length, and A for the given byte
+; Memory locations in use: Memory Address of the array
+;
+; Comments: This subroutine requires serial to be setup and putchar subroutine.
+;
+
+memset
+ staa 1,x+ ; Load A into byte at X
+ dbne y,memset ; Decrement Y and loop if Y != 0
+ rts ; Return to caller
+
+;*************************************************************************
; WriteString subroutine
;
; This subroutine will write a given null terminated string to the serial.
@@ -625,7 +674,6 @@ doneRead ldaa #LF ; Load Line Feed into A
pula ; restore A from the stack
rts ; return to caller
-
;*************************************************************************
; putchar subroutine
;
@@ -658,26 +706,24 @@ getchar brclr SCISR1,#%00100000,getchar7 ; If no input on SCI port, r
getchar7 clra ; Set A to 0
rts ; Return to caller
+*
**************************************************************************
-* Data Section: address used [ $3100 to $3FFF ] RAM Memory
+* Data Section 2: address used [ $3100 to $3FFF ] RAM Memory
*
-; unknown: string to warn the user of unknown output
-unknown dc.b 'Error: Unknown Command',CR,LF,NULL
+badAddr dc.b 'invalid input, address',CR,LF,NULL ; Error message for bad address
+
+badData dc.b 'invalid input, data',CR,LF,NULL ; Error message for bad data
+
+badCom dc.b 'invalid input, command',CR,LF,NULL ; Error message for bad command
; twMsg: welcome message when type writer loads
twMsg dc.b 'Welcome to Type Writer, you may type below.',CR,LF
dc.b 'Restart to enter main menu again.',CR,LF,NULL
-; msg: this is the main option menu string
-msg dc.b 'L1: Turn on LED1',CR,LF
- dc.b 'F1: Turn off LED1',CR,LF
- dc.b 'L2: Turn on LED2',CR,LF
- dc.b 'F2: Turn off LED2',CR,LF
- dc.b 'L3: Turn on LED3',CR,LF
- dc.b 'F3: Turn off LED3',CR,LF
- dc.b 'L4: LED4 goes from 0% light level to 100% light level in 0.4 seconds',CR,LF
- dc.b 'F4: LED4 goes from 100% light level to 0% light level in 0.4 seconds',CR,LF
- dc.b 'QUIT: Quit menu program, run Type writer program.',CR,LF,NULL
+; msg: this is the main option menu string
+msg dc.b 'S: Show the contents of memory location in word',CR,LF
+ dc.b 'W: Write the data word (not byte) to memory location',CR,LF
+ dc.b 'QUIT: Quit the main program, run Type writer program.',CR,LF,NULL