ASSEMBLY LANGUAGE. Upon completing this topic, you should be able to: Classify the 8085A...

Preview:

Citation preview

ASSEMBLY LANGUAGE

Upon completing this topic, you should be able to:• Classify the 8085A microprocessor

instructions• Explain the basic function of common use

instruction.• Write simple program using assembly

language

Assembly language is used to program microprocessor.

Assembly language instructions can be classified into 5 distinct operational categories:a. Data transfer (copy) operationsb. Arithmetic operationsc. Logical operationsd. Branching operationse. Stack, I/O and machine control operations

Data transfer instructions move (copy) :- Data between register

o MOV Destination, SourceoCopy data from source to destinationoDestination and source is register (A, B, C, D, E, H, L)oSize of moving data is 8 bit (1 byte)oExample: MOV B,A

oXCHGoExchange the contents of HL register with DE registeroThe contents of register H are exchanged with register D and

the contents of register L are exchanged with register EoExample: XCHG

Data transfer instructions move (copy) :- Data from accumulator to memory

oSTA AddressoData from Accumulator are copied into specific memory

location given by AddressoThe size of address is 16 – bit (2 byte)oExample: STA 3200H

oSTAX Register PairoData from Accumulator are copied into specific memory

location given by Register Pairo Indirect data transferoRegister pair( B = BC, D = DE)oExample: STAX B

Data transfer instructions move (copy) :- Data from memory to accumulator

oLDA AddressoData from specific memory location given by Address are

copied into AccumulatoroThe size of address is 16 – bit (2 byte)oExample: LDA 3200H

oLDAX Register PairoData from specific memory location given by Register Pair

are copied into Accumulatoro Indirect data transferoRegister pair( B = BC, D = DE)oExample: LDAX D

Data transfer instructions move (copy) :- Data from memory to register

oMOV Register, MoCopy data from memory(source) into register (destination)oThe memory location is specified by HL registeroRegister (A, B, C, D, E, H, L)oExample: MOV B, M

oLHLD Address (Load H and L register Direct)oData from memory location specified by Address is copied

into register LoData from memory location specified by Address + 1 is

copied into register HoThe size of address is 16 – bit (2 byte)oExample: SHLD 2000H

Data transfer instructions move (copy) :- Data from register to memory

oMOV M, RegisteroCopy data from register(source) into memory (destination)oThe memory location is specified by HL registeroRegister (A, B, C, D, E, H, L)oExample: MOV M,D

oSHLD Address (Store H and L register Direct)oData from register L is stored into memory location specified

by AddressoData from register H is stored into memory location specified

by Address + 1oThe size of address is 16 – bit (2 byte)oExample: LHLD 2000H

Arithmetic operations are perform by ALU and the result of operations will be stored in Accumulator (for instruction that involved Accumulator only).

All arithmetic instructions (except INX, DCX) will alter the Flag register.

Add immediate (constant) with accumulator ADI Constant (8 bit)

o [A] [A] + Constanto Constants ( any 8 bit number )o Decimal 0 – 255 ADI 200o Binary 00000000B – 11111111B ADI 11001000Bo Hexadecimal 00H – 0FFH ADI 0C8H

o If the result of operation produce carry, CY flag is seto S, P, AC, Z will reflect to the result of operation (content of A)

ACI Constant (8 bit)o [A] [A] + Constant + CYo Constants ( any 8 bit number )o Decimal 0 – 255 ACI 200o Binary 00000000B – 11111111B ACI 11001000Bo Hexadecimal 00H – 0FFH ACI 0C8H

o If the result of operation produce carry, CY flag is seto S, P, AC, Z will reflect to the result of operation (content of A)

Add register with accumulator ADD Register

o [A] [A] + [Register]oRegister (A, B, C, D, E, H, L)o If the result of operation produce carry, CY flag is setoS, P, AC, Z will reflect to the result of operation (content of A)oExample: ADD B

ADC Registero [A] [A] + [Register] + CYoRegister (A, B, C, D, E, H, L)o If the result of operation produce carry, CY flag is setoS, P, AC, Z will reflect to the result of operation (content of A)oExample: ADC B

Add memory content with accumulator ADD M

o [A] [A] + [M]oThe memory location is specified by HL registero If the result of operation produce carry, CY flag is setoS, P, AC, Z will reflect to the result of operation (content of A)oExample: ADD M

ADC Mo [A] [A] + [M] + CYoThe memory location is specified by HL registero If the result of operation produce carry, CY flag is setoS, P, AC, Z will reflect to the result of operation (content of A)oExample: ADC M

