You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ AS4
7
7
8
8
AS4 is the low level assembler on written in C99 for the Nibble Knowledge CPU. It is under 700 lines of executable code, and recognises only 12 contructs:
9
9
10
-
## Useage ###
10
+
###Useage ###
11
11
There are only two invocations of as4:
12
12
* ./as4 -b BASE_ADDRESS INPUT OUTPUT
13
13
* ./as4 INPUT OUTPUT
@@ -38,8 +38,13 @@ AS4 recognises two inbuilt data types:
38
38
Labels are of the format "NAME:". They are used to refer to memory locations without having to memorise or calculate number.
39
39
An example of useage would be "number: .data 1 2", which is using the label "number" to point to a data element of 1 nibble in size with the initial value of 2.
40
40
41
+
Labels when referenced in instructions can be used in two forms:
42
+
* INST LABEL - where the instruction INST simply references the memory location pointed to by LABEL
43
+
* INST LABEL[OFFSET] - where the instruction INST references the memory location pointed to by LABEL + OFFSET. OFFSET must be a hexidecimal value, optionally preceded by "0x".
44
+
An example of usage would be "LOD sum[F]", which loads the memory address pointed to by "sum" plus the offset of "F" (15 in decimal) into the accumulator.
45
+
41
46
### Comments ###
42
-
Comments in AS4 start with a semicolon, ";".
47
+
Comments in AS4 start with a semicolon, ";" or an octothorp, "#".
/* If it is, then take stock of both the address it was referenced */
700
700
unsigned short intinstaddress= (*unknownlabels)[i].addr;
701
-
/* And the address the label points to. */
702
-
unsigned short intlabeladdr= (*labels)[(*numlabels) -1].addr;
701
+
/* And the address the label points to plus the requested offset. */
702
+
unsigned short intlabeladdr= (*labels)[(*numlabels) -1].addr+ (*unknownlabels)[i].offset;
703
703
704
704
/* The address it was referenced at is actually the opcode of the instruction, so go up one nibble to point to the address section. */
705
705
instaddress++;
@@ -751,7 +751,9 @@ unsigned short int findlabel(label **unknownlabels, label **labels, const char *
751
751
unsigned short intaddress=UNKNOWNADDR;
752
752
/* tempaddress is what is assigned to the return value of strtol. We use this value if we find that the token after the assembly instruction is actually a number. */
753
753
unsigned short inttempaddress=address;
754
-
754
+
/* offset stores the offset in nibbles from the specific label. */
755
+
unsigned short intoffset=0;
756
+
755
757
/* Set errno to 0 so we can check for errors from strtol, which will tell us if the token after the assembly instruction is a number or a label (if it's neither we find out a bit later, not in this function). */
756
758
errno=0;
757
759
/* tempaddress is 0 if the labelstr is actually a label and not a value. */
@@ -773,12 +775,28 @@ unsigned short int findlabel(label **unknownlabels, label **labels, const char *
773
775
/* Remove any possible whitespace */
774
776
for(i=0; i<strlen(tempstr); i++)
775
777
{
776
-
if(isspace(tempstr[i]))
778
+
if(isspace(tempstr[i])!=0)
777
779
{
778
780
tempstr[i] ='\0';
779
781
break;
780
782
}
781
783
}
784
+
/* Search for the square brackets to determine label offset */
/* Check the offset is in the correct form. If the last character isn't ] for both where we stopped reading the string to find the offest value and where the string ends, then it's wrong. */
791
+
/* If both are ], but they're not pointing to the same place (ie: LABEL[HEX_OFFSET]uh oh]) then it's still wrong. */
0 commit comments