2 After studying this chapter you should be able to - describe the structure of typical assembly language instructions using the terms op-code and operanddescribe and give examples of assembly language instructions of the following typesdata transferarithmeticlogicalshift and rotatebranch
3 B Revision Question 1 Machine code is a common programming language which can be used on any machinethe low level language specific to a particular microprocessorthe number which identifies a particular type of computerany high level language which can be compiled for use by a microprocessorB
4 Revision Question 2The processor register which holds the address of the next instruction to be fetched is thememory address register (MAR)instruction register (IR)program counter (PC)memory data register (MDR)C
5 Revision Question 3The correct sequence of steps in the fetch-executecycle isfetch instruction ➜ increment PC ➜ decode instruction ➜ execute instructionincrement PC ➜ fetch instruction ➜ decode instruction ➜ execute instructionfetch instruction ➜ decode instruction ➜ increment PC ➜ execute instructionfetch instruction ➜ decode instruction ➜ execute instruction ➜ increment PCA
6 D Revision Question 4 Data fetched from memory arrives in the memory address register (MAR)the instruction register (IR)the program counter (PC)the memory data register (MDR)D
7 B Revision Question 5 In an 8-bit microprocessor, the data and address buses must both be 8 bits widethe data bus is 8 bits wide, but the address bus may be more than 8 bits widethe address bus must be 8 bits wide, but the data bus can be any widtha single 8 bit wide system bus is used to transfer all data and addressesB
8 Machine Code Processors only understand instructions in machine code These are difficult to read and understande.g
9 Machine Code Assembly Language 10101001 00000001 10001101 00000011 LDA #1STA 1000LDA 1000ADC #1STA 1001JSR OSWRCHRTSMnemonic – a short code – replaces the machine code instruction
10 Assembly Language Instructions Op-codeOperandWhat the instruction is to doData to be operated upon
11 Assembly Language Instructions Op-codeOperandMeaningLDA#1Load the accumulator with the value 1STA1DFFStore the contents of the acc in memory location 1DFFLDA3C15Load the acc. with the contents of memory location 3C15
12 Assembly Language Instructions Op-codeOperandLDA#1
26 6502 Microprocessor System introduced in about 1975among the first microprocessors to be used in early home computers.included the usual Arithmetic/Logic Unit with some internal registers and a Control Unit all on the same chip.It had an external crystal-controlled clock to generate timing signals
27 6502 Microprocessor System ROM was used to hold a bootstrap program to permit initial operation of the systemRAM was used to hold programs and dataThe 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.
28 6502 Microprocessor System The external bus was a combination of an 8-bit-wide data bus, a 16-bit-wide address bus and some control lines that carried synchronisation signals throughout the system.
29 6502 Microprocessor System Hence only 8 bits of data could be moved around the system, but 16-bit addresses could be used to address memory.Memory locations with addresses in the range 0 to (216-1) could be directly addressedMemory was made up of individually addressable 8-bit words (bytes).
30 6502 Microprocessor System - registers 8 bits – used for storing data16 bits – used for storing 16 bit addresses
31 6502 Registers 8 bit registers A X Y SR IR MDR 16-bit registers MAR PC SP
32 6502 registers - AA is known as the Accumulator – the main general purpose register in which data is held during most arithmetical and logical operations
33 6502 registers – X,YX and Y are index registers. They are designed to hold loop counters or as gp registers
34 6502 registers - SRSR 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
35 6502 registers - SRN- the negative flag – set o 1 if the result of the last operation is zeroV – the overflow flag – set to 1 if the last result operation is invalidB – the break bit – set to 1 when a break instruction is executedD – the decimal flag – when set to 1, the processor will operate using binary coded decimal arithmeticI – the interrupt disable flag – when set the processor will ignore any interrupt signalsZ – the zero flag – set to 1 when the last result was zeroC – the carry flag – set to 1 if the result of an operation is a number that cannot be stored in a single 8-bit register
36 6502 registers - IR IR is the instruction register. It holds the instruction being decoded or executed
37 6502 registers - MDR MDR is the Memory Data register. It holds data which has just arrived along the data bus or is just about to be sent along the data bus
38 6502 registers - MAR MAR is the Memory Address register. It holds an address about to be sent out along the address bus
39 6502 registers - PC PC is the Program Counter. It holds the address of the next instruction to be fetched, decoded and executed
40 6502 registers - SP SP is the Stack Pointer. Temporary data storage. The SP holds the address of the next free location in the stack
41 Exercise Copy and complete the table Page 55 Q.7 Complete questions 8-11
42 LDA #55Load the accumulator with the value 55See scholar animation
43 Addressing Modes Refers to the operand There are many types e.g. ImmediateDirectImpliedOthers such as relative, indirect, indexed
44 Immediate Addressing The operand is the actual data to be used Example – LDA #55Other examplesCMP #27 – compare the contents of A with the number 27LDX #A4 – load the X register with the value A4LDY #00 – load the Y register with the number 008-bit Op-code8-bit operand
45 Direct Addressing The operand is the address to be used Example – LDA 3C15Other examplesJMP 2015 – jump to instruction in location 2015ADC 2099 – add the data in location 2099 to the accumulator8-bit Op-code16-bit operand (address)
46 Implied Addressing No operand is required Example – TAX – transfer the contents of A to XOther examplesTYA – transfer the contents of the Y-register to the accumulator8-bit Op-code
47 Other addressing modes As well as immediate, absolute and implied addressing, the 6502 processor has many other addressing modes. These include:relative addressing - for example BEQ 09, which means "if the zero flag was set by the last operation, branch to the instruction 9 locations forward in memory"indexed addressing - for example LDA 3C15,Y which means "load the accumulator with the data to be found at the location 3C15+Y, where Y is the value stored in the Y registerindirect addressing - for example LDA (3C15), which means "load the accumulator with the data you find at the address which is to be fond at location 3C15"
48 Instruction types Data transfer instructions Arithmetic instructions Logical instructionsShift and rotate instructionsBranch instructionsVarious othersNow have a look at the animations in Scholar
49 Program 1 – adding two numbers CLC clear the carry flag, just in caseLDA 2004 fetch the number from location 2004ADC 2005 add on the number from location 2005STA 2006 store the result in location 2006
50 Program 2 – Multiplying by 3 CLC clear the carry flag, just in caseLDA 2004 fetch the number from location 2004ADC 2004 add the number to itselfADC 2004 add the number on againSTA 2005 store the result in location 2005
51 Program 3 – Multiplying two numbers LDA fetch the number from location 2004LDX load the X register with the number from location 2005DEX reduce X by 1 (see note 1 below)CLC clear the carry flag just in caseADC add the number from location 2004 to the current value in the accumulatorDEX reduce the X register by 1BNE -6 if X is not zero, branch back 6 locations see note 2 below)STA store the result in location 2006
Your consent to our cookies if you continue to use this website.