2016-07-01 22:14:14 +01:00
|
|
|
:start
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R8 @table ; Where we are putting our address pointers
|
|
|
|
LOADUI R9 0xFF ; Byte mask
|
|
|
|
LOADUI R10 0x0F ; nybble mask
|
|
|
|
LOADUI R11 1 ; Our toggle
|
|
|
|
FALSE R12 ; Our PC counter
|
|
|
|
LOADUI R13 0x600 ; Where we are starting our Stack
|
2016-06-27 01:18:19 +01:00
|
|
|
;; We will be using R14 for our condition codes
|
|
|
|
;; We will be using R15 for holding our processed nybbles
|
|
|
|
|
|
|
|
;; Prep TAPE_01
|
|
|
|
LOADUI R0 0x1100
|
|
|
|
FOPEN_READ
|
|
|
|
|
|
|
|
;; Prep TAPE_02
|
|
|
|
LOADUI R0 0x1101
|
|
|
|
FOPEN_WRITE
|
|
|
|
|
2016-09-06 00:18:20 +01:00
|
|
|
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Function for collecting the address of all labels
|
2016-07-01 22:14:14 +01:00
|
|
|
:getLables
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Check for EOF
|
2016-10-29 12:03:25 +01:00
|
|
|
CMPSKIPI.GE R0 0
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @stage2
|
|
|
|
|
|
|
|
;; Check for Label
|
2016-10-29 12:03:25 +01:00
|
|
|
CMPSKIPI.NE R0 58 ; If the Char is : the next char is the label
|
2016-06-27 01:18:19 +01:00
|
|
|
CALLI R13 @storeLabel
|
|
|
|
|
|
|
|
;; Check for pointer to label
|
2016-09-06 00:18:20 +01:00
|
|
|
CMPUI R14 R0 64 ; If the Char is @ the next char is the pointer to a label
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP.NE R14 @.L0
|
|
|
|
|
|
|
|
;; Ignore the pointer for now
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
2016-09-06 00:18:20 +01:00
|
|
|
ADDUI R12 R12 2 ; The pointer will end up taking 2 bytes
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @getLables
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:.L0
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Otherwise attempt to process
|
2016-09-06 00:18:20 +01:00
|
|
|
CALLI R13 @hex ; Convert it
|
2016-10-29 12:03:25 +01:00
|
|
|
CMPSKIPI.GE R0 0 ; Don't record, nonhex values
|
2016-09-06 00:18:20 +01:00
|
|
|
JUMP @getLables ; Move onto Next char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Determine if we got a full byte
|
2016-09-06 00:18:20 +01:00
|
|
|
JUMP.Z R11 @.L1 ; Jump if toggled
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Deal with case of first half of byte
|
2016-09-06 00:18:20 +01:00
|
|
|
FALSE R11 ; Flip the toggle
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @getLables
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:.L1
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Deal with case of second half of byte
|
2016-09-06 00:18:20 +01:00
|
|
|
TRUE R11 ; Flip the toggle
|
|
|
|
ADDUI R12 R12 1 ; increment PC now that we have a full byte
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @getLables
|
|
|
|
|
|
|
|
;; Function for storing the address of the label
|
2016-07-01 22:14:14 +01:00
|
|
|
:storeLabel
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Get the char of the Label
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; We require 4 bytes to store the pointer values
|
2016-09-06 00:18:20 +01:00
|
|
|
SL0I R0 2 ; Thus we multiply our label by 4
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Store the current Program counter
|
|
|
|
STOREX R12 R8 R0
|
|
|
|
|
|
|
|
;; Label is safely stored, return
|
|
|
|
RET R13
|
|
|
|
|
|
|
|
;; Main Functionality
|
2016-07-01 22:14:14 +01:00
|
|
|
:stage2
|
2016-06-27 01:18:19 +01:00
|
|
|
;; We first need to rewind tape_01 to perform our second pass
|
|
|
|
LOADUI R0 0x1100
|
|
|
|
REWIND
|
|
|
|
|
|
|
|
;; Reset our toggle and counter, just in case
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R11 1 ; Our toggle
|
|
|
|
FALSE R12 ; Our PC counter
|
2016-06-27 01:18:19 +01:00
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:loop
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Check for EOF
|
2016-10-29 12:03:25 +01:00
|
|
|
CMPSKIPI.GE R0 0
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @finish
|
|
|
|
|
|
|
|
;; Check for Label
|
2016-09-06 00:18:20 +01:00
|
|
|
CMPUI R14 R0 58 ; Make sure we jump over the label
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP.NE R14 @.L97
|
|
|
|
|
|
|
|
;; Consume next char
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @loop
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:.L97
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Check for Pointer
|
2016-09-06 00:18:20 +01:00
|
|
|
CMPUI R14 R0 64 ; If it is a pointer Deal with it
|
|
|
|
JUMP.NE R14 @.L98 ; Otherwise attempt to process it
|
2016-06-27 01:18:19 +01:00
|
|
|
CALLI R13 @storePointer
|
|
|
|
JUMP @loop
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:.L98
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Process Char
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0 ; Write to Char to TTY
|
|
|
|
FPUTC ; Print the Char
|
|
|
|
CALLI R13 @hex ; Convert it
|
|
|
|
CMPI R14 R0 0 ; Check if it is hex
|
|
|
|
JUMP.L R14 @loop ; Don't use nonhex chars
|
|
|
|
JUMP.Z R11 @.L99 ; Jump if toggled
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Process first byte of pair
|
2016-09-06 00:18:20 +01:00
|
|
|
AND R15 R0 R10 ; Store First nibble
|
|
|
|
FALSE R11 ; Flip the toggle
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @loop
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:.L99
|
2016-09-06 00:18:20 +01:00
|
|
|
SL0I R15 4 ; Shift our first nibble
|
|
|
|
AND R0 R0 R10 ; Mask out top
|
|
|
|
ADD R0 R0 R15 ; Combine nibbles
|
|
|
|
TRUE R11 ; Flip the toggle
|
|
|
|
LOADUI R1 0x1101 ; Write the combined byte
|
|
|
|
FPUTC ; To TAPE_02
|
|
|
|
ADDUI R12 R12 1 ; increment PC now that we have a full byte
|
|
|
|
JUMP @loop ; Try to get more bytes
|
2016-06-27 01:18:19 +01:00
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:storePointer
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Correct the PC to reflect the size of the pointer
|
2016-09-06 00:18:20 +01:00
|
|
|
ADDUI R12 R12 2 ; Exactly 2 bytes
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Get the char of the Label
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from tape_01
|
|
|
|
FGETC ; Read a Char
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Since we stored a full pointer taking up 4 bytes
|
2016-09-06 00:18:20 +01:00
|
|
|
SL0I R0 2 ; Thus we multiply our label by 4 to get where it is stored
|
|
|
|
LOADX R2 R8 R0 ; Load the address of the label
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; We now have to calculate the distance and store the 2 bytes
|
2016-09-06 00:18:20 +01:00
|
|
|
SUB R2 R2 R12 ; First determine the difference between the current PC and the stored PC of the label
|
|
|
|
ADDUI R2 R2 4 ; Adjust for relative positioning
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Store Upper byte
|
|
|
|
COPY R0 R2
|
2016-09-06 00:18:20 +01:00
|
|
|
SARI R0 8 ; Drop the bottom 8 bits
|
|
|
|
AND R0 R0 R9 ; Mask out everything but bottom bits
|
|
|
|
LOADUI R1 0x1101 ; Write the byte
|
|
|
|
FPUTC ; To TAPE_02
|
2016-06-27 01:18:19 +01:00
|
|
|
|
|
|
|
;; Store Lower byte
|
2016-09-06 00:18:20 +01:00
|
|
|
AND R0 R2 R9 ; Drop everything but the bottom 8 bits
|
|
|
|
FPUTC ; Write the byte to TAPE_02
|
2016-06-27 01:18:19 +01:00
|
|
|
RET R13
|
|
|
|
|
2016-09-06 00:18:20 +01:00
|
|
|
|
|
|
|
;; Hex function
|
|
|
|
;; Returns hex value of ascii char
|
|
|
|
;; Or -1 if not a hex char
|
2016-07-01 22:14:14 +01:00
|
|
|
:hex
|
2016-06-27 01:18:19 +01:00
|
|
|
;; Deal with line comments starting with #
|
|
|
|
CMPUI R14 R0 35
|
|
|
|
JUMP.E R14 @ascii_comment
|
|
|
|
;; Deal with line comments starting with ;
|
|
|
|
CMPUI R14 R0 59
|
|
|
|
JUMP.E R14 @ascii_comment
|
|
|
|
;; Deal with all ascii less than '0'
|
|
|
|
CMPUI R14 R0 48
|
|
|
|
JUMP.L R14 @ascii_other
|
|
|
|
;; Deal with '0'-'9'
|
|
|
|
CMPUI R14 R0 57
|
|
|
|
JUMP.LE R14 @ascii_num
|
|
|
|
;; Deal with all ascii less than 'A'
|
|
|
|
CMPUI R14 R0 65
|
|
|
|
JUMP.L R14 @ascii_other
|
|
|
|
;; Deal with 'A'-'F'
|
|
|
|
CMPUI R14 R0 70
|
|
|
|
JUMP.LE R14 @ascii_high
|
|
|
|
;; Deal with all ascii less than 'a'
|
|
|
|
CMPUI R14 R0 97
|
|
|
|
JUMP.L R14 @ascii_other
|
|
|
|
;; Deal with 'a'-'f'
|
|
|
|
CMPUI R14 R0 102
|
|
|
|
JUMP.LE R14 @ascii_low
|
|
|
|
;; Ignore the rest
|
|
|
|
JUMP @ascii_other
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:ascii_num
|
2016-06-27 01:18:19 +01:00
|
|
|
SUBUI R0 R0 48
|
|
|
|
RET R13
|
2016-07-01 22:14:14 +01:00
|
|
|
:ascii_low
|
2016-06-27 01:18:19 +01:00
|
|
|
SUBUI R0 R0 87
|
|
|
|
RET R13
|
2016-07-01 22:14:14 +01:00
|
|
|
:ascii_high
|
2016-06-27 01:18:19 +01:00
|
|
|
SUBUI R0 R0 55
|
|
|
|
RET R13
|
2016-07-01 22:14:14 +01:00
|
|
|
:ascii_other
|
2016-06-27 01:18:19 +01:00
|
|
|
TRUE R0
|
|
|
|
RET R13
|
2016-07-01 22:14:14 +01:00
|
|
|
:ascii_comment
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R1 0x1100 ; Read from TAPE_01
|
|
|
|
FGETC ; Read another char
|
|
|
|
CMPUI R14 R0 10 ; Stop at the end of line
|
|
|
|
LOADUI R1 0 ; Write to TTY
|
|
|
|
FPUTC ; The char we just read
|
|
|
|
JUMP.NE R14 @ascii_comment ; Otherwise keep looping
|
2016-06-27 01:18:19 +01:00
|
|
|
JUMP @ascii_other
|
|
|
|
|
2016-07-01 22:14:14 +01:00
|
|
|
:finish
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R0 0x1100 ; Close TAPE_01
|
2016-06-27 01:18:19 +01:00
|
|
|
FCLOSE
|
2016-09-06 00:18:20 +01:00
|
|
|
LOADUI R0 0x1101 ; Close TAPE_02
|
2016-06-27 01:18:19 +01:00
|
|
|
FCLOSE
|
|
|
|
HALT
|
|
|
|
|
2016-09-06 00:18:20 +01:00
|
|
|
|
|
|
|
;; Where all of our pointers will be stored for our locations
|
2016-07-01 22:14:14 +01:00
|
|
|
:table
|