Sie sind auf Seite 1von 43

Assembly Language Instructions

& Programming
PART 1
INR R

• INR R – Increment the specified register by 1.


– R←R+1
– R can be any of the general purpose registers (A, B,
C, D, E, H, L).
– Affects all the flags except CY.
– Register Addressing Mode.
– 1-byte instruction and takes 1 Machine Cycle for
execution.
– E.g. INR B, INR A.
– Amounts to 7 different Opcodes.
DCR R

• DCR R – Decrement the specified register by


1.
– R←R-1
– R can be any of the general purpose registers (A, B,
C, D, E, H, L).
– Affects all the flags except CY.
– Register Addressing Mode.
– 1-byte instruction and takes 1 Machine Cycle for
execution.
– E.g. DCR C, DCR H.
– Amounts to 7 different Opcodes.
INR M

• INR M – Increment the content of


memory (location specified by HL
Pair) by 1.
– ((HL)) ← ((HL)) + 1
– Affects all the flags except CY.
– Indirect Addressing Mode.
– 1-byte instruction
– Takes 3 Machine Cycles (Fetch, Read and
Write) for execution.
DCR M

• DCR M – Decrement the indirect byte


by 1 (memory location specified by HL
Pair).
– ((HL)) ← ((HL)) – 1
– Affects all the flags except CY.
– Indirect Addressing Mode.
– 1-byte instruction
– Takes 3 Machine Cycles (Fetch, Read and
Write) for execution.
INX & DCX

• INX RP – Increment the specified register pair by 1.


– RP ← RP + 1
• DCX RP – Decrement the specified register pair by 1.
– RP ← RP - 1

– RP can be any of the register pairs (HL, DE, BC, SP).


– Does not affect any of the flags.
– 1-byte instruction & 1 Machine Cycle (6 T-States).
– E.g. INX H, DCX SP.
JMP Instruction

• JMP – Jump (Go) to an instruction to


execute.
E.g. JMP LABEL
• This instruction is used to change the execution
sequence.
• LABEL is a symbol placed before instruction
where processor has to jump.
• E.g. JMP HERE
• Next is a simple example for understanding
JMP
JMP (Contd.)

• Example of JMP
• Symbol HERE is
:
address where the
MOV A, B
instruction INR A is
JMP HERE
stored in memory.
LDA 2500H • Execution of JMP
DCR B HERE, skips the
HERE: INR A execution of LDA &
MOV B, A DCR in program.

:
JMP (Contd.)

• JMP ADDRESS – Jump (Go) to


ADDRESS to execute an instruction.
• ADDRESS is actually the memory address
where instruction INR A (Last Slide) is stored
in memory.
• E.g. JMP 5000H
• PCH ← 50H and PCL ← 00H, finally PC=5000H,
showing address of instruction to be executed.
• It takes 3 Machine Cycles for execution.
• Execution of JMP is shown next.
Conditional JMPs

• JZ – Jump (Go) to instruction to execute


if ZF=1.
E.g. JZ ADDRESS (Memory Address)
• Executes similar to JMP but checks ZF before jump. If
ZF=1 then jump otherwise don’t jump.
• JNZ– Jump (Go) to instruction to execute
if ZF=0.
E.g. JNZ ADDRESS (Memory Address)
• Executes similar to JZ but checks for ZF=0 before
jump. If ZF=0 then jump otherwise don’t jump.
Conditional JMPs (Contd.)

• Example of JZ
• DCR A sets ZF=1.
MVI A, 01
• So JZ HERE makes a
DCR A
jump.
JZ HERE • Execution of JZ
STAX D HERE, skips the
DCR B execution of STAX &
HERE: INR D DCR in program.
MOV C, A
:
Conditional JMPs (Contd.)

• Example of JZ
• INR A, sets ZF=0.
MVI A, 01
• So, JZ HERE does
INR A
not make a jump.
JZ HERE • Hence, STAX D and
STAX D DCR B is executed
DCR B next and so on.
HERE: INR D
MOV C, A
:
Conditional JMPs (Contd.)

– JPE Jump on EVEN Parity


