pc = 0; do { instruction = memory[pc++]; decode(instruction); fetchoperands(); execute(); storeresults(); } while (instruction != halt);
Different (von Neumann) architectures differ mainly in how they implement
fetchoperands(),
execute(), and
storeresults();
void fetchoperands(int howmany) { if (howmany > 0) op1 = *(sp--); if (howmany > 1) op2 = *(sp--); }
void storeresults() { *(++sp) = result; }
void literal(int value) { *(++sp) = value; }
void fetchoperands(int howmany) { if (howmany > 0) op1 = accumulator; if (howmany > 1) op2 = *(*(pc++)); }
void storeresults() { accumulator = result; }
void load(int address) { accumulator = *address; }
void store(int address) { *address = accumulator; }
void fetchoperands(int howmany, int* selector) { if (howmany > 0) op1 = r[selector[0]]; if (howmany > 1) op2 = r[selector[1]]; }
void storeresults(int where) { r[where] = result; }
void load(int address, int register) { r[register] = *address; }
void store(int address, int register) { *address = r[register]; }
pc = 0; do { instruction = memory[pc++]; if (ismemop(instruction)) { addr = memaddr(instruction); reg = regnum(instruction); if (isload(instruction)) memory[addr] = r[reg]; else r[reg] = memory[addr]; } else { r1 = reg1num(instruction); r2 = reg2num(instruction); r3 = reg3num(instruction); r[r3] = execute(op(instruction), r[r1], r[r2]); } while (instruction != halt);
subscribe ICS312-L your-email-address