Translated improvement into hex0 version of stage1_assembler-2
This commit is contained in:
parent
d75b146eb0
commit
cfe1684312
|
@ -1,5 +1,5 @@
|
|||
# :start
|
||||
2D2D03b4 # LOADUI R13 @table ; Where we are putting our table
|
||||
2D2D040c # LOADUI R13 @table ; Where we are putting our table
|
||||
# ;; We will be using R14 for our condition codes
|
||||
2D2F7fff # LOADUI R15 0x7FFF ; We will be using R15 for our stack
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
|||
# ;; Prep TAPE_02
|
||||
2D201101 # LOADUI R0 0x1101
|
||||
42100001 # FOPEN_WRITE
|
||||
2D0F0064 # CALLI R15 @second_pass
|
||||
2D0F006c # CALLI R15 @second_pass
|
||||
# ;; Close up as we are done
|
||||
2D201100 # LOADUI R0 0x1100 ; Close TAPE_01
|
||||
42100002 # FCLOSE
|
||||
|
@ -36,6 +36,7 @@
|
|||
42100002 # FCLOSE
|
||||
FFFFFFFF # HALT
|
||||
|
||||
|
||||
# ;; First pass function
|
||||
# ;; Reads Tape_01 and creates our label table
|
||||
# ;; Will Overwrite R0 R10 R11
|
||||
|
@ -46,28 +47,34 @@ FFFFFFFF # HALT
|
|||
# ;; Check for EOF
|
||||
A0100000 # CMPSKIP.GE R0 0
|
||||
0D01001F # RET R15
|
||||
# ;; Check for and deal with label
|
||||
# ;; Check for and deal with label (:)
|
||||
A030003a # CMPSKIP.NE R0 58
|
||||
3C00009c # JUMP @storeLabel
|
||||
3C0000ac # JUMP @storeLabel
|
||||
# ;; Check for and deal with pointers to labels
|
||||
# ;; Starting with (@)
|
||||
A0300040 # CMPSKIP.NE R0 64
|
||||
3C00024c # JUMP @ThrowAwayPointer
|
||||
3C000298 # JUMP @ThrowAwayPointer
|
||||
# ;; Then dealing with ($)
|
||||
A0300024 # CMPSKIP.NE R0 36
|
||||
3C000244 # JUMP @ThrowAwayPointer
|
||||
3C000290 # JUMP @ThrowAwayPointer
|
||||
# ;; Now check for absolute addresses (&)
|
||||
A0300026 # CMPSKIP.NE R0 38
|
||||
3C000294 # JUMP @ThrowAwayAddress
|
||||
# ;; Otherwise attempt to process
|
||||
2D0F0278 # CALLI R15 @hex ; Convert it
|
||||
2D0F02c8 # CALLI R15 @hex ; Convert it
|
||||
A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
|
||||
3C00ffd0 # JUMP @first_pass ; Move onto Next char
|
||||
3C00ffc8 # JUMP @first_pass ; Move onto Next char
|
||||
# ;; Determine if we got a full byte
|
||||
2C9A000c # JUMP.Z R10 @first_pass_0 ; Jump if toggled
|
||||
# ;; Deal with case of first half of byte
|
||||
0D00002A # FALSE R10 ; Flip the toggle
|
||||
3C00ffc4 # JUMP @first_pass
|
||||
3C00ffbc # JUMP @first_pass
|
||||
# :first_pass_0
|
||||
# ;; Deal with case of second half of byte
|
||||
0D00003A # TRUE R10 ; Flip the toggle
|
||||
0FBB0001 # ADDUI R11 R11 1 ; increment PC now that that we have a full byte
|
||||
3C00ffb8 # JUMP @first_pass
|
||||
3C00ffb0 # JUMP @first_pass
|
||||
|
||||
|
||||
# ;; Second pass function
|
||||
# ;; Reads from Tape_01 and uses the values in the table
|
||||
|
@ -82,22 +89,24 @@ A0100000 # CMPSKIP.GE R0 0
|
|||
0D01001F # RET R15
|
||||
# ;; Check for and deal with label
|
||||
A030003a # CMPSKIP.NE R0 58
|
||||
3C000214 # JUMP @ThrowAwayLabel
|
||||
3C000264 # JUMP @ThrowAwayLabel
|
||||
# ;; Check for and deal with Pointers to labels
|
||||
A0300040 # CMPSKIP.NE R0 64 ; @ for relative
|
||||
3C000070 # JUMP @StoreRelativePointer
|
||||
3C000078 # JUMP @StoreRelativePointer
|
||||
A0300024 # CMPSKIP.NE R0 36 ; $ for absolute
|
||||
3C000090 # JUMP @StoreAbsolutePointer
|
||||
3C000098 # JUMP @StoreAbsolutePointer
|
||||
A0300026 # CMPSKIP.NE R0 38 ; & for address
|
||||
3C0000b0 # JUMP @StoreAbsoluteAddress
|
||||
# ;; Process everything else
|
||||
2D0F022c # CALLI R15 @hex ; Attempt to Convert it
|
||||
2D0F0274 # CALLI R15 @hex ; Attempt to Convert it
|
||||
A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
|
||||
3C00ffd0 # JUMP @second_pass ; Move onto Next char
|
||||
3C00ffc8 # JUMP @second_pass ; Move onto Next char
|
||||
# ;; Determine if we got a full byte
|
||||
2C9A0010 # JUMP.Z R10 @second_pass_0 ; Jump if toggled
|
||||
# ;; Deal with case of first half of byte
|
||||
05020C08 # AND R12 R0 R8 ; Store our first nibble
|
||||
0D00002A # FALSE R10 ; Flip the toggle
|
||||
3C00ffc0 # JUMP @second_pass
|
||||
3C00ffb8 # JUMP @second_pass
|
||||
# :second_pass_0
|
||||
# ;; Deal with case of second half of byte
|
||||
2D5C0004 # SL0I R12 4 ; Shift our first nybble
|
||||
|
@ -107,7 +116,8 @@ A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
|
|||
2D211101 # LOADUI R1 0x1101 ; Write the combined byte
|
||||
42100200 # FPUTC ; To TAPE_02
|
||||
0FBB0001 # ADDUI R11 R11 1 ; increment PC now that that we have a full byte
|
||||
3C00ffa0 # JUMP @second_pass
|
||||
3C00ff98 # JUMP @second_pass
|
||||
|
||||
|
||||
# ;; Store Label function
|
||||
# ;; Writes out the token and the current PC value
|
||||
|
@ -122,16 +132,17 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
|
|||
23B00000 # STORE32 R11 R0 0
|
||||
# ;; Store the name of the Label
|
||||
0F000004 # ADDUI R0 R0 4 ; Increment the offset of the index
|
||||
2D0F005c # CALLI R15 @writeout_token
|
||||
2D0F0098 # CALLI R15 @writeout_token
|
||||
# ;; Update our index
|
||||
0F00003c # ADDUI R0 R0 60 ; Hopefully our tokens are less than 60 bytes long
|
||||
2F000008 # STORER R0 @current_index
|
||||
# ;; And be done
|
||||
3C00ff30 # JUMP @first_pass
|
||||
3C00ff20 # JUMP @first_pass
|
||||
# ;; Where we are storing the location of the next free table entry
|
||||
# :current_index
|
||||
00000000 # NOP
|
||||
|
||||
|
||||
# ;; StoreRelativepointer function
|
||||
# ;; Deals with the special case of relative pointers
|
||||
# ;; Clears Temp
|
||||
|
@ -143,15 +154,16 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
|
|||
# :StoreRelativePointer
|
||||
# ;; Correct the PC to reflect the size of the pointer
|
||||
0FBB0002 # ADDUI R11 R11 2 ; Exactly 2 bytes
|
||||
2D200374 # LOADUI R0 $Temp ; Set where we want to shove our string
|
||||
2D0F008c # CALLI R15 @Clear_string ; Clear it
|
||||
2D0F003c # CALLI R15 @writeout_token ; Write it
|
||||
2D0F00c4 # CALLI R15 @Match_string ; Find the Match
|
||||
2D2003cc # LOADUI R0 $Temp ; Set where we want to shove our string
|
||||
2D0F00c8 # CALLI R15 @Clear_string ; Clear it
|
||||
2D0F0078 # CALLI R15 @writeout_token ; Write it
|
||||
2D0F0100 # CALLI R15 @Match_string ; Find the Match
|
||||
1800fffc # LOAD32 R0 R0 -4 ; Get the value we care about
|
||||
0500200B # SUB R0 R0 R11 ; Determine the difference
|
||||
0F000004 # ADDUI R0 R0 4 ; Adjust for relative positioning
|
||||
2D0F0134 # CALLI R15 @ProcessImmediate ; Write out the value
|
||||
3C00ff50 # JUMP @second_pass
|
||||
2D0F0170 # CALLI R15 @ProcessImmediate ; Write out the value
|
||||
3C00ff48 # JUMP @second_pass
|
||||
|
||||
|
||||
# ;; StoreAbsolutepointer function
|
||||
# ;; Deals with the special case of absolute pointers
|
||||
|
@ -164,13 +176,41 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
|
|||
# :StoreAbsolutePointer
|
||||
# ;; Correct the PC to reflect the size of the pointer
|
||||
0FBB0002 # ADDUI R11 R11 2 ; Exactly 2 bytes
|
||||
2D200374 # LOADUI R0 $Temp ; Set where we want to shove our string
|
||||
2D0F0064 # CALLI R15 @Clear_string ; Clear it
|
||||
2D0F0014 # CALLI R15 @writeout_token ; Write it
|
||||
2D0F009c # CALLI R15 @Match_string ; Find the Match
|
||||
2D2003cc # LOADUI R0 $Temp ; Set where we want to shove our string
|
||||
2D0F00a0 # CALLI R15 @Clear_string ; Clear it
|
||||
2D0F0050 # CALLI R15 @writeout_token ; Write it
|
||||
2D0F00d8 # CALLI R15 @Match_string ; Find the Match
|
||||
1800fffc # LOAD32 R0 R0 -4 ; Get the value we care about
|
||||
2D0F0114 # CALLI R15 @ProcessImmediate ; Write out the value
|
||||
3C00ff30 # JUMP @second_pass
|
||||
2D0F0150 # CALLI R15 @ProcessImmediate ; Write out the value
|
||||
3C00ff28 # JUMP @second_pass
|
||||
|
||||
|
||||
# ;; StoreAbsoluteAddress function
|
||||
# ;; Deal with the special case of absolute Addresses
|
||||
# ;; Clear Temp
|
||||
# ;; Stores string in Temp
|
||||
# ;; Finds match in Table
|
||||
# ;; Writes out the full absolute address [32 bit machine]
|
||||
# ;; Modifies R0 R11
|
||||
# ;; Jumpbacs back into Pass2
|
||||
# :StoreAbsoluteAddress
|
||||
# ;; COrrect the PC to reflect the size of the address
|
||||
0FBB0004 # ADDUI R11 R11 4 ; 4 Bytes on 32bit machines
|
||||
2D2003cc # LOADUI R0 $Temp ; Set where we ant to shove our string
|
||||
2D0F0080 # CALLI R15 @Clear_string ; Clear it
|
||||
2D0F0030 # CALLI R15 @writeout_token ; Write it
|
||||
2D0F00b8 # CALLI R15 @Match_string ; Find the Match
|
||||
090200EF # PUSHR R14 R15 ; Get a temp storage place
|
||||
18E0fffc # LOAD32 R14 R0 -4 ; Get the value we care about
|
||||
0900040E # COPY R0 R14 ; We need to print the top 2 bytes first
|
||||
2D400010 # SARI R0 16 ; Drop bottom 16 bits
|
||||
2D0F0124 # CALLI R15 @ProcessImmediate ; Write out top 2 bytes
|
||||
2D20ffff # LOADUI R0 0xFFFF ; Provide mask to keep bottom 2 bytes
|
||||
0502000E # AND R0 R0 R14 ; Drop top 16 bits
|
||||
090280EF # POPR R14 R15 ; Restore R14
|
||||
2D0F0114 # CALLI R15 @ProcessImmediate ; Write out bottom 2 bytes
|
||||
3C00feec # JUMP @second_pass
|
||||
|
||||
|
||||
# ;; Writeout Token Function
|
||||
# ;; Writes the Token [minus first char] to the address
|
||||
|
@ -208,6 +248,7 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
|
|||
# ;; And be done
|
||||
0D01001F # RET R15
|
||||
|
||||
|
||||
# ;; Clear string function
|
||||
# ;; Clears string pointed at by the value of R0
|
||||
# ;; Until a null character is reached
|
||||
|
@ -236,6 +277,7 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
|
|||
0902800F # POPR R0 R15
|
||||
0D01001F # RET R15
|
||||
|
||||
|
||||
# ;; Match string function
|
||||
# ;; Walks down table until match is found
|
||||
# ;; Then returns address of matching string in R0
|
||||
|
@ -245,8 +287,8 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
|
|||
0902001F # PUSHR R1 R15
|
||||
0902002F # PUSHR R2 R15
|
||||
# ;; Initialize for Loop
|
||||
2D210374 # LOADUI R1 $Temp ; We always compare against Temp
|
||||
2D2203b4 # LOADUI R2 $table ; Begin at start of table
|
||||
2D2103cc # LOADUI R1 $Temp ; We always compare against Temp
|
||||
2D22040c # LOADUI R2 $table ; Begin at start of table
|
||||
0F220004 # ADDUI R2 R2 4 ; Where the string is located
|
||||
# ;; Loop until we find a match
|
||||
# :Match_string_0
|
||||
|
@ -254,7 +296,7 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
|
|||
2D0F0024 # CALLI R15 @strcmp
|
||||
2C500010 # JUMP.E R0 @Match_string_1 ; It is a match!
|
||||
# ;; Prepare for next loop
|
||||
2D210374 # LOADUI R1 $Temp ; That function clears R1
|
||||
2D2103cc # LOADUI R1 $Temp ; That function clears R1
|
||||
0F220040 # ADDUI R2 R2 64 ; Each Index is 64 bytes
|
||||
3C00ffec # JUMP @Match_string_0 ; Keep looping
|
||||
# :Match_string_1
|
||||
|
@ -265,6 +307,7 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
|
|||
0902801F # POPR R1 R15
|
||||
0D01001F # RET R15
|
||||
|
||||
|
||||
# ;; Our simple string compare function
|
||||
# ;; Recieves two pointers in R0 and R1
|
||||
# ;; Returns the difference between the strings in R0
|
||||
|
@ -294,6 +337,7 @@ A0200000 # CMPSKIP.E R0 0 ; Stop if byte is NULL
|
|||
0902802F # POPR R2 R15
|
||||
0D01001F # RET R15
|
||||
|
||||
|
||||
# ;; Processimmediate Function
|
||||
# ;; Recieves an integer value in R0
|
||||
# ;; Writes out the values to Tape_02
|
||||
|
@ -322,6 +366,7 @@ A0200000 # CMPSKIP.E R0 0 ; Stop if byte is NULL
|
|||
# ;; Be Done
|
||||
0D01001F # RET R15
|
||||
|
||||
|
||||
# ;; ThrowAwaypointer function
|
||||
# ;; Handle the special case of a generic problem
|
||||
# ;; for Pass1, Will update R11 and modify R0
|
||||
|
@ -329,8 +374,18 @@ A0200000 # CMPSKIP.E R0 0 ; Stop if byte is NULL
|
|||
# ;; Never call this function, only jump to it
|
||||
# :ThrowAwayPointer
|
||||
0FBB0002 # ADDUI R11 R11 2 ; Pointers always take up 2 bytes
|
||||
2D0F001c # CALLI R15 @throwAwayToken ; Get rid of rest of token
|
||||
3C00fd44 # JUMP @first_pass ; Then return to the proper place
|
||||
# ;; ThrowAwayAddress function
|
||||
# ;; Handle the case of a 32bit absolute address storage
|
||||
# ;; for Pass1, Will update R11 and modify R0
|
||||
# ;; Will return to the start of first_pass
|
||||
# ;; Never call this function, conly jump to it
|
||||
# :ThrowAwayAddress
|
||||
0FBB0004 # ADDUI R11 R11 4 ; Addresses on 32bit systems take up 4 bytes
|
||||
2D0F0010 # CALLI R15 @throwAwayToken ; Get rid of rest of token
|
||||
3C00fd90 # JUMP @first_pass ; Then return to the proper place
|
||||
3C00fd38 # JUMP @first_pass ; Then return to the proper place
|
||||
|
||||
|
||||
# ;; ThrowAwaylabel function
|
||||
# ;; Handle the special case of a generic problem
|
||||
|
@ -339,7 +394,8 @@ A0200000 # CMPSKIP.E R0 0 ; Stop if byte is NULL
|
|||
# ;; Never call this function, only jump to it
|
||||
# :ThrowAwayLabel
|
||||
2D0F0008 # CALLI R15 @throwAwayToken ; Get rid of rest of token
|
||||
3C00fdd4 # JUMP @second_pass
|
||||
3C00fd84 # JUMP @second_pass
|
||||
|
||||
|
||||
# ;; Throw away token function
|
||||
# ;; Deals with the general case of not wanting
|
||||
|
@ -361,6 +417,7 @@ A030000a # CMPSKIP.NE R0 10
|
|||
# ;; Otherwise keep looping
|
||||
3C00ffe0 # JUMP @throwAwayToken
|
||||
|
||||
|
||||
# ;; Hex function
|
||||
# ;; This function is serving three purposes:
|
||||
# ;; Identifying hex characters
|
||||
|
@ -414,6 +471,7 @@ A030000a # CMPSKIP.NE R0 10
|
|||
2C6Efff4 # JUMP.NE R14 @ascii_comment ; Otherwise keep looping
|
||||
3C00ffe8 # JUMP @ascii_other
|
||||
|
||||
|
||||
# ;; Where we are storing our Temp
|
||||
# :Temp
|
||||
00000000 # NOP
|
||||
|
@ -433,5 +491,6 @@ A030000a # CMPSKIP.NE R0 10
|
|||
00000000 # NOP
|
||||
00000000 # NOP
|
||||
|
||||
|
||||
# ;; Where we will putting our Table
|
||||
# :table
|
||||
|
|
Loading…
Reference in New Issue