or Jump if Parity is SET
i.e. Jump on PF = 1.
– JPO Jump on ODD Parity
or Jump if Parity is NOT SET
i.e. Jump on PF = 0.
– JM Jump if Result is Minus (Negative)
i.e. Jump on SF = 1.
– JP Jump if Result is Positive
i.e. Jump on SF = 0
Conditional JMPs (Contd.)

– JC Jump if a Carry Generated


i.e. Jump on CF = 1.
– JNC Jump if Carry Not Generated
i.e. Jump on CF = 0.
A Simple Program (P6)

A data table containing 10 elements is


stored at memory location 2050H.
Write an 8085 ALP that will store 00 at
all the data positions.
Data Table (Program P6)
Physical Data SYMBOL
Address
Base Address of TABLE 2050H XX TABLE
2051H XX
2052H XX
2053H XX
2054H XX
2055H XX
2056H XX
2057H XX
2058H XX
2059H XX
Program P6 (Contd.)

HL ← Base Address of TABLE


C ← Data Count (0AH)
A ← 00, Data to store

Store data into TABLE


i.e. ((HL)) ← A

Increment Memory Pointer


i.e. HL ← HL +1

Decrement the data counter


i.e. C ← C - 1

All Data Y
STOP
N Cleared?
Program P6 (Contd.)

START: LXI H, TABLE ; Initialize Memory


Pointer.
MVI C, COUNT ; Init. Data Counter (0AH).
MVI A, 00 ; Clear Accumulator.
AGAIN: MOV M, A ; Clear memory using Acc.
INX H ; Point to Next Data
DCR C ; Decrement Count by 1
JNZ AGAIN ; All Data cleared?
; ‘NO’, Go back to clear again
HLT ; ‘YES’, STOP
Alternate Program P6 (Contd.)

START: LXI H, TABLE ; Initialize Memory Ptr.


MVI C, COUNT ; Init. Data Counter (0A)
AGAIN: MVI M, 00 ; Clear memory.
INX H ; Point to Next Data
DCR C ; Decrement Count by 1
JNZ AGAIN ; All Data cleared?
; ‘NO’, Go back to clear again
HLT ; ‘YES’, STOP
A Different Organization of Data Table
• First Location tells how Address Data Comments
many data are there in 2600 0AH DATA COUNT
the given table.
2601 XX
• Program should use this
2602 XX
fact as the data starts
from next location. 2603 XX
• Write program to 2604 XX
clear this table. 2605 XX
2606 XX
2607 XX
2608 XX
2609 XX
260A XX
Program P6 (Contd.)
HL ← Base Address of TABLE
A ← 00, Data to store

Store count into C


i.e. C ← ((HL))

Increment Memory Pointer


i.e. HL ← HL +1

Store data into TABLE


i.e. ((HL)) ← A

Decrement the data counter


i.e. C ← C - 1

All Data Y
STOP
N Cleared?
Alternate Program P6 (Contd.)

START: LXI H, TABLE ; Initialize Memory Pointer.


MVI A, 00 ; Clear Accumulator.
MOV C, M ; Init. Data Counter (0AH).
AGAIN: INX H ; Point to Next Data
location.
MOV M, A ; Clear memory using Acc.
DCR C ; Decrement Count by 1
JNZ AGAIN ; All Data cleared?
; ‘NO’, Go back to clear again
HLT ; ‘YES’, STOP
Program (P7)
A data table containing 10 data items,
named TABLE1, is stored in memory.
Write an 8085 ALP to copy data from
TABLE1 to another table, namely
TABLE2 memory.
Data Table (P7)
Address Data Comments
Base Address of TABLE1 2400 91H DATA1
2401 28H DATA2
: : :
: : :
2409 44H DATA10
: : :
: : :
Base Address of TABLE2 2450 XX DATA1
: : :
2459 XX DATA10
Program P7 (Contd.)
HL ← Base Address of TABLE1
DE ← Base Address of TABLE2
C ← Data Count (0AH)

Get data from TABLE1


i.e. A ← ((HL))

Store data into TABLE2


i.e. ((DE)) ← A

Increment Memory Pointers


