Translated improvement into hex1 version of stage1_assembler-2

This commit is contained in:
Jeremiah Orians 2016-09-03 19:18:00 -04:00
parent cdea34fa4f
commit d75b146eb0
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
1 changed files with 69 additions and 6 deletions

View File

@ -4,6 +4,7 @@
# ;; We will be using R14 for our condition codes
2D2F7fff # LOADUI R15 0x7FFF ; We will be using R15 for our stack
# ;; Main program functionality
# ;; Reads in Tape_01 and writes out results onto Tape_02
# ;; Accepts no arguments and HALTS when done
@ -38,6 +39,7 @@
42100002 # FCLOSE
FFFFFFFF # HALT
# ;; First pass function
# ;; Reads Tape_01 and creates our label table
# ;; Will Overwrite R0 R10 R11
@ -49,14 +51,19 @@ 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
3C00 @5 # JUMP @storeLabel
# ;; Check for and deal with pointers to labels
# ;; Starting with (@)
A0300040 # CMPSKIP.NE R0 64
3C00 @6 # JUMP @ThrowAwayPointer
# ;; Then dealing with ($)
A0300024 # CMPSKIP.NE R0 36
3C00 @6 # JUMP @ThrowAwayPointer
# ;; Now check for absolute addresses (&)
A0300026 # CMPSKIP.NE R0 38
3C00 @v # JUMP @ThrowAwayAddress
# ;; Otherwise attempt to process
2D0F @7 # CALLI R15 @hex ; Convert it
A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
@ -73,6 +80,7 @@ A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
0FBB0001 # ADDUI R11 R11 1 ; increment PC now that that we have a full byte
3C00 @2 # JUMP @first_pass
# ;; Second pass function
# ;; Reads from Tape_01 and uses the values in the table
# ;; To write desired contents onto Tape_02
@ -93,6 +101,8 @@ A0300040 # CMPSKIP.NE R0 64 ; @ for relative
3C00 @a # JUMP @StoreRelativePointer
A0300024 # CMPSKIP.NE R0 36 ; $ for absolute
3C00 @b # JUMP @StoreAbsolutePointer
A0300026 # CMPSKIP.NE R0 38 ; & for address
3C00 @w # JUMP @StoreAbsoluteAddress
# ;; Process everything else
2D0F @7 # CALLI R15 @hex ; Attempt to Convert it
A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
@ -115,6 +125,7 @@ A0100000 # CMPSKIP.GE R0 0 ; Don't record, nonhex values
0FBB0001 # ADDUI R11 R11 1 ; increment PC now that that we have a full byte
3C00 @4 # JUMP @second_pass
# ;; Store Label function
# ;; Writes out the token and the current PC value
# ;; Its static variable for storing the next index to be used
@ -140,6 +151,7 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
:d
00000000 # NOP
# ;; StoreRelativepointer function
# ;; Deals with the special case of relative pointers
# ;; Clears Temp
@ -152,7 +164,7 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
:a
# ;; 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
2D2003cc # LOADUI R0 $Temp ; Set where we want to shove our string
2D0F @f # CALLI R15 @Clear_string ; Clear it
2D0F @e # CALLI R15 @writeout_token ; Write it
2D0F @g # CALLI R15 @Match_string ; Find the Match
@ -162,6 +174,7 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
2D0F @h # CALLI R15 @ProcessImmediate ; Write out the value
3C00 @4 # JUMP @second_pass
# ;; StoreAbsolutepointer function
# ;; Deals with the special case of absolute pointers
# ;; Clears Temp
@ -174,7 +187,7 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
:b
# ;; 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
2D2003cc # LOADUI R0 $Temp ; Set where we want to shove our string
2D0F @f # CALLI R15 @Clear_string ; Clear it
2D0F @e # CALLI R15 @writeout_token ; Write it
2D0F @g # CALLI R15 @Match_string ; Find the Match
@ -182,6 +195,35 @@ A0300000 # CMPSKIP.NE R0 0 ; If zero intialize from R13
2D0F @h # CALLI R15 @ProcessImmediate ; Write out the value
3C00 @4 # 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
:w
0FBB0004 # ADDUI R11 R11 4 ; 4 Bytes on 32bit machines
2D2003cc # LOADUI R0 $Temp ; Set where we ant to shove our string
2D0F @f # CALLI R15 @Clear_string ; Clear it
2D0F @e # CALLI R15 @writeout_token ; Write it
2D0F @g # 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
2D0F @h # 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
2D0F @h # CALLI R15 @ProcessImmediate ; Write out bottom 2 bytes
3C00 @4 # JUMP @second_pass
# ;; Writeout Token Function
# ;; Writes the Token [minus first char] to the address
# ;; It recieves in R0 until it reaches a delimiter
@ -221,6 +263,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
@ -251,6 +294,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
@ -261,8 +305,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
@ -271,7 +315,7 @@ A030000a # CMPSKIP.NE R0 10 ; Finished if newline
2D0F @l # CALLI R15 @strcmp
2C50 @m # 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
3C00 @n # JUMP @Match_string_0 ; Keep looping
# :Match_string_1
@ -283,6 +327,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
@ -314,6 +359,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
@ -343,6 +389,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
@ -354,6 +401,19 @@ A0200000 # CMPSKIP.E R0 0 ; Stop if byte is NULL
2D0F @p # CALLI R15 @throwAwayToken ; Get rid of rest of token
3C00 @2 # 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
:v
0FBB0004 # ADDUI R11 R11 4 ; Addresses on 32bit systems take up 4 bytes
2D0F @p # CALLI R15 @throwAwayToken ; Get rid of rest of token
3C00 @2 # JUMP @first_pass ; Then return to the proper place
# ;; ThrowAwaylabel function
# ;; Handle the special case of a generic problem
# ;; for Pass2, Will update R11 and modify R0
@ -385,6 +445,7 @@ A030000a # CMPSKIP.NE R0 10
# ;; Otherwise keep looping
3C00 @p # JUMP @throwAwayToken
# ;; Hex function
# ;; This function is serving three purposes:
# ;; Identifying hex characters
@ -444,6 +505,7 @@ A030000a # CMPSKIP.NE R0 10
2C6E @q # JUMP.NE R14 @ascii_comment ; Otherwise keep looping
3C00 @r # JUMP @ascii_other
# ;; Where we are storing our Temp
# :Temp
:z
@ -464,6 +526,7 @@ A030000a # CMPSKIP.NE R0 10
00000000 # NOP
00000000 # NOP
# ;; Where we will putting our Table
# :table
:1