/** @todo implement this function */ void asm_pass_two (char* obj_file_name) { //do? FILE* fw = open_write_or_error(obj_file_name); for(currInfo = infoHead; currInfo->opcode != 17; currInfo = currInfo->next){ //asm_print_line_info(currInfo); LC3_inst_t* inst = lc3_get_inst_info(currInfo -> opcode); printf("WHY IS ADD WRONG %p\n", inst); operands_t operands = inst->forms[currInfo->form].operands; printf("form is: %d\n", currInfo->form); currInfo->machineCode = inst->forms[currInfo->form].prototype; for (operand_t op = FMT_R1; op <= FMT_STR; op <<= 1) { if(op & operands){ printf("op is %d\n", op ); if(currInfo->opcode == OP_BR){ currInfo->machineCode = setField(currInfo->machineCode,11,9,currInfo->reg1); encode_PC_offset_or_error(9); } encode_operand(op); // printf("making it?\n"); } } asm_print_line_info(currInfo); if(currInfo->opcode == OP_BLKW){ for(int i = 0; i < currInfo->immediate;i++){ lc3_write_LC3_word(fw,0000); } }else{ lc3_write_LC3_word(fw,currInfo->machineCode); } } }
int main (int argc, char* argv[]) { if (argc != 2) { printf("Usage: seeLC3 opcode\n"); printf("e.g. seeLC3 ADD\n"); } else { opcode_t opcode = util_get_opcode(argv[1]); LC3_inst_t* info = lc3_get_inst_info(opcode); if (! info) { printf("%s is no an opcode\n", argv[1]); } else { printf("form bit:%2d\n", info->formBit); for (int i = 0; i < 2; i++) { if (info->forms[i].name != NULL) { printf("form: %d name: %s operands: %s operandsnum: %d prototype x%04x\n", i, info->forms[i].name, lc3_get_format_name(info->forms[i].operands), info->forms[i].operands, //operand numeric representatio info->forms[i].prototype); } } } } }
//done void check_line_syntax (char* token) { printf("check_line_syntax('%s')\n", token); //check if its a label token = check_for_label(token); printf(" my token is %s \n ", token); //store the op in an int if(token == NULL) return; int myop = util_get_opcode(token); printf("opcode is: %d\n", myop ); //store it itno my data structure.. currInfo -> opcode = myop; if(myop == OP_BR){ currInfo->reg1 = util_parse_cond(token+2); token = next_token(); currInfo->reference = strdup(token); //get_operand(op,token); } LC3_inst_t* inst = lc3_get_inst_info(myop); printf("inst is: %p \n" , inst); int position = 0; if(strcasecmp(inst ->forms[0].name,token) != 0){ position = 1; } /*if(inst ->forms[1].name != NULL &&strcasecmp(inst ->forms[1].name,token) == 0){ position = 1; if(strcasecmp(inst ->forms[0].name,token) != 0) position = 1; }*/ if(myop != OP_BR){ currInfo->form=position;} printf("%d\n whats my position", position); operands_t format = inst -> forms[position].operands; scan_operands(format); }