Skip to content

Commit 886d562

Browse files
U-UC\harvey1U-UC\harvey1
authored andcommitted
Made direct numbers after an instruction unaffected by base address.
1 parent 09edb4c commit 886d562

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/as4.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
176176
/* If it's just a number after the instruction, that will be returned with the base address added to it. */
177177
/* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */
178178
/* If it's an already declared label return the address relative to the base address. */
179-
address = findlabel(&unknownlabels, &labels, tokens, baseaddr, numlabels, &numunknownlabels, bits);
179+
address = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits);
180180
/* Add this to the output buffer. */
181181
addinst(outbuf, LOD, address, &bits, &bytes);
182182
}
@@ -195,7 +195,7 @@ int main(int argc, char **argv)
195195
/* If it's just a number after the instruction, that will be returned with the base address added to it. */
196196
/* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */
197197
/* If it's an already declared label return the address relative to the base address. */
198-
address = findlabel(&unknownlabels, &labels, tokens, baseaddr, numlabels, &numunknownlabels, bits);
198+
address = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits);
199199
/* Add this to the output buffer. */
200200
addinst(outbuf, STR, address, &bits, &bytes);
201201
}
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
214214
/* If it's just a number after the instruction, that will be returned with the base address added to it. */
215215
/* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */
216216
/* If it's an already declared label return the address relative to the base address. */
217-
address = findlabel(&unknownlabels, &labels, tokens, baseaddr, numlabels, &numunknownlabels, bits);
217+
address = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits);
218218
/* Add this to the output buffer. */
219219
addinst(outbuf, ADD, address, &bits, &bytes);
220220
}
@@ -241,7 +241,7 @@ int main(int argc, char **argv)
241241
/* If it's just a number after the instruction, that will be returned with the base address added to it. */
242242
/* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */
243243
/* If it's an already declared label return the address relative to the base address. */
244-
address = findlabel(&unknownlabels, &labels, tokens, baseaddr, numlabels, &numunknownlabels, bits);
244+
address = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits);
245245
/* Add this to the output buffer. */
246246
addinst(outbuf, NND, address, &bits, &bytes);
247247
}
@@ -260,7 +260,7 @@ int main(int argc, char **argv)
260260
/* If it's just a number after the instruction, that will be returned with the base address added to it. */
261261
/* If it's a yet undeclared label, 65535 (UNKNOWNADDR) is returned. The instruction will be modified when the label is declared. */
262262
/* If it's an already declared label return the address relative to the base address. */
263-
address = findlabel(&unknownlabels, &labels, tokens, baseaddr, numlabels, &numunknownlabels, bits);
263+
address = findlabel(&unknownlabels, &labels, tokens, numlabels, &numunknownlabels, bits);
264264
/* Add this to the output buffer. */
265265
addinst(outbuf, JMP, address, &bits, &bytes);
266266
}
@@ -736,9 +736,9 @@ void addlabel(char *outbuf, label **labels, label **unknownlabels, unsigned long
736736
}
737737
}
738738

739-
/* findlabel() determines the memory address that follows the opcode. If the memory address is already a number, it adds the base address to this and returns the result */
739+
/* findlabel() determines the memory address that follows the opcode. If the memory address is already a number, and returns it */
740740
/* If it is an undeclared label, it adds the label name and the instruction location to the "unknown labels" collection. If the label is declared, it returns it's address */
741-
unsigned short int findlabel(label **unknownlabels, label **labels, const char *labelstr, unsigned short int baseaddr, unsigned long long numlabels, unsigned long long *numunknownlabels, unsigned long long bits)
741+
unsigned short int findlabel(label **unknownlabels, label **labels, const char *labelstr, unsigned long long numlabels, unsigned long long *numunknownlabels, unsigned long long bits)
742742
{
743743
/* endptr is used to check if the strtol finds a valid number. */
744744
/* If not, it's likely a label. */
@@ -844,8 +844,8 @@ unsigned short int findlabel(label **unknownlabels, label **labels, const char *
844844
/* If there is no error from strtol, the token after the assembly instruction is probably a numerical value. */
845845
else
846846
{
847-
/* So add the base address to it, and return it as is. */
848-
address = (tempaddress + baseaddr);
847+
/* Assume the programmer knows what he's doing and directly assign it. */
848+
address = tempaddress;
849849
}
850850
/* Return the final address found. */
851851
return address;

src/as4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ void adddata(char **outbuf, size_t bufsize, unsigned long long size, long long v
5252
/* addlabel() adds a label to the collection of labels, to be used by other functions when a label reference is made. */
5353
/* Additionally, if there are outstanding "queries" for a certain label (if the label has been used before it has been declared) it replaces the "unknown address" address in an instruction with the address of the label on declaration */
5454
void addlabel(char *outbuf, label **labels, label **unknownlabels, unsigned long long *numlabels, unsigned long long numunknownlabels, const char *labelstr, unsigned long long bits, unsigned short int baseaddr);
55-
/* findlabel() determines the memory address that follows the opcode. If the memory address is already a number, it adds the base address to this and returns the result */
55+
/* findlabel() determines the memory address that follows the opcode. If the memory address is already a number, returns it */
5656
/* If it is an undeclared label, it adds the label name and the instruction location to the "unknown labels" collection. If the label is declared, it returns it's address */
57-
unsigned short int findlabel(label **unknownlabels, label **labels, const char *labelstr, unsigned short int baseaddr, unsigned long long numlabels, unsigned long long *numunknownlabels, unsigned long long bits);
57+
unsigned short int findlabel(label **unknownlabels, label **labels, const char *labelstr, unsigned long long numlabels, unsigned long long *numunknownlabels, unsigned long long bits);
5858
/* addstring() handles adding .ascii and .ascii (zero terminating ascii string) to the output buffer, including handling escape characters. */
5959
void addstring(char *outbuf, char *string, char zeroterm, unsigned long long *bits, unsigned long long *bytes);
6060

0 commit comments

Comments
 (0)