EMAC PRIMER Instruction Manual page 53

Table of Contents

Advertisement

LESSON 17: Using Variables
NEW INSTRUCTIONS
SHLD <addr> op code = 22
Store the L register at memory address <addr> and store the H register at memory address <addr+1>.
The first byte after the op code is the low order byte of <addr> and the second byte after the op code is the
high order byte of the address. No flags are affected.
LHLD <addr> op code = 2A
Load the L register with the data at memory address <addr> and load the H register with the data at
memory address <addr+1>. The first byte after the op code is the low order byte of <addr> and the
second byte after the op code is the high order byte of the address. No flags are affected.
STA
<addr> op code = 32
Store the A register at memory address <addr>. The first byte after the op code is the low order byte of
<addr> and the second byte after the op code is the high order byte of the address. No flags are affected.
LDA
<addr> op code = 3A
Copy the value from memory address <addr> to the A register. The first byte after the op code is the low
order byte of <addr> and the second byte after the op code is the high order byte of the address. No flags
are affected.
RLC
Shift every bit left and copy the bit shifted out of bit 7 into bit 0 and the carry flag. Only the carry flag is
affected.
Variables are areas of RAM that the programmer intends to be changed during the execution of a program. In contrast,
constants are values that a programmer does not desire to change. For example, if you want to load the A register with an
8 bit constant, use the instruction MVI A,<byte>, but if you want to load it with an 8 bit variable, use the instruction LDA
<addr>. Similarly, when you want to load the HL register pair with a 16 bit constant, use the LXI H,<addr> instruction, or if
you want to load it with a 16 bit variable, use the instruction LHLD <addr>.
To store a value in an 8 bit variable, you can use the instruction STA <addr> and to store a 16 bit variable, you can use
SHLD <addr>.
The program below uses a 16 bit variable and 8 bit variable to produce a LED pattern that changes at a varying rate. The
program could have easily been written using registers instead of variables. It is written this way to demonstrate the new
instructions.
org
lxi
lxi
mvi
dlay:
sta
dad
shld
dlay1:
dcx
mov
ora
jnz
lda
out
rlc
lhld
jmp
dlaytm:
ds
leddta:
ds
end
op code = 07
0ff01h
h,8000h
; load hl with the constant 8000h
d,-100h
; load de with the constant -100h
a,1
; load A with the constant 1
leddta
; store A in the LED data variable
d
; add de to HL
dlaytm
; store the new delay
h
; decrement HL
a,h
; move H to A
l
; so it can be ORed with L
dlay1
; if H and L are not 0, go to dlay1
leddta
; get the LED data
leds
; output the pattern to the LEDs
; rotate bits left
dlaytm
; load hl with delay variable again
dlay
; do another delay
2
; length of delay
1
; bit pattern to output to LEDs
53

Advertisement

Table of Contents
loading

Table of Contents