Example #1
0
int main (int argc, char **argv)
{
    int res, i;
    int handle;
    char *hexfilename;
    unsigned short *hexbuffer;
    unsigned short nb_words;
    FILE *hexout;

    if (argc != 2)
    {
        printf ("usage: dcpu16asm <file>\n");
        exit (-1);
    }

    /* Parse input file */
    yyin = fopen (argv[1], "rw");
    if (yyin == NULL)
    {
        printf ("File not found.\n");
        exit (-1);
    }

    nb_lines_parsed = 0;
    memset (&parser_output, 0, sizeof (parser_output_t));
    res = yyparse ();

    fclose (yyin);

    /* dump_parser_output (); */

    if (res == 0)
    {
        /* Assemble output buffer */
        dcpu16_assemble (&parser_output /*in*/, &hexbuffer /*out*/, &nb_words /*out*/);

        i = strlen (argv[1]);
        hexfilename = strdup (argv[1]);
        strcpy (hexfilename + i - 3, "hex");
        hexout = fopen (hexfilename, "wb");
        fwrite (hexbuffer, sizeof (unsigned short), nb_words, hexout);
        fclose (hexout);

        printf ("%d lines successfully assembled in %d words!\n", nb_lines_parsed, nb_words);
    }

    exit (res);
}
Example #2
0
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	return dcpu16_assemble (op->buf, buf);
}
Example #3
0
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	int len = dcpu16_assemble ((ut8*)r_strbuf_get (&op->buf), buf);
	op->buf.len = len;
	return len;
}