Informal specification of the Tiny machine See Section 8.7 of Louden for details. TM consists of a read-only instruction memory, a data memory, and a set of eight general-purpose registers. These all use nonnegative integer addresses beginning at 0. Register 7 (PC_REG) is the program counter and is the only special register. We write reg[r] for the contents of register r, iMem[i] for the contents of instruction address i, and dMem[d] for the contents of data address d. At start-up, all registers and data memory are set to 0, and the value of the highest legal data address is loaded into data address 0. The TM then starts to execute instructions from instruction address 0. The machine halts when a HALT instrictution is executed or an error occurs. The fetch-execute cycle has the conventional form: do /* fetch */ currentInstruction = iMem[reg[PC_REG]++] ; /* execute currentInstruction */ ... while (!(halt || error)) ; There are two forms of instructions: register-only (RO) instructions and register-memory (RM) instructions. The format of an RO instruction is: opcode r, s, t HALT Halt execution IN reg[r] <- integer value read from standard input OUT reg[r] -> standard output ADD reg[r] <- reg[s] + reg[t] SUB reg[r] <- reg[s] - reg[t] MUL reg[r] <- reg[s] * reg[t] DIV reg[r] <- reg[s] / reg[t] The format of an RM instruction is: opcode r,d(s) The effective address a = dMem[d] + reg[s]. LD reg[r] = dMem[a] LDA reg[r] = a LDC reg[r] = d ST dMem[a] = reg[r] JLT if (reg[r] < 0) reg[PC_REG] = a JLE if (reg[r] <= 0) reg[PC_REG] = a JGE if (reg[r] >= 0) reg[PC_REG] = a JGT if (reg[r] > 0) reg[PC_REG] = a JEQ if (reg[r] == 0) reg[PC_REG] = a JNE if (reg[r] != 0) reg[PC_REG] = a An unconditional jump instruction has the following form: LDA 7,d(s) reg[7] = d + reg[s] A conditional jump instruction can be made relative to the current position by using the program counter as the second register: JEQ 0,4(7) if (reg[0] == 0) reg[PC_REG] += 4 There is no procedure call or JSUB instruction, but we can write LD 7,d(s) to jump to the procedure whose entry address is dMem[d+reg[s]]. To save the return address, it necessary to first execute something like LDA 0,1(7) which places the address after the current instruction into reg[0] (assuming the next instruction is the procedure call/jump instruction).