Lecture 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Introduction to programming

- A microprocessor can be considered as a device that reads binary-coded


information from its input, manipulates this information according to a
program stored within its memory, and subsequently produces information at
its output. This process is shown in Figure 1.

MICROCOMPUTER

Binary Binary
Stored
input output
Program

Figure 1

- The program instructions/manipulation process could affect the internal


registers and/or memory locations.
- Some of the registers are accessible by the machine instructions. These are
called visible registers.
- The non-visible register is the one where the processor cannot access it
directly.

Assembly Language:

- An assembly language is a low-level programming language designed for a


processor. It may be produced by compiling source code from a high-level
programming language (such as C++).
- Assembly code can be converted to machine code using an assembler.
- Assembly often include instructions and operators.
- The microprocessor understands the binary representation which means the
form of 0 and 1.
- The programmer writes a program in a convenient representation of machine
instruction, such that each instruction has its own representation in words.
- This representation is called assembly language.
- The programmer programs a processor using assembly language then, it is
converted to the binary representation to be understandable by the machine.

1
- The translator that converts the assembly language to machine code is called
assembler.

Source Object
Assembler
Code code
(Assembly (Machine)
)

- Each instruction in the program is called mnemonic


- The operation mnemonic is a simple word that reflects the action involved.

MOV - move data from one location to another


ADD - add two values
SUB - subtract a value from another value
PUSH - push data onto a stack
POP - pop data from a stack
JMP - jump to another location
INT - interrupt a process

- The operands are the registers or memory locations that are used to perform
this operation.
- Some mnemonics are called directives, which provide the computer with
important data.
- To understand how to write a program, we should know first the instruction
types that can be used in the processor.

- Example:

MOV A, B

ADD B

Instruction Types

- In microprocessor we have large number of machine instructions. These


instructions can be generally classified to five groups as follows:

2
1. Data Transfer
2. Data Manipulation
3. Transfer of control
4. Input/output
5. Machine control

• Data Transfer: moves the data between registers or between register and
memory location.

Example:
MOV A,B

This instruction will move the content of B-register to A-register.


The move here means copy.

• Data Manipulation: performs the arithmetic or logical operations on data


stored in a register or memory location.

Example:
ADD B

This instruction modifies the content of the A-register (accumulator) to the


sum of previous contents and the contents of B-register.

• Transfer of control: provides the capability and ability to transfer from one
sequence of operations to another, based on variety of conditions.

Example:
JMP Address/label

This instruction is unconditional branch to the memory location written in


operand

3
• Input/Output: moves the data between the registers and I/O ports

Example:
OUT 5H

The contents of A-register will be moved to output port #5

• Machine control: affects the state or mode of operation of the processor


itself.

Example:
NOP

This causes the machine to wait through an instruction.

- Also, each of this group is classified depending on the types of the source and
destination address.
- These sub-classifications called addressing mode.

Operand Addressing Mode

- Data manipulation instruction implies access as many as three locations:

o Two for values to be manipulated ( i.e. sources)


o One to specify the destination for the result

Source 1

Operation Destination
Source 2

- Most microprocessor including 8085 only requires a maximum of two


addresses to be specified.
- The type of the source or destination is determined by the instruction type
which is called the addressing mode.

4
- Each microprocessor could provide several addressing modes.
- The main four types are:

1. Register addressing Used for data transfer and manipulation


2. Immediate addressing that use only internal registers

3. Direct addressing Used for data transfer and manipulation


4. Indirect addressing that uses the system memory & registers

- Other addressing modes used in some microprocessors like index addressing;


this type is the same as the third and fourth type in addition of a shift used.
- When several addressing modes are used more instruction will be available to
program which let the programming faster and easier.

Data Transfer Instructions


- Data Transfer instructions move data from one location to another.
- The heart of each of the data transfer instruction is the definition of the
locations where the source and destination bytes are to be found.

1. Register Addressing
- This kind of addressing moves data between internal registers.
- The order of the operands defines which register is the source and which is
the destination.

a) 8-bit Data Transfer:


MOV R1, R2
(R1) ← (R2)

Operation: MOV
Operands: R2 (source)
R1 (Destination)
Function: moves the contents of R2 to R1

Example:
MOV C, B
(C) ← (B)

moves the contents of B-register to C-register

5
b) 16-bit Data Transfer:

XCHG
(HL) ↔ (DE)

Operation: XCHG
Operands: No operands
Function: moves 16-bit address length transfer between two register pairs
(DE, HL).
(H) ↔ (D)
(L) ↔ (E)

Example: Assume that (HL)= 71D3 , (DE)=A071

XCHG

D A0 71 71 D3 E
H 71 A0 D3 71 L

You might also like