M11 8085 Programming
M11 8085 Programming
Based on TM concept Employs a single data bus to fetch both the instruction and the data Has a CPU with a control unit, an Arithmetic and Logic Unit (ALU) and registers to temporarily store data for the two to use Memory and I/O are addressed by a separate address bus
Had a long life as a microcontroller (with added peripherals) Its actual name is 8085A, and it is NMOS device containing ~6,500 transistors and 40 pins
8085 Architecture
Another View
HL H B, C, D, E, H, and L PC SP They are used as needed. Can be used as 16-bit register pairs: BC, DE, HL
8 0
7 7 S
6 6 Z
5 5
4 4 C E L
3 3
2 2 P
1 1
0 0
0 AC 0
1 CY F
PC SP
Operand Types
There are different ways for specifying the operand:
There may not be an operand (implied operand)
CMA
The operand may be an internal register (register) The operand may be a 16-bit address (memory address)
Instruction Size
Depending on the operand type, the instruction may have different sizes. It will occupy a different number of memory bytes:
Instructions with implied operand occupy one byte Instruction that contains immediate data or a memory address occupy 2 or 3 bytes:
Instructions that include immediate data use two bytes:
One for the opcode and the other for the 8-bit data.
3E 32
C3 85 20
Addressing Modes
The microprocessor has different ways of specifying the data for the instruction. These are called addressing modes: The 8085 has four addressing modes:
Implied Immediate Direct Indirect CMA MVI B, 45 LDA 4000 LDAX B
Load the accumulator with the contents of the memory location whose address is stored in the register pair BC).
Source: 7305862-Introduction-to-8085-Instructions.ppt by Dr. Bassel Soudan
A simple program
Objective: Add 3216 and 4816
Step English 1 Load 3216 into accumulator 2 Load 4816 into register B 3 Add B to A 4 Halt Mnemonic (Assembly) MVI A,32H MVI B,48H ADD B HLT Memory Address C000 C001 C002 C003 C004 C005 Hex 3E 32 06 48 80 76 Binary (Machine) 0011 1110 0011 0010 0000 0110 0100 1000 1000 0000 0111 0110
Notice that:
Possible instructions are defined by the programming model There is a 1-to-1 relation between an instruction in English, its mnemonic, Hex and binary. In the lab, you will get a handout for this
Tutorials:
http://en.wikipedia.org/wiki/Intel_8085 http://www.computer-solutions.co.uk/info/Embedded_tutorials/8085_tutorial.htm http://webphysics.davidson.edu/faculty/dmb/py310/8085.pdf
Instruction sets:
http://ce.sharif.ir/courses/86-87/1/ce126/resources/root/instructionset8085.pdf http://www.8085projects.info/page/8085-Instruction-set-list.aspx http://webphysics.davidson.edu/faculty/dmb/py310/emac_primer/8085.instructionset.full.pdf
Pin description
http://www.8085projects.info/pin_diagram.asp http://www.8085projects.info/Pindiagram-and-pin-description-of-8085.html http://www.8085projects.info/Pin-description-of-8085.html
Program counter (also called the instruction pointer) indicates the memory address of the instruction to be executed Stack pointer points to top of the (subroutine) call stack
8085 is an 8-bit P
All calculations manipulate 8-bits of data Operations and data with more bits is broken down into 8-bits
Memory has 64k addressable locations These locations are divided into:
User addressable (stored in a RAM) EEPROM I/O ports (connected to devices)
Arithmetic Operations
Addition (ADD, ADI):
Any 8-bit number. The contents of a register. The contents of a memory location.
Can be added to the contents of the accumulator and the result is stored in the accumulator.
Can be subtracted from the contents of the accumulator. The result is stored in the accumulator
Arithmetic Operations
Increment (INR) and Decrement (DCR):
The 8-bit contents of any memory location or any register can be directly incremented or decremented by 1 No need to disturb the contents of the accumulator
Logic Operations
These instructions perform logic operations on the contents of the accumulator
ANA, ANI, ORA, ORI, XRA and XRI
Source: Accumulator and
An 8-bit number The contents of a register The contents of a memory location
Destination: Accumulator
ANA ANI ORA ORI XRA XRI R/M # R/M # R/M # AND Accumulator With Reg/Mem AND Accumulator With an 8-bit number OR Accumulator With Reg/Mem OR Accumulator With an 8-bit number XOR Accumulator With Reg/Mem XOR Accumulator With an 8-bit number
Complement:
1s complement of the contents of the accumulator
CMA No operand
Source: 7305862-Introduction-to-8085-Instructions.ppt by Dr. Bassel Soudan
Branch Operations
Two types:
Unconditional branch
Go to a new location no matter what
Conditional branch
Go to a new location if the condition is true
Unconditional Branch
JMP CALL RET
Return from a subroutine
Address Address
Conditional Branch
Go to new location if a specified condition is met
JZ JNZ JC JNC JP JM Address (Jump on Zero) Address (Jump on NOT Zero) Address (Jump on Carry) Address (Jump on No Carry) Address (Jump on Plus) Address (Jump on Minus)
Go to address specified if the Zero flag is set Go to address specified if the Zero flag is not set Go to the address specified if the Carry flag is set Go to the address specified if the Carry flag is not set Go to the address specified if the Sign flag is not set Go to the address specified if the Sign flag is set
Machine Control
HLT
Stop executing the program
NOP
No operation Exactly as it says, do nothing Usually used for delay or to replace instructions during debugging
Program 1: Read a 16-bit number from memory, take its 1s complement and store it back in memory
Step English 1 Load number pointer of lower 8-bits to H 2 Move lower 8-bits to A 3 Complement A 4 Write A to C052 Mnemonic (Assembly) LXI H,C050 Memory Address C000 C001 C002 C003 C004 C005 C006 C007 C008 C009 C00A C00B C00C C00D C00E Hex 21 50 C0 7E 2F 32 52 C0 23 7F 2F 32 53 C0 76 Binary (Machine) 0010 0001 0101 0000 1100 0000 0111 1110 0010 1111 0011 0010 0101 0010 1100 0000 0010 0011 0111 1111 0010 1111 0011 0010 0101 0011 1100 0000 0111 0110
9 Halt
HLT
Note: The following slides have been adapted from works of others, primarily: 8085architecturememoryinterfacing1-100523023313-phpapp01.ppt by Pratik Amlani and 1204-ppi-8255-100523023201-phpapp02.ppt by Unknown
Memory Mapping
8085 has 16-bit Address Bus The complete address space is thus given by the range of addresses 0000H FFFFH The range of addresses allocated to a memory device is known as its memory map
U1 36 1 2 5 6 9 8 7 10 11 29 33 39 35 38 4 37 3 RST-IN X1 X2 SID TRAP RST 5.5 RST 6.5 RST 7.5 INTR INTA S0 S1 HOLD READY HLDA SOD CLKO RST-OT 8085 AD0 AD1 AD2 AD3 AD4 AD5 AD6 AD7 ALE A8 A9 A10 A11 A12 A13 A14 A15 IO/M WR RD 12 13 14 15 16 17 18 19 30 21 22 23 24 25 26 27 28 1 34 2 32 74LS32 U5A 3 3 4 7 8 13 14 17 18 11
U2 D0 D1 D2 D3 D4 D5 D6 D7 G Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 OC 2 5 6 9 12 15 16 19 1 10 9 8 7 6 5 4 3
U4 A0 A1 A2 A3 A4 A5 A6 A7 O0 O1 O2 O3 O4 O5 O6 O7 11 12 13 15 16 17 18 19
RAM
Memory device is selected only if IO/M = 0 & A15 = 0 You can do other things with A15=1, such as communicate with devices
31
= 0000H to
A11 to A0
1. 111
= 7FFFH
System Bus
8085
Memory Interface Memory Devices
Peripheral-mapped I/O
Reading Input: IO/M = 1, RD = 0 Write to Output: IO/M = 1, WR = 0
Memory-mapped I/O
8085 uses its 16-bit address bus to identify a memory location Memory address space: 0000H to FFFFH 8085 needs to identify I/O devices also I/O devices can be interfaced using addresses from memory space 8085 treats such an I/O device as a memory location This is called Memory-mapped I/O Same commands are used to communicate with I/O devices that are memory mapped, e.g.
MOV STA
STA 8001H
Stores (Outputs) contents of A to output device with 16-bit address 8001H
Example Program
WAP to read a number from input port (port address 8000H) and display it on ASCII display connected to output port (port address 8001H) LDA 8000H;reads data value 03H(example) into ;accumulator, A = 03H MVI B, 30H;loads register B with 30H ADD B ;A = 33H, ASCII code for 3 STA 8001H;display 3 on ASCII display
Peripheral-mapped I/O
8085 has a separate 8-bit addressing scheme for I/O devices I/O address space: 00H to FFH This is called Peripheral-mapped I/O or I/Omapped I/O The chip used to interface with peripherals is 8255 also called PPI (programmable Peripheral Interface) This uses different commands, e.g.
IN OUT
Example Program
WAP to read a number from input port (port address 01H) and display it on ASCII display connected to output port (port address 02H) IN 01H ;reads data value 03H (example) into ;accumulator, A = 03H from Port 01H MVI B, 30H;loads register B with 30H ADD B ;A = 33H, ASCII code for 3 OUT 02H ;display 3 on ASCII display Port 02H
8085
I/O Devices
Port Cu
8-bit ADC
Temperature Sensor
8085
8255
Port Cl
Problem example
Let us say that we want to read an 8-bit input, take its complement, and display the result on 8 LEDs Here are the steps to follow:
1. Configure the 8255 ports 2. Write program to:
1. Read input from an 8255 port 2. Take its complement 3. Write output to an 8255 port, which is connected to LEDs
8-bit input
System Bus Port Cu Port Cl
8085
8255
Application Programming
1. Configure 8255 I/O ports
1. MVI A, 90H 2. OUT CWR
Writing value 90H in Control Word Register of 8255 CWR represents the 8-bit port address of Control Word Register
Application Programming
2. Write program:
1. 2. 3. 4. 5. MVI A, 90H OUT CWR IN PORTA CMA OUT PORTB
3. Note that the output will have to be buffered, because the P output is fleeting (remains for a very short time)
A7 A6 A5 A4 A3 A2 A1 A0 A1 A0 CS
A = 80H B = 81H
8255
C = 82H
A1 A0 Port 0 0 1 1 0 1 0 1 A B C CWR
Classification of Interrupts
Based on priority:
Maskable Interrupts (Can be delayed or Rejected) Non-Maskable Interrupts (Can not be delayed or Rejected)
Responding to Interrupts
Responding to an interrupt may be immediate or delayed depending on whether the interrupt is maskable or non-maskable and whether interrupts are being masked or not. There are two ways of redirecting the execution to the ISR depending on whether the interrupt is vectored or non-vectored.
Vectored: The address of the subroutine is already known to the Microprocessor Non Vectored: The device will have to supply the address of the subroutine to the Microprocessor
Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
RST 5.5, RST 6.5, RST 7.5 are all automatically vectored.
RST 5.5, RST 6.5, and RST 7.5 are all maskable.
8085 Interrupts
Interrupt name INTR RST 5.5 RST 6.5 RST 7.5 TRAP
Example
Let , a device interrupt the Microprocessor using the RST 7.5 interrupt line.
Because the RST 7.5 interrupt is vectored, Microprocessor knows, in which memory location it has to go using a call instruction to get the ISR address. RST7.5 is known as Call 003CH to Microprocessor. Microprocessor goes to 003C location and will get a JMP instruction to the actual ISR address. The Microprocessor will then, jump to the ISR location
4. 5.
Equivalent to CALL 0000H CALL 0008H CALL 0010H CALL 0018H CALL 0020H CALL 0028H CALL 0030H CALL 0038H
Restart Sequence
The restart sequence is made up of three machine cycles
In the 1st machine cycle:
The microprocessor sends the INTA signal. While INTA is active the microprocessor reads the data lines expecting to receive, from the interrupting device, the opcode for the specific RST instruction.
77
Therefore, INTR should be turned off as soon as the INTA signal is received.
Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
Therefore, the answer is: only if we allow it to. If the EI instruction is placed early in the ISR, other interrupt may occur before the ISR is done.
Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
The 3 outputs carry the index of the highest priority active input.
The one draw back to this scheme is that the only way to change the priority of the devices connected to the 74366 is to reconnect the hardware.
Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
The vectors for these interrupt fall in between the vectors for the RST instructions. Thats why they have names like RST 5.5 (RST 5 and a half).
Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
Through individual mask flip flops that control the availability of the individual interrupts.
These flip flops control the interrupts individually.
0 - Available 1 - Masked
Mask Set Enable 0 - Ignore bits 0-2 1 - Set the masks according to bits 0-2
Not Used
Bit 4 of the accumulator in the SIM instruction allows explicitly resetting the RST 7.5 memory even if the microprocessor did not respond to it. Bit 5 is not used by the SIM instruction
M 7.5
RST 6.5
M 6.5
RST 5.5
M 5.5
INTR
Interrupt Enable Flip Flop
Triggering Levels
RST 7.5 is positive edge sensitive.
When a positive edge appears on the RST7.5 line, a logic 1 is stored in the flip-flop as a pending interrupt. Since the value has been stored in the flip flop, the line does not have to be high when the microprocessor checks for the interrupt to be recognized. The line must go to zero and back to one before a new interrupt is recognized.
- Enable 5.5 bit 0 = 0 - Disable 6.5 bit 1 = 1 - Enable 7.5 bit 2 = 0 - Allow setting the masks bit 3 = 1 - Dont reset the flip flop bit 4 = 0 - Bit 5 is not used - Dont use serial data - Serial data is ignored
EI MVI A, 0A SIM
; Enable interrupts including INTR ; Prepare the mask to enable RST 7.5, and 5.5, disable 6.5 ; Apply the settings RST masks
RST7.5 Memory
M 7.5
RST 6.5
M 6.5
RST 5.5
M 5.5 Interrupt Enable Flip Flop Source: www.aust.edu/cse/moinul/interrupt.ppt by Moinul Hoque
5 4
Serial Data In RST5.5 Interrupt Pending RST6.5 Interrupt Pending RST7.5 Interrupt Pending
0 - Available 1 - Masked
Pending Interrupts
Since the 8085 has five interrupt lines, interrupts may occur during an ISR and remain pending.
Using the RIM instruction, it is possible to can read the status of the interrupt lines and find if there are any pending interrupts.
TRAP
TRAP is the only non-maskable interrupt.
It does not need to be enabled because it cannot be disabled.
It has the highest priority amongst interrupts. It is edge and level sensitive.
It needs to go high and stay high to be recognized. Once it is recognized, it wont be recognized again until it goes low, then high again.
No Yes Yes
No No Yes
TRAP
No
Yes
No
The Stack
The stack is an area of memory identified by the programmer for temporary storage of information. The stack is a LIFO structure.
Last In First Out.
The Stack
Given that the stack grows backwards into memory, it is customary to place the bottom of the stack at the end of memory to keep it as far away from user programs as possible. In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
LXI SP, FFFFH
This sets the Stack Pointer to location FFFFH (end of memory for the 8085). The Size of the stack is limited only by the available memory.
LIFO
The order of PUSHs and POPs must be opposite of each other in order to retrieve information back into its original location. PUSH B PUSH D ... POP D POP B Reversing the order of the POP instructions will result in the exchange of the contents of BC and DE
It is possible to push the PSW onto the stack, do whatever operations are needed, then POP it off of the stack.
The result is that the contents of the Accumulator and the status of the Flags are returned to what they were before the operations were executed
Subroutines
A subroutine is a group of instructions that will be used repeatedly in different locations of the program.
Rather than repeat the same instructions several times, they can be grouped into a subroutine that is called from the different locations.
Subroutines
The 8085 has two instructions for dealing with subroutines.
The CALL instruction is used to redirect program execution to the subroutine. The RET instruction is used to return the execution to the calling routine.
CALL Instruction
CALL 4000H (3 byte instruction)
When CALL instruction is fetched, the MP knows that the next two Memory location contains 16bit subroutine address in the memory.
CALL Instruction
MP Reads the subroutine address from the next two memory location and stores the higher order 8bit of the address in the W register and stores the lower order 8bit of the address in the Z register Push the address of the instruction immediately following the CALL onto the stack [Return address] Loads the program counter with the 16-bit address supplied with the CALL instruction from WZ register
RET Instruction
RET (1 byte instruction)
Retrieve the return address from the top of the stack Load the program counter with the return address
The RET instruction takes the contents of the two memory locations at the top of the stack and uses these as the return address.
Do not modify the stack pointer in a subroutine. You will loose the return address.
A Proper Subroutine
According to Software Engineering practices, a proper subroutine:
Is only entered with a CALL and exited with an RET Has a single entry point
Do not use a CALL statement to jump into different points of the same subroutine.
Has a single exit point
A tri-state buffer is used to connect the input device to the data bus. The control (Enable) for these buffers is connected to the result of combining the address signal and the signal IORD.
However, the latch will not be able to source enough current. So, we will use the inverted outputs and make it sink the current instead.
A8 IO/M WR
Latch Enable
Source: http://www.kulo.in/micro/8085ss/Chapter%25204.ppt