tern-assembler/asm_rules.c

43 lines
814 B
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void asm_rules(char *in, char _asm[9]){
char src_addr[9];
char dest_addr[9];
char tryte[9];
for (int i = 0; i < 9; i++) {
_asm[i] = 0;
}
char *instruction = (char*) malloc(10*sizeof(char));
int instruction_location = 0;
char *word = strtok(in, " ");
while(word != NULL) {
if (word[strlen(word)-1] == '\n') {
word[strlen(word)-1] = '\0'; //cleans newline from string
}
if (strcmp(word, "nop") == 0) {
//keeps the default value (0)
} else {
if (strcmp(word, "max") == 0) {
_asm[6] = 1;
//printf("%c\n", tryte[6]);
}
}
for (int i = 0; i < 9; i++) {
instruction[instruction_location] = _asm[i];
instruction_location++;
}
instruction[instruction_location] = ' ';
word = strtok(NULL, " ");
}
}