i.e. HL ← HL +1
DE ← DE + 1

Decrement the data counter

All Data Y
STOP
N Copied?
Program P7 (Contd.)

START: LXI H, TABLE1 ; Initialize TABLE1 Pointer.


LXI D, TABLE2 ; Initialize TABLE2 Pointer.
MVI C, 0AH ; Initialize Data Counter.
AGAIN: MOV A, M ; Get TABLE1 Data.
STAX D ; Store at TABLE2.
INX H ; Point to Next Data location.
INX D
DCR C ; Decrement Count by 1.
JNZ AGAIN ; All Data copied?
; ‘NO’, Go back to copy again
HLT ; ‘YES’, STOP
Program (P8)
Two data tables containing 10 data
items, named TABLE1 and TABLE2, are
stored in memory. Write an 8085 ALP to
exchange the data of two tables.
Data Table (P8)
Address Data Comments
Base Address of TABLE1 2400 91H DATA1
2401 28H DATA2
: : :
: : :
2409 44H DATA10
: : :
: : :
Base Address of TABLE2 2450 20H DATA1
: : :
2459 6AH DATA10
Program P8 (Contd.)
START: LXI H, TABLE1 ; Initialize TABLE1 Pointer.
LXI D, TABLE2 ; Initialize TABLE2 Pointer.
MVI C, 0AH ; Initialize Data Counter.
AGAIN: MOV B, M ; TABLE1 Data in B.
LDAX D ; TABLE2 Data in A.
MOV M, A ; Store TABLE2 Data at TABLE1.
MOV A, B ; TABLE1 Data in A.
STAX D ; Store TABLE1 Data at TABLE2.
INX H ; Point to Next Data location.
INX D
DCR C ; Decrement Count by 1.
JNZ AGAIN ; All Data copied?
; ‘NO’, Go back to copy again
HLT ; ‘YES’, STOP
Alternate Program P8
START: LXI H, TABLE1 ; Initialize TABLE1 Pointer.
LXI D, TABLE2 ; Initialize TABLE2 Pointer.
MVI C, 0AH ; Initialize Data Counter.
AGAIN: MOV B, M ; TABLE1 Data in B.
LDAX D ; TABLE2 Data in A.
XCGH ; Exchange the pointers.
MOV M, B ; TABLE1 Data at TABLE2.
STAX D ; Store TABLE2 Data at TABLE1.
XCHG ; Restore the pointers
INX H ; Point to Next Data location.
INX D
DCR C ; Decrement Count by 1.
JNZ AGAIN ; All Data copied? ‘NO’, Go back.
HLT ; ‘YES’, STOP
ADDITIONs

• ADD R – Add specified register to Accumulator.


– A←A+R
– Affects all the flags.
– R can be any of the general purpose registers (A, B,
C, D, E, H, L).
– e.g. ADD B A←A+B

• ADD M – Add indirect byte to Accumulator.


– A ← A + ((HL))
– Affects all the flags.
– Takes 2 Machine Cycles to execute
ADDITION with CARRY

• ADC R – Add specified register to Accumulator


along with carry.
– A ← A + R + CY
– Affects all the flags.
– R can be any of the general purpose registers.
– e.g. ADC B A ← A + B + CY

• ADC M – Add indirect byte to Accumulator along


with carry
– A ← A + ((HL)) + CY
– Affects all the flags.
– Takes 2 Machine Cycles to execute
Immediate ADDITIONs

• ADI DATA8 – Add immediate byte to


Accumulator.
– A ← A + DATA8
– Affects all the flags.
– e.g. ADI 80H A ← A + 80H

• ACI DATA8 – Add immediate byte to Accumulator


along with carry
– A ← A + DATA8 + CY
– Affects all the flags.

• Both are 2-byte instructions and take 2 Machine


Cycles to execute.
Subtractions (Contd.)

• SUB R
– A←A-R
– A ← A + 2’s Comp (R)
– Affects All the conditional flags.

• SBB R
– A ← A - R – CY
– A ← A + 2’s Comp (R) + 2’s Comp(CY)
– Affects All the conditional flags.
• SUB M
– A ← A – ((HL))
– Affects All the conditional flags.
Subtractions (Contd.)

