Topic 3 Processor Function
Topic 3 Processor Function
Topic 3
After studying this chapter you should be able to describe the structure of typical assembly language instructions using the terms op-code and operand describe and give examples of assembly language instructions of the following types
data transfer arithmetic logical shift and rotate branch
Revision Question 1
Machine code is A. a common programming language which can be used on any machine B. the low level language specific to a particular microprocessor C. the number which identifies a particular type of computer D. any high level language which can be compiled for use by a microprocessor
Revision Question 2
The processor register which holds the address of the next instruction to be fetched is the A. memory address register (MAR) B. instruction register (IR) C. program counter (PC) D. memory data register (MDR)
Revision Question 3
The correct sequence of steps in the fetch-execute cycle is A. fetch instruction increment PC decode instruction execute instruction B. increment PC fetch instruction decode instruction execute instruction C. fetch instruction decode instruction increment PC execute instruction D. fetch instruction decode instruction execute instruction increment PC
Revision Question 4
Data fetched from memory arrives in A. the memory address register (MAR) B. the instruction register (IR) C. the program counter (PC) D. the memory data register (MDR)
Revision Question 5
In an 8-bit microprocessor, A. the data and address buses must both be 8 bits wide B. the data bus is 8 bits wide, but the address bus may be more than 8 bits wide C. the address bus must be 8 bits wide, but the data bus can be any width D. a single 8 bit wide system bus is used to transfer all data and addresses
Machine Code
Processors only understand instructions in machine code These are difficult to read and understand e.g 10101001 00000001 10000101 01110000 10100101 01110000
Machine Code
10101001 00000001 10001101 00000011 11101000 10001101 00000011 11101000 01101001 00000001 10001101 00000011 11101001 00100000 11101110 11111111 01100000
Assembly Language
LDA #1 STA 1000 LDA 1000 ADC #1 STA 1001 JSR OSWRCH
Mnemonic a short code replaces the machine code instruction
RTS
Operand
Data to be operated upon
Machine Code
10101001 00000001 10001101 00000011 11101000 10001101 00000011 11101000 01101001 00000001 10001101 00000011 11101001 00100000 11101110 11111111 01100000
Assembly Language
LDA #1 STA 1000 LDA 1000 ADC #1 STA 1001 JSR OSWRCH
RTS
Instruction Formats
Not all instructions are the same length e.g. 6502 processor
8-bit Op-code 8-bit Op-code 8-bit Op-code 8-bit operand 16-bit operand
Instruction Formats
IBM mainframe instruction set
8-bit Op-code 8-bit Op-code 8-bit Op-code
4-bit operand 4-bit operand
4-bit operand
4-bit operand
12-bit operand
Instruction Formats
X86 mainframe instruction set
Op-code
What the instruction is to do
Operand
Data or address of data to be operated upon
Instruction types
Data transfer instructions Arithmetic instructions Logical instructions Shift and rotate instructions Branch
Data transfer
Used to move data from one place to another
Between registers From memory to processor/register From processor to memory
Arithmetic
Used to carry out simple arithmetic e.g. +-/x
Add contents of 2 registers Adding 1 to contents of register
Logical
Used to make logical comparisons Checking whether contents of two registers are equal to each other
Branch
Branch instructions break the normal sequential flow of execution by changing the program counter if a specified condition is met.
6502 processor
Simple processor used in BBC, Apple II and Atari
ROM was used to hold a bootstrap program to permit initial operation of the system RAM was used to hold programs and data The interface with the external devices was via a Programmable Input/Output unit (PIO), which communicated with the external devices using 16-bit wide I/O buses.
6502 Registers
8 bit registers A X Y SR IR MDR 16-bit registers MAR PC SP
6502 registers - A
A is known as the Accumulator the main general purpose register in which data is held during most arithmetical and logical operations
6502 registers - SR
SR is the status register. It is really a set of 8 1-bit registers. Each bit operates independently, and is used to flag to record the status of the processor after each instruction
6502 registers - SR
N- the negative flag set o 1 if the result of the last operation is zero V the overflow flag set to 1 if the last result operation is invalid
6502 registers - IR
IR is the instruction register. It holds the instruction being decoded or executed
6502 registers - PC
PC is the Program Counter. It holds the address of the next instruction to be fetched, decoded and executed
6502 registers - SP
SP is the Stack Pointer. Temporary data storage. The SP holds the address of the next free location in the stack
Exercise
Copy and complete the table Page 55 Q.7 Complete questions 8-11
LDA #55
Load the accumulator with the value 55 See scholar animation
Addressing Modes
Refers to the operand There are many types e.g.
Immediate Direct Implied Others such as relative, indirect, indexed
Immediate Addressing
Other examples
CMP #27 compare the contents of A with the number 27 LDX #A4 load the X register with the value A4 LDY #00 load the Y register with the number 00
Direct Addressing
Other examples
JMP 2015 jump to instruction in location 2015 ADC 2099 add the data in location 2099 to the accumulator
Implied Addressing
Other examples
TYA transfer the contents of the Yregister to the accumulator
Instruction types
Data transfer instructions Arithmetic instructions Logical instructions Shift and rotate instructions Branch instructions Various others
Program 2 Multiplying by 3
CLC LDA 2004 ADC 2004 ADC 2004 STA 2005
clear the carry flag, just in case fetch the number from location 2004 add the number to itself
Exercise
Scholar Page 91
Past Papers
Q 12 19
2008 Q14 a-b 2006 Q17 b+c 2010 Q15 2011 Q11