Anda di halaman 1dari 23

Addressing Mode & Programming Basics

By Hoo Mow Heng

Addressing Modes g
Addressing modes define how machine language i t ti l instructions id tif th operand of identify the d f each instruction. An dd A addressing mode specifies h i d ifi how t calculate to l l t the effective memory address of an operand by using information held in registers and/or constants contained within an instruction. Different computer architectures vary greatly as to the number of addressing modes they provide.

Addressing Modes
The 8085 provides FIVE different modes for address data: 1. Direct Addressing 2. Register Addressing 3. Register Indirect Addressing 4. Immediate Addressing 5. 5 Implied Addressing

Direct Addressing
In direct addressing mode, the address of the data is specified in the instruction. This mode creates instructions 3 bytes long. y g The first byte contains the operation to be p performed. The second (low order byte) and third bytes (high order byte) contain the address in memory where the data byte may be found. Ex. LDA 1050H - Load the data available in memory location 1050H in to accumulator

Register Addressing
In register addressing mode, the instruction specifies the name of the register in which the data is available. This mode results in single-byte instructions. The byte contains bits which specify a register or register pair in which the data is located. Ex MOV A, B - Move the content of B Ex. A register to A register

Register Indirect Addressing


In register indirect addressing mode, the instruction specifies th name of th register i which th address of ifi the f the i t in hi h the dd f the data is available. Here the data will be in memory and the address will be in the i th register pair. i t i This mode results in single-byte instructions. The byte contains bits which specify a register pair, which in turn contains the address of the data in f memory. The high order byte address is stored in the leftmost of the th register pair, while th l i t i hil the low order b t of th address d byte f the dd is stored in the rightmost of the register pair. Ex. Address 3000H would be stored as 30 in H, and 00 in L. E MOV A, M - Th memory d t addressed b H L pair Ex. A The data dd d by i is moved to A register. LDAX B.

Immediate Addressing
In immediate addressing mode, the data is specified in g , p the instruction itself. The data will be a part of the program instruction. Thi mode results in a two or three byte instruction. This d lt i t th b t i t ti The first byte contains the instruction itself. The second and third bytes contain the immediate data data, either as a single 8-bit value, or as a 16-bit value. If the 16-bit value is used, the bytes are reversed, with the second byte containing the low order byte, and the third byte containing the high order byte. EX MVI B 3EH - Move the data 3EH given in the EX. B, instruction to B register; LXI SP, 2700H.

Implied Addressing
In implied addressing mode the mode, instruction itself specifies the data to be operated. operated Ex. CMA - Complement the content of accumulator; RAL

Five Steps of Programming


1. 1 2. 3. 3 4. 5. Definition of Problem Logic Design Programming P i Load, Test and Debug Documentation

1. Definition of Problem
Clarify Programming Needs. Knowing the objective is the first consideration. Is it a payroll or editing program? Knowing who the end user will be is also important. Determining the inputs and outputs is next. How will the program operate and what data is needed to make it happen. After this has been decided feasability is the next consideration. How many programmers will it take, is the project within budget, does the project have a realistic outline outline. Finally, if the project is a go, then one must take measures to ensure the proect is properly documented and analyzed. Six mini steps:
Clarify objectives and users Clarify desired outputs Clarify desired inputs Clarify desired Cl if d i d processing i Double - check feasibility of implementing the program Document the analysis

2. Logic Design
Design the program. Programs use algorithms which are like equations that tell the computer what task to perform. The aim of the programmer is to create algorithms that are clear and p g g simple. Algorithms are expressed first in logical hierarhical form known as modularzation. Using modules or (a complete thought) the programmer creates a logical thought process for the computer to follow. After that the program is broken down in greater detail using psuedocode. Psudocode uses terms like if, else, and, then to relate the programs rules to the computer computer.

Two mini steps:


Determine program logic through top down approach and modularization, using a heiarchy chart Design details using pseudocode and/or flowcharts preferably involving flowcharts, control structure.
A module, a processing step of a program, made up of logically related program statements. A hierarchy chart, which represents top-down program desigh, explains the main purpose of the program. Pseudocode, a way of desighing a program which uses normal language statements in order to describe the logic and the p g processing flow. g Program flowcharts, graphically shows the detailed series of steps

