Пример #1
0
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();
}
Пример #2
0
void fill_ins(){
    spToken = nextToken();
    accept(TC_INT, "Integer literal expected.");
    strcpy(outputBuffer, signedBinary(spToken.intValue, 16));
    outputBinary();
    finishInstruction();
}
Пример #3
0
void jsr_ins(){
    strcpy(outputBuffer, spToken.binary);
    spToken = nextToken();
    processLabel(11);
    outputBinary();
    finishInstruction();
}
Пример #4
0
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();
}
Пример #5
0
void jmp_ins(){
    strcpy(outputBuffer, spToken.binary);
    spToken = nextToken();
    accept(TC_REG, "Register expected.");
    strcat(outputBuffer, spToken.binary);
    strcat(outputBuffer, SIX_ZEROS);
    outputBinary();
    finishInstruction();
}
Пример #6
0
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();
}
Пример #7
0
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();
}
Пример #8
0
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();
}
Пример #9
0
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();
}
Пример #10
0
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();
}
Пример #11
0
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();
}
Пример #12
0
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;
}
Пример #13
0
void ret_or_rti_ins(){
    strcpy(outputBuffer, spToken.binary);
    outputBinary();
    finishInstruction();
}