You are on page 1of 30

u 




 

Lecture 6: Control Instructions

|   |


OBJECTIVES

u Explain the operation of the unconditional and


conditional jump instructions.
u Describe the flags tested by each conditional jump
instruction.
u Explain the operation of the unconditional and
conditional call and return instructions.
u Show how the stack functions when used by the
call and return instructions.
u Describe the operation of the instructions: NOP,
RST, STC, CMC, RIM, SIM, and HLT.

a September 2010 Prepared by: Dr Masri Ayob 2


3

  


u Allow computers to make decisions and


change the flow of the programme based on
the results outcome.
u Two main forms:
u JUMP instructions:
u Allow programme to jump to any memory

locations.
u CALL instructions
u Allow a group of instructions (subroutine) to be

reused by the program in many different


places.

a September 2010 Prepared by: Dr Masri Ayob 3


UNCONDITIONAL JUMP INSTRUCTIONS

u This is a three-byte instruction that allows the


programmer to jump over unused portions of the
memory.

a September 2010 Prepared by: Dr Masri Ayob 4


UNCONDITIONAL JUMP INSTRUCTIONS

u The JMP instruction uses direct addressing, and the PCHL


instruction uses register indirect addressing.
u This causes the next program instruction to execute at the
address stored with the JMP instruction.
u The PCHL instruction causing the microprocessor to jump
to the memory location addressed by the HL register pair.
a September 2010 Prepared by: Dr Masri Ayob 5
UNCONDITIONAL JUMP INSTRUCTIONS

a September 2010 Prepared by: Dr Masri Ayob 6


3 u 

u Conditional JUMP instructions:


u Allow the programmer or programme to make a choice based
on conditional terms.
u A condition is tested by the microprocessor to decide whether a
jump occurs.
u The conditions tested by the conditional jumps are the same
conditions held in the flag bits.
u The terms are :
u Zero / not zero

u Carry set / cleared

u Positive / minus

u Parity odd / even

a September 2010 Prepared by: Dr Masri Ayob a


CONDITIONAL JUMP INSTRUCTIONS

a September 2010 Prepared by: Dr Masri Ayob 8


CONDITIONAL JUMP INSTRUCTIONS

a September 2010 Prepared by: Dr Masri Ayob 9


CONDITIONAL JUMP INSTRUCTIONS

a September 2010 Prepared by: Dr Masri Ayob 10


EXAMPLES

u 1. Write a short program that tests the contents of


memory location F000H. If it contains a positive number,
jump to location F200H; if negative number, jump to
location F400H; and if it contains a zero, jump to location
F800H.

u 2. Write a short program that tests the contents of


memory location F000H. If it contains a number >20H,
jump to location F200H; if it contains a number <20H,
jump to location F400H; and if it contains a number =20H,
jump to location F800H.

a September 2010 Prepared by: Dr Masri Ayob 11


SUBROUTINES

u A subroutine is a short sequence of instructions that


performs a single task.
u One advantage of using a subroutine is a significant
savings of memory space.
u Subroutines also simplify the task of writing a program
because subroutines only appear in a program once, but
are used often.
u CALL instruction allows the programmer to use (link to) a
subroutine.
u When the 8O85 executes a CALL instruction, two events
occur:
u u 
  
 3    

  
u u 
 
    
 3
  
 u 3   
 
!

 "#
    
 

a September 2010 Prepared by: Dr Masri Ayob 12


SUBROUTINES

a September 2010 Prepared by: Dr Masri Ayob 13


SUBROUTINES

u The RET(return) instruction returns to the main program at the


instruction that follows the CALL.
u This can be accomplished because the address of this instruction is
stored on the stack because the CALL placed it there as a return
address.
u The RET command POPs a number from the stack and places it into
the program counter.

a September 2010 Prepared by: Dr Masri Ayob 14


  $ "%&'''#

SUBROUTINES STACK(before)
CALL COMP
1000

?
?

