0% found this document useful (0 votes)
53 views

Lecture 6

A subroutine is a piece of code that can be called from anywhere in a program. It starts with a label and ends with a RET instruction. A CALL instruction is used to call a subroutine. Subroutines can be user-defined or provided by a manufacturer. The Ohm's Trainer contains subroutines like DELAY, DISPLAY, and GETKEY that perform tasks like delaying, displaying characters, and getting keyboard input. An example program is provided that displays the word "HELP" on the trainer's display for 10 seconds using these subroutines.

Uploaded by

Said Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Lecture 6

A subroutine is a piece of code that can be called from anywhere in a program. It starts with a label and ends with a RET instruction. A CALL instruction is used to call a subroutine. Subroutines can be user-defined or provided by a manufacturer. The Ohm's Trainer contains subroutines like DELAY, DISPLAY, and GETKEY that perform tasks like delaying, displaying characters, and getting keyboard input. An example program is provided that displays the word "HELP" on the trainer's display for 10 seconds using these subroutines.

Uploaded by

Said Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Program Subroutines

A subroutine is a piece of code that can be


called from anywhere in a program. In
higher level programming languages they
are referred to as procedures and/or
functions.
In assembly language a subroutine starts
with a Label and ends with the RET
instruction (Return).
Program Subroutines..
A CALL instruction is used to call a sub-
routine:
CALL address
With the first instruction in a sub-routine
labelled the label becomes like a subroutine
name.
CALL subroutine_Label
Program Subroutines..
A subroutine can be user-defined
(user-developed) or provided by
microcomputer training kit
manufacturer.
The Ohm’s Trainer Subroutines
Address ROM Purpose
Name Address
(LABEL)
DELAY 1200H Provides a 1 sec delay (HL count
F9B0). Destroys Accumulator
DISPLAY 1000H Display characters that are in the
Display buffer (Reg. pair H pointing to
display buffer i.e. Buffer Contains
Offset addresses from the top of the 7-
Segment Codes lookup tables)
GETKEY 1100H Waits for a key to be pressed.
Returns the pressed key in
Accumulator
The Ohm’s Trainer Display Buffer
Buffer Content (hex) Display Character
00 0
01 1
02 2
03 3
04 4
05 5
06 6
07 7
08 8
09 9
0A A
0B B
0C C
0D D
0E E
0F F
The Ohm’s Trainer Display Buffer..
Buffer Content (hex) Display Character
10 G ?/
11 H
12 I
13 J
14 K??
15 L
16 M??
17 N
18 O
19 P
1A ??
1B R
1C ??
1D T
1E U
1F ??
20 ??
21 ??
22 Y
23 ??
24 Blank
25 ??
26 -
27 =
28 _
29 C
2A H
The Ohm’s Trainer SubRoutines..

Example :
Write a program that displays the
word HELP on the Trainer Address
Field for 10 seconds.
Display HELP Example
Label Mnemonic Comment
  NAME HELP ;Program Name
  DELAY EQU 1200H ;Delay Routine ROM Address
  DISPLAY EQU 1000H ;Display Routine ROM Address
  ORG 8100H ;Program Starting Address
  LXI SP, 8200H ;Initialise Stack Pointer
  LXI H, CHARS ;Point to display characters Buffer
  CALL DISPLAY ;Display HELP
  MVI B, 0AH ;10 seconds loop counter
WAIT: CALL DELAY ;1 second delay
  DCR B ;Is 10 seconds Interval over?
  JNZ WAIT ;No – Another one second Delay
  RST 0 ;Yes - Done.
CHARS: DB 11H, 0EH, 15H, 19H ;HELP Characters
   DB 24H, 24H  ;Blank characters for Display Data field
Exercise

1. Assemble the HELP program and


Test it
2. Modify the HELP Example such that
it continuously Flashes HELP i.e.
Display HELP for 2 seconds followed
by Blank for 1 second endlessly
Example
Example :
Write a program that behaves like a
second counter displaying decimal
seconds in the Data Display field of
the Ohm’s Trainer. The seconds
should be displayed endlessly in this
manner: 00,01,02,…58,59,00,02,etc.
Seconds Counter Flow Chart
Seconds Counter Program
Plan of Action:
-The display Buffer consists of 6 bytes. The first 4
are for the Address field. The last 2 are for the Data
display field.
-To display the current second the lower nibble has
to be written to the 6th byte and the Upper nibble to
the 5tn byte in the display buffer. The DISPLAY
routine is then called.
-The built-in 1 second DELAY routine will be
utilised.
Program Header
Label Mnemonic Comment

  NAME SECNDs ;Program Name

  DELAY EQU 1200H ;1 second Delay ROM Routine


; Address
  DISPLAY EQU 1000H ;Display ROM Routine Address
 

  ORG 8100H ;Program Staring Address


Initialisation and Display Calls
  LXI SP, 8200H ;Initialize Stack Pointer

INIT: MVI B,00H ;Initialize Current Second

       

COUNT: CALL SHOW ;Display Currant Second

  CALL DELAY ;Delay for 1 second


Adjusting Count To Decimal
  INR B ;Get Next Second

  MOV A,B ;Prepare to adjust it to decimal

  ORA A ;make sure CY = 0 and AC = 0

  DAA   ;Adjust new current second


;to decimal
  MOV B,A ;Save new current second
Loop Control
  CPI 60H ;Is One minute over?

  JNZ COUNT ;No – process new second count


;for display

  JMP INIT ;Yes- Start all over again?


The SHOW Subroutine
SHOW: MOV A, B ;Get Current Second

  ANI 0FH ;Extract lower nibble i.e.


;Mask off upper Nibble
  LXI D, CHARS + 5 ;Point to Display Buffer
;6th Location for Lower
;Nibble.
  STAX D ;Send lower nibble to
;display buffer
The SHOW Subroutine…
  MOV A,B ;Retrieve current second
  ANI 0F0H ;Mask off lower Nibble
  RRC   ;Extract Upper Nibble
  RRC    
  RRC    
  RRC    
  DCX D ;Point to Display Buffer Location
      ;for Upper Nibble.
  STAX D ;Send Upper nibble to display
;buffer
The SHOW Subroutine…
  LXI H, CHARS ;Point to Display Buffer
  CALL DISPLAY ;Display Current Count
  RET   ;Return to Main Program

       
CHARS: DB 24H,24H,24H ;Initialize BLANK characters
  DB 24H,24H,24H ;for the entire Display Unit

  END    
Exercise

Using the seconds counter as a foundation


develop a real clock program that displays
hours and minutes in the Address field, and
seconds in the Data filed.
Hint:
Place seconds in Register B, Minutes in
Register E, and Hours in Register D
The Ohm’s Trainer
An Intel 8085 based microcomputer to be
used in the Lab:
• The EPROM chip Starting Address:
0000H

• The RAM Starting Address : 8000H


The Ohm’s Trainer…
To feed in the machine code program:

1. Press RESET to Reset /Restart the System


then press INC Key.
2. The Address Field shows the RAM Starting
Address 8000H . In Case it is not the desired
Starting Address Press RESET type in the
desired Address then Press INC
The Ohm’s Trainer…

3. The Data Display Filed now shows the


Content of the displayed address. Overwrite
the Content by typing in the desired data then
press INC. The address Filed is incremented
by 1 and you can type in the content of the
new address then press INC. This is repeated
until the entire program is entered.
The Ohm’s Trainer…

4. To Run the program press the EXEC


key then type in the program starting
address in case it is different from that
shown then press INC.

You might also like