void stringz_ins(){ spToken = nextToken(); accept(TC_STRING_LIT, "String literal expected."); char* lit = spToken.source; int i; for (i = 0; i < spToken.intValue; i++){ char ch = lit[i]; strcpy(outputBuffer, unsignedBinary(ch, 16)); outputBinary(); } strcpy(outputBuffer, FILL_ZERO); outputBinary(); spAddress += spToken.intValue - 2; finishInstruction(); }
void fill_ins(){ spToken = nextToken(); accept(TC_INT, "Integer literal expected."); strcpy(outputBuffer, signedBinary(spToken.intValue, 16)); outputBinary(); finishInstruction(); }
void jsr_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); processLabel(11); outputBinary(); finishInstruction(); }
void add_or_and_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); if (spToken.type == TC_REG){ strcat(outputBuffer, "000"); strcat(outputBuffer, spToken.binary); } else if (spToken.type == TC_INT){ strcat(outputBuffer, "1"); if (spToken.intValue < -16 || spToken.intValue > 15) putError("Integer literal too large or too small."); else strcat(outputBuffer, signedBinary(spToken.intValue, 5)); } else putError("Register or immediate operand expected."); outputBinary(); finishInstruction(); }
void jmp_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); strcat(outputBuffer, SIX_ZEROS); outputBinary(); finishInstruction(); }
void trap_ins(){ strcpy(outputBuffer, spToken.binary); if (spToken.type == TC_TRAP){ spToken = nextToken(); accept(TC_INT, "Trap vector expected."); strcat(outputBuffer, unsignedBinary(spToken.intValue, 12)); } outputBinary(); finishInstruction(); }
void blkw_ins(){ strcpy(outputBuffer, FILL_ZERO); spToken = nextToken(); accept(TC_INT, "Integer literal expected."); int i; for (i = 1; i <= spToken.intValue; i++) outputBinary(); spAddress += spToken.intValue - 1; finishInstruction(); }
void orig_ins(){ if (spToken.type = TC_ORIG){ spToken = nextToken(); // First pass guarantees an int here spAddress = spToken.intValue - 1; spToken = nextToken(); finishInstruction(); } strcpy(outputBuffer, unsignedBinary(spAddress, 16)); outputBinary(); }
void ld_ldi_lea_st_sti_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); processLabel(9); outputBinary(); finishInstruction(); }
void not_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); outputBinary(); finishInstruction(); }
void ldr_or_str_ins(){ strcpy(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); accept(TC_REG, "Register expected."); strcat(outputBuffer, spToken.binary); spToken = nextToken(); accept(TC_COMMA, "Comma expected."); spToken = nextToken(); accept(TC_INT, "Integer literal expected."); if (spToken.intValue < -32 || spToken.intValue > 31) putError("Integer literal too large or too small."); else strcat(outputBuffer, signedBinary(spToken.intValue, 6)); outputBinary(); finishInstruction(); }
int main(void) { char naturalInput[256]; int naturalLength; while(1) { printf("Input a natural number in decimal representation.\n"); printf(">"); fgets(naturalInput, 256, stdin); removeNewline(naturalInput); //Remove newline character from array. naturalLength = strlen(naturalInput); if(isValidNumber(naturalInput, naturalLength) == 1) //Check if array contains non-digits. outputBinary(naturalInput); else printf("\nPlease input a natural number in decimal representation.\n"); } return 0; }
void ret_or_rti_ins(){ strcpy(outputBuffer, spToken.binary); outputBinary(); finishInstruction(); }