• Keine Ergebnisse gefunden

DATA STORAGE CONVENTIONS

Im Dokument MICROPROCESSO� SOFTWARE & HARDWARE (Seite 116-130)

TWO AND THREE BYTE INSTRUCTIONS

2.2 DATA STORAGE CONVENTIONS

You may have wondered why 8300 was selected as the storage location for this result. While it is somewhat arbitrary, the basic requirement is to keep programs and data separated. It would have been quite possible, for example, to store the results in location 820F. The program would execute exactly as before, except that the results would be placed in a different memory word. Suppose,

however, that you wished to modify the program, to add instructions to achieve some different purpose? The program could not utilize additional consecutive addresses without changing the initial storage address. In the example, only one such address was used, but in a

�omplex program with many storage addresses, the problem becomes acute. Data addresses are therefore chosen to leave lots of space between program and data areas.

N.B. As the monitor is stored in read�only memory, it requires part of the RAM for temporary storage of data. Sixty four bytes of RAM, addresses 83CO through 83FF, are allocated to the monitor; care should be taken not to modify these memory locations.

TWO AND THREE BYTE INSTRUCTIONS 2.3 PROGRAM EXERCISE #3

2.3.1 The LDA Instructions

An instruction similar to STA has the effect of transferring data from memory to the Accumulator:

BINARY CODE:

HEX CODE:

BYTE TWO:

BYTE THREE:

MNEMONIC:

MEANING:

00111010 3A

Low-order part of address.

High-order part of address.

LDA

Load the Accumulator with the contents of the word whose address is contained in the following two memory locations.

The detailed instruction cycle for LDA is shown in Figures 2-1, 2-2, and 2-3.

data bus.

In these figures note the mention of the address bus and Review Section 1.3.3 and be sure you understand these buses and their functions.

PROCESSOR MEMORY

TWO AND THREE BYTE INSTRUCTIONS returns its contents on data bus Register Z and increments Processor sends PC

@

Processor sends contents of W and z on address bus

TWO AND THREE BYTE INSTRUCTIONS 2.3.2 The JMP Instruction

To this point we have used instructions which perform an operation and advance the program counter so that it points to the address of the next sequential instruction. A very important class of instructions allows a program to branch or "jump" to an instruction at an arbitrary add ress. One of these instructions is JMP:

BINARY CODE:

HEX CODE:

BYTE TWO:

BYTE THREE:

MNEMONIC:

MEANING:

11000011 C3

Low-order part of address.

High-order part of address.

JMP

Load the PC with address contained in the following two memory

locations.

The Execution cycle of the JMP instruction is shown in Figures 2-4 and 2-5.

PROCESSOR MEMORY

TWO AND THREE BYTE INSTRUCTIONS

Register

w.

Processor transfers data from

Counter W and

z

into Program

JMP Instruction Cycle (continued)

MEMORY

2.3.3 Writing the Program Program specification:

"Write a program which will clear the Accumulator, load it with the contents of 8300, increment this number by one, and store the result in 8300. Loop through this sequence repeatedly."

The program below starts with three consecutive NOPs, a convention which would permit entering a three-byte instruction here, should we

wish to change the program later:

ADDR HEX MNEMONIC COMMENTS

8200 00 NOP Dummy

01 00 NOP

02 00 NOP

03 AF XRA A Clear A

04 3A LOA 8300 Load A from 8300

05 00

06 83

07 3C INR A Increment A

08 32 STA 8300 Store A in 8300

09 00

OA 83

OB C3 JMP 8203 Jump back to Start

oc

03

TWO AND THREE BYTE INSTRUCTIONS

Load and verify the program, press RST to set (PC) to 8200, then press STEP:

I

STEP! 82011

ooJ.

STEP executes the first NOP instruction and displays the next one:

I

STEPI

1

8202) 00)

I

82031

AF!

Two m ore STEP's get us to the Clear A instruction, AF, at 8203.

Execute this instruction.

lsTEPI

I

8204

!

We have executed Clear A. The next instruction is LOA. (3A at location 8204)

I

STEP!

I

82011

3Al

3Cl

We cannot see the internal steps. The three byte instruction LOA occupies addresses 8204, 8205 and 8206. It has been executed and now the INR A instruction at 8207 is displayed.

Execute the INR A instruction.

321 This is STA, another three byte instruction.

1820B I C3l We have come to the JMP instruction.

I 82031 AF!

And now we are back to the start. Examine Register A.

EJEJ !

8203!

!

A-15)

The program loaded 14 from 8300, incremented it and stored the new value. Register A still holds that value. Execute the Clear A instruction at 8203.

Now Register A has been cleared.

I

s204

I I

A-oo

I

TWO AND THREE BYTE INSTRUCTIONS

I

ADDRI I 82011 3C]

ADDR displays the instruction

I 8208! 1 A-161

Step executes it and again displays the register we last examined.

Let's examine the memory location.

BEJEJEJEJ I

83001 15!

The new value has not been stored yet. DO NOT PRESS STEP NOW - The computer would execute from location 8300. Use ADDR to recall the current program counter.

I ADDRI j 8208l 32l

Then STEP.

I

STEPI 820BI

I A-lGI

And look again at 8300:

IADDRI

EJ [] EJ EJ I

s3oo

I

16)

Now the new value has been stored.

83001

.16!

MEM tells the monitor you did not intend to change the program counter, but only the memory address. Therefore you can now use STEP. The PC contained 8208, addressing the Jump instruction.

ISTEPI 18203

! AF!

So we jumped. Using the MEM key disposed of.Register A display. The memory address we last requested is still there, so pressing MEM will fetch it back again.

EJ

18300

I

.16!

We have introduced four new instructions and looked at the details of their execution cycles. The instructions are summarized in Section 2.4, and the command key functions are reviewed in Section 2.5. In Chapter 3 we will begin to develop some fundamental concepts of programming.

TWO AND THREE BYTE INSTRUCTIONS 2.4 SUMMARY OF INSTR UCTIONS

3C INR A Increment Register A One byte

one

machine cycle AF XRA A Clear Register A

One byte

One machine cycle

C6 ADI Add immediate

xx data Two bytes

Two machine cycles

32 STA Store Register A

xx low address Three bytes

xx high address Four machine cycles

3A LDA Load Register A

xx low address Three bytes

xx high address Four machine cycles

C3 JMP Jump

xx low address Three bytes

xx high address Three machine cycles

Im Dokument MICROPROCESSO� SOFTWARE & HARDWARE (Seite 116-130)