EMAC PRIMER Instruction Manual page 78

Table of Contents

Advertisement

LESSON 26: Writing Your Own Programs
NEW INSTRUCTIONS
LXI
D,<word>
Load the DE register pair with the word (a word = 2 bytes) that follows the op code. The byte following the
op code goes in the E register and the byte after that goes into the D register. No flags are affected.
Now that you have a basic knowledge of most of the 8085 instructions, it is possible for you to write your own programs.
The first step is to decide what you want the program to do. If what you want it to do is similar to what one of the programs
in the previous lessons does, you can just modify the program in the lesson to suit your needs. You can also combine
programs from different lessons to make a program.
Suppose you decide to make a calculator program which adds the hex digits that you type on the keypad and then shows
the total on the display when a key other than a hex digit is typed. To start write the program in your own words, in english.
This is called "pseudo-code". A pseudo-code version of the program is as follows:
1.
make the total 0
2.
read the keypad
3.
if the key pressed wasn't a hex digit, go to step 6
4.
add the key to the total
5.
go to step 2
6.
display the total
7.
go to step 1
Now convert the above program to assembly language.
1.
The first step requires that the total be made 0. You must decide which register or register pair will hold the total.
The DE register pair would work well for this. To make the DE register 0 you can use the instruction LXI D,0.
2.
The next step is to read the keypad. This was done in lesson 23 and involved two assembly language instructions:
MVI C,KEYIN and CALL MOS.
3.
Step three checks to see if the number that was typed isn't a hex digit. An easy way to do this is to see if the
number is greater than F hex and this can be done with a compare instruction. Remember that in a compare
instruction, if the number being compared to the A register is bigger, the carry flag is set. Since the keyin service
returns the number of the key in the L register it is necessary to load the A register with 0F hex which is the value
that you want to compare it with. To load the A register with 0F and compare it to the L register you must use the
two following assembly language instructions: MVI A,0Fh and CMP L. In order to jump to step 6 when L is greater
than 0F hex (in which case the carry flag is set) a JC DSPLAY instruction can be used. The DSPLAY label is used
because we don't know the address of the display code yet.
4.
There are several different ways to add the key value that is in L to the total that is in DE. One of the most efficient
ways is to load the H register with 0 and add DE to the HL register then exchange the DE register with the HL
register so the total will be in DE again. This can be done with the following assembly language instructions: MVI
H,0 , DAD D, and XCHG.
5.
Step 5 can be translated easily to a jump instruction. We will give the jump address the label "RDKEY" since it
jumps to the instructions that read the keys. Therefore the assembly language for this instruction will be JMP
RDKEY.
6.
To display the total that is in the DE register you can use the ledhex service (service 12), which displays the hex
value in the DE register pair to the "ADDRESS/REGISTER PAIR" displays. So the assembly language
instructions for this will be: MVI C,LEDHEX and CALL MOS.
7.
The last step can be easily translated to the assembly language instruction JMP START, where START is a label
pointing to the first instruction.
Make a listing of the assembly language instructions that were given above. Start the listing with an ORG instruction
followed by the EQU instructions necessary to define the values of "mos", "keyin" and "ledhex" and put the labels "start"
and "rdkey" in the label field before their appropriate instructions. Also add comments to each line to enhance readability
and put an END instruction at the end. It should look like the following:
op code = 11
78

Advertisement

Table of Contents
loading

Table of Contents