A summary of TOY - Tasmanian Blogs

Download Report

Transcript A summary of TOY - Tasmanian Blogs

A summary of TOY
4 Main Components
Data Processor
Control Processor
Memory
Input/Output Device
Data Processor
The data processor contains:
– Sixteen 16-bit registers
– ALU: Arithmetic Logic Unit containing circuits
for performing arithmetic and logical functions
– TEMP: a temporary register used by the ALU
in computations
Control Processor
The control processor is the hardware
needed to perform the instruction
execution cycle and to execute operations
Control Processor
The control processor contains:
– PC: Program Counter, containing the address
of the next instruction
– MAR: Memory Address Register, holds the
address of the memory location to be accessed
– MBR: Memory Buffer Register, holds the value
extracted from, or to be placed into a location
specified by the MAR
– IR: Instruction Register, holds the current
instruction
Memory
Memory
Memory is used to store Instructions and
Data
– Data is stored sequentially from location 00
onwards
– Instructions are stored sequentially from
location 10 onwards
Has 16 bit memory with each memory
location labelled with an address between
00 and FF
Input/Output Devices
I/O Devices are used in Read and Write
operations
– Read user input
– Write output to the screen
Fetch-Execution Cycle
Fetch instruction from memory then execute the
instruction: 4 step cycle
1: Transfer contents of PC to MAR to prepare from reading
the next instruction
[pc] -> [mar]
2: Contents of MAR used as an address in memory. The
contents of the memory location (an instruction) are
transferred to the MBR
mem[[mar]] -> [mbr]
3: Instruction transferred to IR for execution
[mbr] -> [ir]
4: PC incremented by 1 and instruction code in IR is executed
[pc]+1 -> [pc]
TOY instruction representation
Each instruction consists of 4 hex digits.
The left-most digit encodes one of the 16
opcodes
The second left-most digit refers to one of
the 16 registers, which we refer to as the
destination register (d)
The two right-most digits depend on the
opcode being used, as each opcode has a
unique format
TOY instruction representation
Format 1:
Opcode
Destination Source (s) Source (t)
Example: Instruction 1462
1: opcode 1: Add
4: store result in register 4
6: use value stored in register 6
2: use value stored in register 2
Add value of register 6 to register 2 and put the
result in register 4
TOY instruction representation
Format 2:
Opcode
Destination
Address
Example: Instruction 9462
9: opcode 9: Store
4: use contents of register 4
62: store in memory location 62
Store value of register 4 in memory location 62
TOY instruction representation
Special Instructions
– Halt: 0000
The first (left-most) 0 is interpreted as ‘quit the
program’, the program quits, and the other 3
digits are not read
– Jump: E500
The first E is interpreted as JUMP (got to a set
instruction), 5 is interpreted as the instruction
to go to, the program jumps to this instruction,
and the other 2 bits are not read
Operations: Arithmetic
Opcode 1: Add
– Example: 1CAB
– Add contents of registers A and B, and store
the result in register C
Opcode 2: Subtract
– Example: 2CAB
Subtract contents of register B from contents
of register A, and store the result in register C
Example Programs - Page 5
Operations: Logical
Opcode 3: AND
– Determines if the integer is Odd (returns 1) or
even (returns 0)
– Example: 3BA1
– AND the contents of register A and 1, and
store the result in register B
Example Programs - Page 6
Operations: Logical
Opcode 4: XOR
– Changes the sign of an integer, positive
becomes negative and negative becomes
positive
– Example: 4BAF
– XOR the contents of registers A and F, and
store the result in register B
Example Programs - Page 6
Operations: Shift
Opcode 5: Left Shift
– Shift bits to the left, add padding (0’s) to the
right.
– Left shift by 1 is equivalent to multiplying by 2
– Left shift by n is equivalent to multiplying by 2n
– Example: 5AA2
– Contents of register A left shifted by contents
of register 2, results stored back into register
A
Example Programs - Page 7
Operations: Shift
Opcode 6: Right Shift
– Shift bits to the right, add padding (0’s or 1’s
depending on the sign bit) to the left.
– Right shift by 1 is equivalent to dividing by 2 (and
throw away the remainder)
– Right shift by n is equivalent to dividing by 2n (and
throw away the remainder)
– Example: 6AA2
– Contents of register A right shifted by contents of
register 2, results stored back into register A
Example Programs - Page 7
Operations: Shift
Right Shift
Operations: Move
Opcode 7: Load Address
– Load a memory address to a register. This opcode
only permits 8bit integers (rather than the 16bit
capacity)
Opcode 8: Load
– Load data from memory to registers
Opcode 9: Store
– Store data from registers to memory
Opcode A& B: Load Indirect & Store Indirect
– Allows manipulation of memory addresses
– Can deal with arrays
Example Programs - Page 8
Operations: Control
Opcode C: Branch Zero
– If a given register has a value of 0, reset the PC to a
given address
(Use branches like IF statements)
Opcode D: Branch Positive
– If a given register has a positive integer value, reset
the PC to a given address
Opcode E: Jump
– Reset the PC to the contents of a given register
Opcode F: Jump & Link
– PC is examined and its value stored in a given
register. PC then reset to desired address
Example Programs - Page 9
Operations: Idioms
Register-to-Register Transfer
– Copies a value from one register to another register.
– Example: 1201
Copies the value of register 1 to register 2, by adding the value
of register 1 to register 0 (which relies on register 0 always being
0)
GoTo
– Directly changes the PC
– Example: C0F0
– Changes PC to F0 since register 0 is always 0
NoOp
– No operation performed, space filler.
– Example: 1000