Skip to content

Commit 2dd7351

Browse files
committed
Address of should be complete
1 parent e8dc805 commit 2dd7351

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The Nibble Knowledge CPU has 8 instructions which are split into two different t
2828
* STR: Store the nibble in the accumulator to the specified memory address.
2929

3030

31+
3132
### Pseudo instructions ###
3233
To aid in disassembly a new metadata format for binary files is now included in the assembler as of v1.1.0.
3334
* INF - the information section must start with this, and this should be the first instruction of any file.
@@ -81,6 +82,13 @@ Labels when referenced in instructions can be used in two forms:
8182

8283
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.
8384

85+
### Address of operations ###
86+
As all programs built by AS4 are assumed to be static, non-relocatable binary files, the addresses pointed by labels can be calculated at assemble time and used statically. The form is below:
87+
* &(LABEL[OFFSET])[ADDRESS_OFFSET]
88+
* LABEL[OFFSET] is the same as for the standard label usage. &() indicates this is an address of operation, and [ADDRESS_OFFSET] is what 4-bit portion of the 16-bit address you want. Both [OFFSET] and [ADDRESS_OFFSET] are optional, without them an offset of zero is assumed.
89+
90+
This loads a corresponding value from the table of static values - for example, if the address of the label "Carmen" is 0x00FE, and you use the address of operation LOD &(Carmen)[1], you would load "0xF" into the accumulator; which is the same as using the instruction LOD N_[F] when the N_ static number series is defined.
91+
8492
### Comments ###
8593
Comments in AS4 start with a semicolon, ";" or an octothorp, "#".
8694

in

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/label.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ void addlabel(char *outbuf, label **labels, label **unknownlabels, unsigned long
111111
if(!strcmp((*unknownlabels)[i].str, tempstr))
112112
{
113113

114-
printf("%s: %s\n", tempstr, (*unknownlabels)[i].str);
115114
/* If it is, then take stock of both the address it was referenced. If a label is referencing a label, we need to move 1 nibble back (as there is no instruction, just 4 nibbles). Cheaper than doing an if below. */
116115
unsigned short int instaddress = (*unknownlabels)[i].addr - ((*unknownlabels)[i].type & 1);
117116
/* And the address the label points to plus the requested offset. We need to add one nibble if it is an instruction referencing a nibble as we moved one back above. */
@@ -123,13 +122,14 @@ void addlabel(char *outbuf, label **labels, label **unknownlabels, unsigned long
123122
if(N_START == 0xFFFF)
124123
{
125124
char *nstr = calloc(1, 6);
126-
sprintf(nstr, "N_[%X]", ((labeladdr >> (3 - (*unknownlabels)[i].addroffset) & 0xF)));
127-
labeladdr = findlabel(unknownlabels, labels, nstr, (*numlabels), numunknownlabels, bits, ((*unknownlabels)[i].type) & 1);
125+
/* As this is getting a portion of the address of the label accessed, we get the label's address and bitwise and that section then shift it back. */
126+
sprintf(nstr, "N_[%X]", (labeladdr & (0xF << ((*unknownlabels)[i].addroffset * 4))) >> ((*unknownlabels)[i].addroffset * 4));
127+
labeladdr = findlabel(unknownlabels, labels, nstr, (*numlabels), numunknownlabels, instaddress * 4, ((*unknownlabels)[i].type) & 1);
128128
continue;
129129
}
130130
else
131131
{
132-
labeladdr = ((labeladdr >> (3 - (*unknownlabels)[i].addroffset) & 0xF)) + N_START;
132+
labeladdr = (labeladdr & (0xF << ((*unknownlabels)[i].addroffset * 4))) >> ((*unknownlabels)[i].addroffset * 4) + N_START;
133133
}
134134
}
135135
/* The address it was referenced at is actually the opcode of the instruction, so go up one nibble to point to the address section. */
@@ -349,6 +349,7 @@ unsigned short int findlabel(label **unknownlabels, label **labels, char *labels
349349
(*unknownlabels)[0].addr = (bits/4);
350350
/* and the offset, so we can add it later. */
351351
(*unknownlabels)[0].offset = offset;
352+
(*unknownlabels)[0].addroffset = addroffset;
352353
/* and whether a label or instruction is referencing this */
353354
(*unknownlabels)[0].type = type;
354355
/* We have one unknown label now, so record that. */
@@ -376,6 +377,7 @@ unsigned short int findlabel(label **unknownlabels, label **labels, char *labels
376377
(*unknownlabels)[(*numunknownlabels) - 1].addr = (bits/4);
377378
/* And the offset */
378379
(*unknownlabels)[(*numunknownlabels) - 1].offset = offset;
380+
(*unknownlabels)[(*numunknownlabels) - 1].addroffset = addroffset;
379381
/* and the type */
380382
(*unknownlabels)[(*numunknownlabels) - 1].type = type;
381383
}

0 commit comments

Comments
 (0)