Subtract immediate (constant) from accumulator SUI Constant (8 bit)

o [A] [A] - Constanto Constants ( any 8 bit number )o Decimal 0 – 255 SUI 200o Binary 00000000B – 11111111B SUI 11001000Bo Hexadecimal 00H – 0FFH SUI 0C8H

o If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)

SBI Constant (8 bit)o [A] [A] - Constant - CYo Constants ( any 8 bit number )o Decimal 0 – 255 SBI 200o Binary 00000000B – 11111111B SBI 11001000Bo Hexadecimal 00H – 0FFH SBI 0C8H

o If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)

Subtract register from accumulator SUB Register

o [A] [A] - [Register]o Register (A, B, C, D, E, H, L)o If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)o Example: SUB B

SBB Registero [A] [A] - [Register] - CYo Register (A, B, C, D, E, H, L)o If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)o Example: SBB B

Subtract memory content from accumulator SUB M

o [A] [A] - [M]o The memory location is specified by HL registero If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)o Example: SUB M

SBB Mo [A] [A] - [M] - CYo The memory location is specified by HL registero If the result of operation required borrow, CY flag is seto If CY = 1, the content of Acc is in 2’s complement form (Negative

Number)o S, P, AC, Z will reflect to the result of operation (content of A)o Example: SBB M

Increment register by 1 INR Register

o [Register] [Register] + 1oRegister (A, B, C, D, E, H, L)oS, P, AC, Z will reflect to the result of operation (content of

Register)oCY flag will remainsoExample: INR B

INX Register Pair (Rp)o [Rp] [Rp] + 1oRegister pair( B = BC, D = DE, H = HL, SP)oNo flags are affectedoExample: INX B

Increment memory content by 1INR M

o [M] [M] + 1oThe memory location is specified by HL registeroS, P, AC, Z will reflect to the result of operation (content of

Register)oCY flag will remainsoExample: INR M

Decrement register by 1 DCR Register

o [Register] [Register] - 1oRegister (A, B, C, D, E, H, L)oS, P, AC, Z will reflect to the result of operation (content of

Register)oCY flag will remainsoExample: DCR B

DCX Register Pair (Rp)o [Rp] [Rp] - 1oRegister pair( B = BC, D = DE, H = HL, SP)oNo flags are affectedoExample: DCX B

Decrement memory content by 1DCR M

o [M] [M] - 1oThe memory location is specified by HL registeroS, P, AC, Z will reflect to the result of operation (content of

Register)oCY flag will remainsoExample: DCR M

Other Arithmetic Instruction DAD Register Pair (Rp)

o [HL] [HL] + [Rp]oRegister pair( B = BC, D = DE)oS, P, AC, Z are not affectedoCY flag will set if results of operation is larger than 16 bitoExample: DCR B

DAAoConvert contents of Accumulator from binary value into two 4

digit BCD valueo If value of lower order 4-bits > 9, or AC = 1, then

[A] = [A] + 06Ho If value of high order 4-bits > 9, or CY = 1, then

[A] = [A] + 60HoS, P, Z, AC, CY flags are altered to reflect the result of

operationoExample: DAA

Logic operations are perform by ALU and most of the result of operations will be stored in Accumulator.

Most of the arithmetic instructions will alter the Flag register.

ANDing data with AccumulatorANI Constant (8 bit)

o [A] [A] ^ ConstantoConstants ( any 8 bit number )oDecimal 0 – 255 ANI 200oBinary 00000000B – 11111111B ANI 11001000BoHexadecimal 00H – 0FFH ANI 0C8H

oS, P, Z will reflect to the result of operation (content of A)oCY flag is Reset, AC is Set

ANA Registero [A] [A] ^ [Register]oRegister (A, B, C, D, E, H, L)oS, P, Z will reflect to the result of operation (content of A)oCY flag is Reset, AC is SetoExample: ANA B

ANDing data with AccumulatorANA M

o [A] [A] ^ [M]oThe memory location is specified by HL registeroS, P, Z will reflect to the result of operation (content of A)oCY flag is Reset, AC is SetoExample: ANA M

ORing data with AccumulatorORI Constant (8 bit)

o [A] [A] v ConstantoConstants ( any 8 bit number )oDecimal 0 – 255 ORI 200oBinary 00000000B – 11111111B ORI 11001000BoHexadecimal 00H – 0FFH ORI 0C8H

oS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are Reset

ORA Registero [A] [A] v [Register]oRegister (A, B, C, D, E, H, L)oS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are ResetoExample: ORA B

ORing data with AccumulatorORA M

