;------------------------------------------------------------------------------
;Steven Heller
;ECE 190 AD1
;27 Feb. 2007
;MP 2.1
;
;INTRO PARAGRAPH
;
;------------------------------------------------------------------------------
;Register Table
;The values of the registers and the purpose of them change throught the
;program. Thier use and what they hold is explaiend as the program progresses.
;------------------------------------------------------------------------------
.ORIG x3000 ;start program at x3000
;intialize registers for the zero fill loop
AND R0, R0, #0 ;set R0 with all 0's
LD R1, DATABASESTART ;set R1 with the start of the database to act as a counter
LD R2, DATABASEEND ;set R2 with the end of the database
;R3 will be a temporary register
ZEROFILL_LOOP: ;go from x4000 to x4D3F and fill in all 0's
STR R0, R1, #0 ;store a zero in the database
ADD R1, R1, #1 ;increment the database location
NOT R3, R1 ;not R1 so we can subtract
ADD R3, R3, #1 ;add one the complimented R1
ADD R3, R2, R3 ;subtract R3 from the end of the database R2
BRzp ZEROFILL_LOOP ;as long as the subtraction was positive or negative
;continue the loop
;reset registers for safety - this may no be needed
;AND R0, R0, #0
;AND R1, R1, #0
;AND R2, R2, #0
;AND R3, R3, #0
;initialize registers for reading the schedule
LD R0, SCHEDULESTART ;load R0 with the address of the first schedule location
LD R3, ASCIIOFFSET ;load R3 with the value to subtract ASCII from (-x0030 = xFFD0)
;R1 temp register to hold the hex value of the character and later the addr loc to write in
; database
;R2 to hold the binary value of the day | modified later to compute ADDR LOC
;R4 to hold the binary value of the hour | modified later to computer ADDR LOC
;R5 temp register
SCHEDULE_READ_LOOP:
LDR R1, R0, #0 ;load the value at the address in R0 to R1
BRz PRE_PRINT ;if the first character is NUL then go to pre_print subroutine
;either there is no database or the end of the schedule has been reached
;the next lines of code check to see if the character is between 0-6
ADD R2, R1, R3 ;subtract the valule in R1 from R3 to get the binary value
BRn ERROR ;if the hex value of R2 was less than the hex value of 0,
;there is an error
ADD R5, R2, #-6 ;add -6 to R2 to see if it is between 0-6
BRp ERROR ;If positive the number is greater than 6, go to Error
;the next lines of code is to check if the second char is between 0-9
ADD R0, R0, #1 ;increment R0 by one to move to next memory location
LDR R1, R0, #0 ;load the value of the memory to R1 (hex character)
BRz ERROR ;If the first char is NUL x0000 then there is an error
ADD R4, R1, R3 ;subtract x30 from the value and store in R4 the binary hour
BRn ERROR ;if negative the char has a value less than x30 (#0)
ADD R5, R2, #-9
BRp ERROR ;The value is greater than the number 9, so go to ERROR
;the first two chars must have both passed the uper test to get here
;get ADDR of where to write the task to | Stroed in R1
JSR RETURN_ADDRESS ;put addr of database into R1
;check to see if the first "task" char is NUL if so, go to ERROR
;R1 - holder of database addr
;R2 - holds the value in the schedule string
;R4 - holds the value at the addr location
ADD R0, R0, #1 ;update memory location of schedule string
LDR R2, R0, #0 ;load the value at R0 into R2 - R2 no longer needed
BRz ERROR ;the character weas NUL so go to error
;check to make sure that the location is x0000 or go to ERROR
LDR R4, R1, #0 ;load the value at the ADDR in R1 into R4
BRnp ERROR ;the value is not set to 0's, trying to refer to
;same location twice, go to ERROR
;The task has at least one char and the memory location is empty
;store the character to the first memory location, then loop
;increment memory location, get new character check if null
;if not null then repeat process, if it is go back to the start
;of the loop and repeat.
CHAR_STORE_LOOP:
STR R2, R1, #0 ;store the character in R2 into the memory location specified
;at R1
ADD R1, R1, #1 ;increment the memory location in the database for the word
ADD R0, R0, #1 ;increment schedule string location
LDR R2, R0, #0 ;store the character at R0 into R2
BRz NUL_EOS ;reached the end of the string (null reached) reapeat process
BRnzp CHAR_STORE_LOOP ;continue storing the chars into the database
NUL_EOS: ;a null value has been reached at the end of the schedule string...
ADD R0, R0, #1 ;the loop needs an updated R0 or it will use the NUL at the end of string
;and cause it to end too early. If the updated char is NUL then end.
BRnzp SCHEDULE_READ_LOOP ;repeat the top loop
;--------------------------------------------------------
RETURN_ADDRESS: ;computes x4000 + ((days*16) + hour) * 32
;R2 MUST BE DAY | R4 MUST BE HOUR | preconditions
;return R1 ADDR LOC postcondition
;Save the original values of R2 and R4 if wanted to be used again
;later
ST R2, SaveR2
ST R4, SaveR4
ST R7, SaveR7 ;for protection
;add day register to itself 4 times
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R4 ;add hour reg
;add new out to itself 5 times (*32)
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R2
ADD R2, R2, R2
;add DATABASESTART
LD R5, DATABASESTART
ADD R1, R5, R2
LD R2, SaveR2
LD R4, SaveR4
LD R7, SaveR7
RET ;return back to where it was called
;-----------------------------------------------------------
PRE_PRINT: ;the purpose of this is to call the PRINT subroutine and later quit
;the program once the PRINT is done, as the PRINT should not be
;responsible for quitting the program.
JSR PRINT ;call the print sub routine
BRnzp QUIT ;Done printing, quit program
;-----------------------------------------------------------
PRINT: ;Loop through the data base and print all text entires in the data base
;each task will be printed in order followed by a line break
;Keep track of hour and day. Computer addr loc where data would be. If the first
;character is NUL, then there is no data for that day|time go to next time
;if there is a non null character store in a block word untill a null is reached
;print the word with line break. then update time.
;when time > 9 update day. when day > 6 the print is done.
;New register values
;R0 - used for storing the address where the word to be printed begins
;R1 - holds the address where the task should be
;R2 - holds the day
;R4 - holds the hour
;R5 - temporary register
ST R7, SaveR7 ;store the value of the origianl R7 to return to
AND R2, R2, #0 ;Make R2 #0
AND R4, R4, #0 ;make R4 #0
PLOOP:
ADD R5, R2, #-6 ;check to see if the day is within 0-6
BRp DPRINT ;If it is positive, the print is done
I_PLOOP: ;inner loop for the hours
ADD R5, R4, #-9 ;check to see if all the hours have been looked at
BRp UCOUNTERS ;if it is postive, all hours have been looked at. update counters
;and go to PLOOP
JSR RETURN_ADDRESS ;store the adress of the task in R1
LDR R5, R1, #0 ;store the value at R1 into R5
BRz UHOUR ;if it is zero, the task is null, no need to print it
ADD R0, R1, #0 ;store the value in R1 to R0 for TRAP x22
TRAP x22 ;print the task. Will automatically stop at a NUL
LEA R0, LINEFEED ;set R0 to the memory loc with a line feed character
TRAP x22 ;add the line feed to the printout
BRnzp UHOUR ;update the hour and restart I_PLOOP
UHOUR:
ADD R4, R4, #1 ;update the hour by one
BRnzp I_PLOOP ;go back to the start of the inner loop with new coutner
UCOUNTERS:
AND R4, R4, #0 ;reset hour to 0
ADD R2, R2, #1 ;add one to the day
BRnzp PLOOP ;go back to the start of the original loop
DPRINT:
LD R7, SaveR7 ;make sure R7 is the original calling R7
RET ;return the the instruction held in R7 that called the PRINT
;----------------------------------------------------------
ERROR:
LEA R0, PARSESTRING ;load R0 with the first memory location of the string
TRAP x22 ;output PARSESTRING
BRnzp QUIT ;go to QUIT
;----------------------------------------------------------
QUIT:
TRAP x25 ;end the program
;----------------------------------------------------------
;----Variables and Constants to make things easier ---------------
DATABASESTART .FILL x4000 ; the start of the database
DATABASEEND .FILL x4D3F ; the end of the data base
ASCIIOFFSET .FILL xFFD0 ; the offset to subtract digits from to get binary
SCHEDULESTART .FILL x5000 ; denotes start of schedule string
NUL .FILL x0000 ; The NUL value
LINEFEED .STRINGZ "\n" ; The line feed character
PARSESTRING .STRINGZ "Parse Error.\n\n" ; makes error string with line breaks.
SaveR2 .BLKW 1 ;memory location to save the contents of R2
SaveR4 .BLKW 1 ;memory location to save R4
SaveR7 .BLKW 1 ;memory location to save R7
;OUTPUT_WORD .BLKW 32 ; Open 32 spots in memory for the output word.
.END