Three control structure:


Sequence control stucture Selection control structure Loop control structure

3. Programming
Code the program. After the program has been designed it must the be coded or p g g written. Using the psudocode and logic requirements from step two an appropriate p g pp p programming language must be selected. g g g As stated in the introduction, coding languages differ in specifications and usability. Once the appropriate code language has been chosen, it is imperative that the programmer follow the , p p g sytax rules with as little deviation as possible.

Two mini steps:


Select the appropriate high-level programming language Code the program in that language following the syntax carefully

4. Load, Test and Debug


Testing the p g g program comes in two p phases, alpha and , p beta. Alpha testing is the process of reading through the program i search of errors i l i Th second step i in h f in logic. The d t is to run a diagnostic program to search for syntax or input errors. Beta testing involves using the program in the real world to see if it contains any bugs or other deficiences. D b Debugging i a methodical process of fi di and i is th di l f finding d reducing the number of bugs, or defects, in a computer p g program thus making it behave as expected. g p

5. Documentation
Documentation should be ongoing from the very g g y beginning because it is needed for those involved with program now and future. U Upon completion U l ti User D Documentation f commercial t ti for i l use, Operator Documentation for people who run computer systems, and Programmer Documentation for programmers charged with maintenancing the program are all issued. Four mini steps:
Write user documentation Write operator documentation Write programmer documentation Mantain the program

Structured Design Using Flowcharts Fl h


Simple programming exercises can often be solved by just itti down and writing code t i l j t sitting d d iti d to implement th t the desired problem. Complex problems, however, can be difficult to write and impossible t d b if not i l i ibl to debug t implemented using a t d i structured design process. Using a structured design proses leads to the following benefits: Early detection of design flaws. Programs that can be easily modified. Clear and complete documentation. Modular design to improve testing. Modular design to break up problem into smaller sections.

The application of a structure design methodology greatly increases the probability of completing a successful design with a minimum amount of time and expense. By using a structured design methodology, the likelihood methodology of finding design flaws early improves considerably. Finding design flaws early in the design process greatly reduces the cost of fixing those flaws flaws. Structured design methods also improve the ability to modify programs at a later date since the techniques make the production of clear and complete documentation much easier. Structured designs can also be more easily broken up into modules to improve testing and to allow development by multiple design teams with a reasonable assurance that the resulting products will be compatible with each other.

Basic Blocks
A terminator marks the beginning or end of the flowchart. A process symbol indicates an operation that changes or manipulates data in some way (e.g., arithmetic, move, or copy). A data symbol (a parallelogram) indicates an operation that inputs or outputs data data. A diamond indicates a decision. A connector (a small circle) means that the logic is continued at another place on the same page. An off page connector (home plate) indicates that the logic is continued on another page off-page page. A rectangle within a rectangle indicates a predefined process (or subroutine).

subroutine

Program Execution Structures


Structured design using flowcharts generally involves a topdown analysis of the problem to be solved. Program logic can be expressed as combinations of four basic patterns: sequence, decision (branch), repetition and subroutine. A program is composed of combinations of these basic structures.

The Sequence Structure implies that the logic is executed in simple sequence, one block after another. Note that each block might represent one or more actual instructions.

In a Decision/ Branch Structure, a condition is tested. If the condition is true, the logic associated with the THEN branch is executed and the ELSE block is skipped. If the condition is false the ELSE logic is executed and the THEN logic is skipped. Note that the THEN and ELSE blocks might represent one or more actual instructions. Note also that a given THEN or ELSE block might incorporate an additional decision block, yielding nested decision logic.

There are two basic patterns for showing repetitive/loop structure. In a DO WHILE block, the test is performed first and the associated instructions are performed only if (while) the test condition is true true. In a DO UNTIL block, the associated instructions are executed first and then the exit condition is tested. Note that the logic block associated with a DO WHILE or DO UNTIL might represent one or more actual instructions.

A subroutine structure functions as a self-contained block of code. However, it is embedded in a large block , g of code and must interact with the calling program. A flowchart for a routine calls another subroutine that perform another operations that the detailed logic is flowcharted elsewhere. In effect, using predefined processes allows the designer to decompose the logic.

Example

Anda mungkin juga menyukai