o [A] [A] v [M]oThe memory location is specified by HL registeroS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are ResetoExample: ORA M

XORing data with AccumulatorXRI Constant (8 bit)

o [A] [A] ConstantoConstants ( any 8 bit number )oDecimal 0 – 255 XRI 200oBinary 00000000B – 11111111B XRI 11001000BoHexadecimal 00H – 0FFH XRI 0C8H

oS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are Reset

XRA Registero [A] [A] [Register]oRegister (A, B, C, D, E, H, L)oS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are ResetoExample: XRA B

XORing data with AccumulatorXRA M

o [A] [A] [M]oThe memory location is specified by HL registeroS, P, Z will reflect to the result of operation (content of A)oCY and AC flags are ResetoExample: XRA M

Compare data with AccumulatorCPI Constant (8 bit)

o [A] – Constant >>>>> Flag RegisteroConstants ( any 8 bit number )oDecimal 0 – 255 CPI 200oBinary 00000000B – 11111111B CPI 11001000BoHexadecimal 00H – 0FFH CPI 0C8H

o If [A] < Constant, then CY = 1, Z = 0o If [A] = Constant, then CY = 0, Z = 1o If [A] > Constant, then CY = 0, Z = 0oS, P, AC are affected by the result of subtraction

Compare data with AccumulatorCMP Register

o [A] - [Register] >>>>> Flag RegisteroRegister (A, B, C, D, E, H, L)o If [A] < [Register] , then CY = 1, Z = 0o If [A] = [Register] , then CY = 0, Z = 1o If [A] > [Register] , then CY = 0, Z = 0oS, P, AC are affected by the result of subtractionoExample: CMP B

Compare data with AccumulatorCMP M

o [A] - [M] >>>> Flag registeroThe memory location is specified by HL registero If [A] < [M] , then CY = 1, Z = 0o If [A] = [M] , then CY = 0, Z = 1o If [A] > [M] , then CY = 0, Z = 0oS, P, AC are affected by the result of subtractionoExample: CMP M

Rotate Accumulator Right 1 bitRRC Rotate Accumulator Right

o [A0] CY

o [A0] [A7]

o [An+1] [An]

oCY is modified according to A0

o S, P, Z, AC are not affected

Rotate Accumulator Right 1 bitRAR Rotate Accumulator Right through

Carryo [A0] CY

oCY [A7]

o [An+1] [An]

oCY is modified according to A0

o S, P, Z, AC are not affected

Rotate Accumulator Left 1 bitRLC Rotate Accumulator Left

o [A7] CY

o [A7] [A0]

o [An] [An+1]

oCY is modified according to A7

o S, P, Z, AC are not affected

Rotate Accumulator Left 1 bitRAL Rotate Accumulator Left through Carry

o [A7] CY

oCY [A0]

o [An] [An+1]

oCY is modified according to A7

o S, P, Z, AC are not affected

Complement AccumulatorCMA

o [A] = [A]oNo Flag are affected

Complement Carry FlagCMC

o CY= CYoOther Flag are not affected

Set Carry FlagSTC

o CY= 1oOther Flag are not affected

Branch operations allow the microprocessor to change a sequence of a program, either unconditionally or under certain test condition.

The branch instructions are classified into 3 categories:• Jump instruction• Call and Return instruction• Restart instruction

Jump instructionUnconditional Jump

o JMP Address (Label)o Jump to specific address location provided by Addresso The size of address is 16 – bit (2 byte)o [byte 3][byte 2] [PC]o Suitable for continuous loopo Example: JMP 3000H

JMP LOOP

Conditional Jumpo J Condition Address (Label)o Jump to specific address location provided by Address if the

condition is trueo The size of address is 16 – bit (2 byte)o [byte 3][byte 2] [PC]o The condition is base on the S, P, CY, Z

Jump instructionConditional Jump

Opcode

Description Condition

JNZ Jump if no Zero Z = 0

JZ Jump if Zero Z = 1

JNC Jump if no Carry C = 0

JC Jump if Carry C = 1

JP Jump if Positive S = 0

JM Jump if Minus S = 1

JPO Jump if Parity Odd P = 0

JPE Jump if Parity Even P = 1

Call and Return instruction• Subroutine is a group of instructions written

separately from the main program to perform function that occurs rapidly in the main program.

• To implement subroutine, 8085 provide two instructions:

1. CALL – Call a subroutine2. RET – Return from subroutine to main program

Call and Return instructionUnconditional Call and Return

oCALL Address of subroutine (Label)o Jump to specific address location provided by Address of

subroutineoThe size of address is 16 – bit (2 byte)o [PCH] [SP – 1]o [PCL] [SP – 2]oSP – 2 SPo [byte 3][byte 2] [PC]oExample: CALL 3000H

CALL DELAY

Call and Return instructionUnconditional Call and Return

oREToReturn to main programo [SP] [PCL]o [SP + 1] [PCH]oSP + 2 SPoExample: RET

Call and Return instructionConditional Call and Return

oC Condition Address of subroutine (Label)o Jump to specific address location provided by Address of

subroutine if specific condition is trueoThe size of address is 16 – bit (2 byte)o If (condition = true)o [PCH] [SP – 1]o [PCL] [SP – 2]oSP – 2 SPo [byte 3][byte 2] [PC]

Jump instructionConditional Call and Return

Opcode

Description Condition

CNZ Call on no Zero Z = 0

CZ Call on Zero Z = 1

CNC Call on no Carry C = 0

CC Call on Carry C = 1

CP Call on Positive S = 0

CM Call on Minus S = 1

CPO Call on Parity Odd P = 0

CPE Call on Parity Even P = 1

Call and Return instructionConditional Call and Return

oR ConditionoReturn to main program if specific condition is trueo If (condition = true)o [SP] [PCL]o [SP + 1] [PCH]oSP + 2 SP

Jump instructionConditional Call and Return

Opcode

Description Condition

RNZ Return on no Zero Z = 0

RZ Return on Zero Z = 1

RNC Return on no Carry C = 0

RC Return on Carry C = 1

RP Return on Positive S = 0

RM Return on Minus S = 1

RPO Return on Parity Odd P = 0

RPE Return on Parity Even P = 1

Restart instruction• Use to transfer program execution to one of

eight memory locations depending upon the number.

• Generally used in conjunction with interrupts and inserted using external hardware

• Can also be used in software.• Memory location can be calculated using the

following formula;Memory Location = n * 08H

• where n is a restart number

Restart instructionRST N

oN number of address locationsoNo Flag are affected

Other instructionPCHL

oCopy contents of register HL to Program Countero [H] [PCH]o [L] [PCL]

Instruction

Address

RST 0 00H

RST 1 08H

RST 2 10H

RST 3 18H

RST 4 20H

RST 5 28H

RST 6 30H

RST 7 38H

Stack can be described as a set of memory locations in the R/W memory specified by a programmer in the main program.

It used to store binary information temporarily during the execution of a program.

The beginning of stack is define in the program using

LXI SP, Stack Address Storing data bytes at the stack location is begin

at memory address that is one less than the address in the stack pointer and continue in reverse numerical order.

Therefore, the stack is initialized at the highest available memory location to prevent the program from being destroyed by the stack information.

Stack InstructionsPUSH Register Pair (Rp)

oStore register pair on StackoRegister pair( B = BC, D = DE, H = HL, PSW = A and Flag)o [RpL] [SP - 1]o [RpH] [SP - 2]oSP – 2 SPoExample: PUSH PSW

POP Register Pair (Rp)oRetrieve register pair from StackoRegister pair( B = BC, D = DE, H = HL, PSW = A and Flag)o [SP ] [RpH]o [SP + 1] [RpL]oSP + 2 SPoExample: POP PSW

I/O devices can be interfaced with the 8085 microprocessor either as peripheral I/O or memory-mapped I/O.

In the peripheral I/O, the instructions IN/OUT are used as data transfer, and the device is identified by an 8-bit address.

In memory-mapped I/O, memory related instructions are used for data transfer, and the device is identified by a 16-bit address

I/O InstructionsIN 8-bit port address

oThe contents of the input port specified by 8-bit port address is read and loaded into the Accumulator

oExample: IN 81H

OUT 8-bit port addressoTransfer data from the Accumulator to the output device

specified by 8-bit port addressoExample: OUT 80H

Machine Control InstructionsNOP

oNo operation is performedoUse to increase processing time or substitute in place of

an instructionoExample: NOP

HLToThe CPU finishes executing the current instruction and

halt any further executionoThe address and data bus are placed in high impedance

stateoNo register contents are affectedoReset or interrupt is necessary to exit from halt stateoExample: HLT

Machine Control InstructionsDI

oDisable InterruptoUse to disable all interruptoExample: DI

EIoEnable InterruptoUse to turn on all interrupt (Except mask interrupt)oExample: EI

Machine Control InstructionsSIM

oSet interrupt maskoUse to enable and disable maskable interruptoBit D7 is use to send serial data outoExample: SIM

RIMoRead Interrupt maskoUse to read current status of maskable interruptoBit D7 is use to read serial data inoExample: RIM

Recommended