diff --git a/src/instruction.c b/src/instruction.c index a52c6d2..3b08f89 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -111,6 +111,7 @@ instruction_print(instruction_t *i) bool assemble_single_implied(uint8_t **buf, uint8_t *bsize, const char *mnemonic) { + /* XXX: does brk needs special handling? */ return assemble_single(buf, bsize, mnemonic, IMPLIED, 0, 0); } @@ -140,16 +141,21 @@ assemble_single(uint8_t **buf, uint8_t *bsize, const char *mnemonic, addressing_ return false; } + *bsize = id.size; *buf = malloc(id.size); if(*buf == NULL) { fprintf(stderr, "Error allocating assembly buffer\n"); return false; } + /* fill the buffer */ memset(*buf, 0, id.size); - *bsize = id.size; - *buf[0] = opcode; + /* XXX */ + if (id.size > 1) + *buf[1] = op1; + if (id.size > 2) + *buf[2] = op2; return found; } diff --git a/test/test_assemble.c b/test/test_assemble.c index 0c24915..3a995bb 100644 --- a/test/test_assemble.c +++ b/test/test_assemble.c @@ -31,6 +31,13 @@ ATF_TC_BODY(asm_single, tc) free(asmbuf); caddr += bsize; + ATF_REQUIRE(assemble_single(&asmbuf, &bsize, "lda", IMMEDIATE, 0xAA, 0)); + ATF_CHECK(asmbuf[0] == 0xA9); /* check if lda really */ + ATF_CHECK(asmbuf[1] == 0xAA); /* check the operand */ + ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); + free(asmbuf); + caddr += bsize; + ATF_REQUIRE(assemble_single_implied(&asmbuf, &bsize, "stp")); ATF_CHECK(asmbuf[0] == 0xDB); /* check if stp really */ ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize));