Operation |
Machine-Language
Instruction |
Example |
Add RA to RB
and store result in RC (RC = RA + RB) |
1010000100
RC RA RB |
1010000100
00 01 10 R0 = R1 + R2 |
Subtract RB
from RA and store result in RC (RC = RA - RB) |
1010001000
RC RA RB |
1010001000
00 01 10 R0 = R1 - R2 |
Load
contents of memory location MMMMM into register RB (RB = MMMMM) |
100000010 RB
MMMMM |
100000010 11
00101 R3 = M[5] |
Store
contents of register RB into memory location MMMMM (MMMMM = RB) |
100000100 RB
MMMMM |
100000100 11
00101 M[5] = R3 |
Move
contents of register RB into register RA (RA = RB) |
100100010000
RA RB |
100100010000
01 00 R1 = R0 |
Halt the
machine |
1111111111111111 |
Memory Address
Machine Instruction Action
0: 1000000100000101 // R0 = M[5]; load memory location 5 into R0
1: 1000000100100110 // R1 = M[6]; load memory location 6 into R1
2: 1010000100100001 // R2 = R0 + R1; add R0 and R1, store result in R2
3:
1000001001000111 // M[7] = R2; copy R2 to memory location 7
4:
1111111111111111 // HALT
5:
0000000000001001 // 9; data to be added
6:
0000000000000001 // 1; data to be added
7:
0000000000000000 // location where sum is to be stored
initialize PC = 0;
fetch instruction stored at memory location PC;
set PC = PC + 1;
while (instuction is not HALT) {
decode the instruction;
configure the CPU hardware to match the settings indicated in the instruction;
execute the CPU datapath cycle using those settings;
when the cycle is complete, fetch next instruction from memory location PC;
set PC = PC + 1;
}