()u*+,($$,-

STACK

20 FFFF

05 FFFE

REGISTERS
A 01

PC 2040

SP FFFE

a September 2010 Prepared by: Dr Masri Ayob 15


EXAMPLES

u Write a short program that ADD the contents of


memory location F000H and F001H. If the result
>20H, CALL subroutineA; If the result =20H,
CALL subroutineB; else CALL subroutineC.

a September 2010 Prepared by: Dr Masri Ayob 16


The Restart Instructions

u These are special unconditional CALL instructions,


because they call a subroutine at a fixed location
in the memory instead of a variable location as
addressed by the CALL instruction.
u E.g. RST 2
u This instruction calls the subroutine at memory

location 0010H, i.e. RST 2 CALL 0010H


u RST N CALL Nx8

a September 2010 Prepared by: Dr Masri Ayob 1a


The Restart Instructions

a September 2010 Prepared by: Dr Masri Ayob 18


MISCELLANEOUS INSTRUCTIONS

u Program execution is stopped by the HLT (halt) instruction.


u 0 

.
  #u  
!./

/   

u 0
      
 
   
  
u u  
 
 !  / 
  

  
 .  

a September 2010 Prepared by: Dr Masri Ayob 19


MISCELLANEOUS INSTRUCTIONS

u An interrupt is a hardware-initiated subroutine call, that


interrupts the currently executing program.
u Whenever the hardware interrupts the microprocessor, it
calls a subroutine that services the interrupt. This special
subroutine is called an interrupt service subroutine (ISR).

a September 2010 Prepared by: Dr Masri Ayob 20


MISCELLANEOUS INSTRUCTIONS
u u +"  
  
   "" 
 
u u u+   !  
!   !.
   

  
 
u u   

  
    
 
  1+"u2 3+"u 3+"u3 3u+4

a September 2010 Prepared by: Dr Masri Ayob 21


MISCELLANEOUS INSTRUCTIONS

u Whenever an ISR takes effect, all future interrupts are


disabled (except TRAP).
u u  .   
104 !  
    
u u 0  
 ! u+     
    
u u   
 !        
 u+ 1
 u+ ! 
     
  !. 


4

a September 2010 Prepared by: Dr Masri Ayob 22


SIM INSTRUCTIONS
u The SIM instruction (set interrupt masks) enables or disables the RST
a.5, RST 6.5, and RST 5.5 pins.
u This instruction also controls the SOD (serial output data) pin on the
8085 and resets the edge-triggered RST a.5 input.
u Table 6-8 lists the bits of the accumulator before a SIM and their effect
on the operation of the machine.

a September 2010 Prepared by: Dr Masri Ayob 23


SIM INSTRUCTIONS
u 0  
  "  
 5'53" !1
  4 
6
7&8 

   

 "
  

u u
    
 +"u    "0!
   '
&  !  
&   


   
 
'  
 

u   
  !  +"u 3  !  +"u2 3
+"u3 3  
   ! !    0  
 ! 
 
 
 +"u 

a September 2010 Prepared by: Dr Masri Ayob 24


DIM INSTRUCTIONS

u The RIM instruction (read interrupt mask) reads the SID pin
(serial input data), the masks, interrupt pins, and the
interrupt enable status.
u The RIM instructions will read the information listed in Table
6-9 into the accumulator.

a September 2010 Prepared by: Dr Masri Ayob 25


DIM INSTRUCTIONS

u The IE bit of the accumulator shows whether El or DI has


been executed most recently.
u This bit also changes whenever an interrupt takes effect,

because interrupts always clear IE disabling future


interrupts. .

a September 2010 Prepared by: Dr Masri Ayob 26


SUMMARY

u Program control instructions allow a program to jump around unused


sections of the memory and allow the program to test the flag bits to
make decisions.
u The unconditional jump (JMP) is a three-byte instruction that causes
program execution to continue at the memory address stored with the
instruction.
u The conditional jump instructions allow the flags (Z, C, S, and P) to be
tested. If the outcome of the test is true, a jump occurs; if the
outcome is false, the next sequential instruction in the program
executes.
u Subroutines are short programs that perform one task, end with a
return instruction, and can be used often from another program.
u The CALL instruction links to a subroutine. It does this by pushing the
contents of the program counter onto the stack and jumping to the
memory location stored in bytes 2 and 3 of the instruction.

a September 2010 Prepared by: Dr Masri Ayob 2a


SUMMARY

u The return address is the contents of the program counter placed on


the stack by a CALL instruction. The return address is removed from
the stack by the return (RET) instruction, which places it back into the
program counter from the stack.
u Conditional call and return instructions work like the conditional jump
instruction. If the condition tested is true, the call or return occurs, and
if false, the next sequential instruction executes.
u Restarts (RST) are one-byte call instructions. The location called by a
RST can be determined by multiplying the restart number times 8. For
example, RST 5 is equivalent to a CALL 0028H.
u The NOP instruction performs no operation and sometimes appears in
time- delay software because it takes about 2 us to do nothing.

a September 2010 Prepared by: Dr Masri Ayob 28


SUMMARY

u The STC and CMC instructions set carry and complement carry,
respectively.
u The HLT (halt) instruction halts execution until either a system reset or
an interrupt.
u The 8085A contains five interrupt inputs (TRAP, RST a.5, RST 6.5, RST
5.5, and INTR) and two serial data pins (SID and SOD).
u The RIM (read interrupt masks) and SIM (set interrupt masks)
instructions control the interrupt structure of the 8085A and the serial
data pins.
u El (enable interrupts) and DI (disable interrupts) turn all the interrupts
on and off except TRAP, which can never be disabled. The RST pins
may still be disabled after an El, if the mask bits are set.

a September 2010 Prepared by: Dr Masri Ayob 29


Thank you
Q&A

a September 2010 Prepared by: Dr Masri Ayob 30

You might also like