void matrix_mul::thread(void) { long* operand1; long* operand2; long* result; while(1) { operand1 = readOperand(); operand2 = readOperand(); result = operand1; //result = multiply(operand1, operand2); sendResult(result); } }
////////////////////////////////////////////////////////////////////////////// /// /// Multiplication's algorithm /// ////////////////////////////////////////////////////////////////////////////// void multiplier::thread(void) { long operand1; long operand2; long result; while(1) { operand1 = readOperand(); operand2 = readOperand(); result = multiply(operand1, operand2); sendResult(result); } }
////////////////////////////////////////////////////////////////////////////// /// /// Addition's algorithm /// ////////////////////////////////////////////////////////////////////////////// void adder::thread(void) { long operand1; long operand2; long result; while(1) { operand1 = readOperand(); operand2 = readOperand(); result = add(operand1, operand2); sendResult(result); } }
void matrix_mul::thread(void) { unsigned int result[MATRIX_ROWS * MATRIX_COLUMNS]; unsigned int operand1[MATRIX_ROWS * MATRIX_COLUMNS]; unsigned int operand2[MATRIX_ROWS * MATRIX_COLUMNS]; while(1) { // Add your code here... readOperand(operand1); readOperand(operand2); multMatrix(operand1, operand2, result); sendResult(result); // SpacePrint( "matrix_mul executing...\n" ); } }
void matrix_mul::thread(void) { while (1) { readOperand(); multiplyMat(); sendResult(); } }
//all input instructions are assumed to be valid. //i.e. sytactically correct and no illegal operations //(e.g. division by zero) //variables may not start with digits //variables are assumed to be integers int main(){ char curr_var[MAX_VAR_IDENT_LENGTH]; char curr_operator; char curr_operand[MAX_VAR_IDENT_LENGTH]; /*Input from file for testing purposes FILE *fin; if( (fin = fopen("in.txt","r")) == NULL){ printf("file not found\n"); exit(1); } fscanf(fin,"%s",inst); */ /*input from keyboard*/ scanf("%s",inst); /**/ instIndex = 0; int instLen = strlen(inst)-1; while(instIndex<instLen){ readVariable(curr_var); readOperator(&curr_operator); readOperand(curr_operand); compute(curr_var, curr_operator, curr_operand); } printVars(); return 0; }
int readInstruction(char *code, unsigned int *ip, struct Instruction *instr) { enum OpCode opcode = (enum OpCode)code[*ip]; *ip += sizeof(enum OpCode); instr->offset = *ip; switch (opcode) { case PUSH: instr->hasOperand = TRUE; instr->opcode = PUSH; instr->stackBehaviour = Push1; readOperand(code, ip, instr); break; case ADD: instr->hasOperand = FALSE; instr->opcode = ADD; instr->stackBehaviour = Push1; break; case SUB: instr->hasOperand = FALSE; instr->opcode = SUB; instr->stackBehaviour = Push1; break; case MUL: instr->hasOperand = FALSE; instr->opcode = MUL; instr->stackBehaviour = Push1; break; case DIV: instr->hasOperand = FALSE; instr->opcode = DIV; instr->stackBehaviour = Push1; break; case RET: instr->hasOperand = FALSE; instr->opcode = RET; instr->stackBehaviour = None; break; case LCALL: instr->hasOperand = TRUE; instr->opcode = LCALL; instr->stackBehaviour = Push1; readOperand(code, ip, instr); break; case IJMP: instr->hasOperand = TRUE; instr->opcode = IJMP; instr->stackBehaviour = None; readOperand(code, ip, instr); break; case RARG: instr->hasOperand = TRUE; instr->opcode = RARG; instr->stackBehaviour = Push1; readOperand(code, ip, instr); break; case MKARR: instr->hasOperand = TRUE; instr->opcode = MKARR; instr->stackBehaviour = Push1; readOperand(code, ip, instr); break; case SETELEM: instr->hasOperand = TRUE; instr->opcode = SETELEM; instr->stackBehaviour = Pop2; readOperand(code, ip, instr); break; case GETELEM: instr->hasOperand = TRUE; instr->opcode = GETELEM; instr->stackBehaviour = Pop1; break; case SETVAR: instr->hasOperand = TRUE; instr->opcode = SETVAR; instr->stackBehaviour = Pop1; readOperand(code, ip, instr); break; case GETVAR: instr->hasOperand = TRUE; instr->opcode = GETVAR; instr->stackBehaviour = Push1; readOperand(code, ip, instr); break; case JLE: instr->hasOperand = TRUE; instr->opcode = JLE; instr->stackBehaviour = None; readOperand(code, ip, instr); break; default: return 0; } return 1; }
void EArm::exec_bl(unsigned int loc,unsigned int opcode) { writeReg(14,pc); jump(readOperand(&op1)); }
void EArm::exec_ldr(unsigned int loc,unsigned int opcode) { ULONG val=readOperand(&op2); writeOperand(&op1,val); }