* © 2018 Aaron Taylor <ataylor at subgeniuskitty dot com>
* See LICENSE.txt file for copyright and license details.
#include "nedasm_structures.h"
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) {
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
++) {
new_instruction
->syllable
= IM
;
new_instruction
->data
= 0x08; /* Address of PC register */
new_instruction
->syllable
= LOAD
;
new_instruction
->syllable
= SWAP
;
new_instruction
->syllable
= JMP
;
new_instruction
->syllable
= NOP
;
new_instruction
->linenum
= linenum
;
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
;