• SBB M
– A ← A – ((HL)) - CY
– Affects All the conditional flags.

• SUI DATA8
– A ← A – DATA8
– Affects All the conditional flags.

• SBI DATA8
– A ← A – DATA8 - CY
– Affects All the conditional flags.
A Simple Program (P9)

Write an 8085 ALP to add two 8-bit


numbers and store result in memory.

MVI A, 25H ; Get DATA1 in A

MVI B, 30H ; Get DATA2 in B

ADD B ; Add the data

STA 2052H ; Store the result in memory.

HLT ; Stop
Alternate Programs (P9)

; Assuming data are stored in memory at


locations 2500H and 2501H.

LDA 2500H

MOV B, A ; Get DATA1 in B

LDA 2501H ; Get DATA2 in A

ADD B ; Add the data

STA 2502H ; Store the result in memory.

HLT ; Stop
Alternate Programs (P9) (Contd.)

; Assuming data are stored in memory at locations


2500H and 2501H.

LXI H, 2500H ; Pointer to first data in memory.

MOV A, M ; Get DATA1 in A.

INX H ; Increment pointer to DATA2.

ADD M ; Add DATA1 and DATA2.

INX H ; Increment pointer to store result.

MOV M, A ; Store the result in memory.

HLT ; Stop
Program (P10)
Write an 8085 ALP to add two 8-bit numbers and result may be
16-bit. Assuming data are stored in memory at locations 2500H
and 2501H.

MVI C, 00 ; Initialize Carry Counter


LDA 2500H
MOV B, A ; Get DATA1 in B.
LDA 2501H ; Get DATA2 in A.
ADD B ; Add DATA1 and DATA2.
JNC DN1 ; Is CY=0? ‘YES’ Go to DN1.
INR C ; ‘NO’ Increment carry counter by 1.
DN1: STA 2502H ; Store the low byte of result in memory.
MOV A, C ; Get high byte of result in in A.
STA 2503H ; Store the high byte of result in memory.
HLT ; Stop
Alternate Program (P10)
MVI C, 00 ; Initialize Carry counter.
LXI H, 2500H ; Pointer to first data in memory.
MOV A, M ; Get DATA1 in A.
INX H ; Increment pointer to DATA2.
ADD M ; Add DATA1 and DATA2.
JNC DN1 ; Is CY=0? ‘YES’ Go to DN1.
INR C ; ‘NO’ Increment carry counter by 1.
DN1: INX H ; Increment Ptr to store low byte of result.
MOV M, A ; Store the low byte of result in memory.
INX H ; Increment Ptr to store high byte of result
MOV M, C ; Store the high byte of result in memory.
HLT ; Stop
Program (P11)
A data series of Address Data Comments
integers is stored in 2500 09H ELEMENT
COUNT
memory, as shown.
2501 10H ELEMENT 1
Write an 8085 ALP that
will add all the 2502 19H ELEMENT 2
elements of this series 2503 25H
and store the result in 2504 01H
memory. Result may 2505 E1H
be 16-bit. 2506 11H
2507 06H
2508 00H
2509 F0H ELEMENT 9
Program (P11) (Contd.)
LXI H, 2500H ; Pointer to data series.
MOV B, M ; Get Element Count in B.
MVI C, 00 ; Initialize Carry counter.
MVI A, 00 ; Initial Sum=00 in A
NEXT: INX H ; Pointer to next data in series.
ADD M ; Add next element to previous sum.
JNC DN1; Is CY=0? ‘YES’ Go to DN1.
INR C ; ‘NO’ Increment carry counter by 1.
DN1: DCR B ; Decrement Element Counter.
JNZ NEXT ; All elements added? ‘NO’ Go back.
; ‘YES’ Store the result …..contd.
Program (P11) (Contd.)

INX H ; Pointer to store low byte of result.


MOV M, A; Store the low byte of result.
INX H ; Pointer to store high byte of result.
MOV M, C ; Store the high byte of result.
HLT ; Stop

Das könnte Ihnen auch gefallen