Initial commit of files related to NED architecture.
[ned1] / nedasm / nedasm_parser_extensions.c
/*
* © 2018 Aaron Taylor <ataylor at subgeniuskitty dot com>
* See LICENSE.txt file for copyright and license details.
*/
#include <stdlib.h>
#include <string.h>
#include "nedasm_structures.h"
#include "nedasm_misc.h"
struct instruction *
parse_pseudo_mnemonic(char * mnemonic, size_t mnemonic_index, char * data, size_t data_index,
char * label, size_t label_index, struct instruction * new_instruction)
{
uint32_t linenum = new_instruction->linenum;
if (strncmp(mnemonic, "JSR", MAX_MNEMONIC_LEN) == 0) {
if (label_index) {
new_instruction->syllable = WORD;
new_instruction->target = malloc(label_index+1);
strncpy(new_instruction->target, label, label_index+1);
new_instruction->next = create_instruction_struct();
new_instruction->next->prev = new_instruction;
new_instruction = new_instruction->next;
}
/* JSR must expand to exactly one word (five syllables). */
/* Otherwise, trailing syllables in the same word are skipped when RTS returns. */
// TODO: This should be on a word boundary, regardless of whether a WORD preceded it.
for (int i=0; i<5; i++) {
switch (i) {
case 0:
new_instruction->syllable = IM;
new_instruction->data = 0x08; /* Address of PC register */
break;
case 1:
new_instruction->syllable = LOAD;
break;
case 2:
new_instruction->syllable = SWAP;
break;
case 3:
new_instruction->syllable = JMP;
break;
case 4:
new_instruction->syllable = NOP;
break;
default:
break;
}
new_instruction->linenum = linenum;
if (i<4) {
new_instruction->next = create_instruction_struct();
new_instruction->next->prev = new_instruction;
new_instruction = new_instruction->next;
}
}
} else if (strncmp(mnemonic, "RTS", MAX_MNEMONIC_LEN) == 0) {
new_instruction->syllable = JMP;
}
return new_instruction;
}