Showing posts with label instructions. Show all posts
Showing posts with label instructions. Show all posts

Branchng Group Instruction , 8085 programming



)Branching, 
The branching instructions alter normal sequential program flow, either unconditionally or conditionally. The unconditional branching instructions are as follows:

JMP Jump
CALL Call
RET Return

Conditional branching instructions examine the status of one of four condition flags to determine whether the specified branch is to be executed. The conditions that may be specified are as follows:

NZ Not Zero (Z = 0)
Z Zero (Z = 1)
NC No Carry (C = 0)
C Carry (C = 1)
PO Parity Odd (P = 0)
PE Parity Even (P = 1)
P Plus (S = 0)
M Minus (S = 1)

Thus, the conditional branching instructions are specified as follows:

Jumps Calls Returns
C CC RC (Carry)
INC CNC RNC (No Carry)
JZ CZ RZ (Zero)
JNZ CNZ RNZ (Not Zero)
JP CP RP (Plus)
JM CM RM (Minus)
JPE CPE RPE (Parity Even)
JP0 CPO RPO (Parity Odd)

Two other instructions can affect a branch by replacing the contents or the program counter:

PCHL Move H & L to Program Counter
RST Special Restart Instruction Used
with Interrupts

Stack I/O, and Machine Control Instructions:
The following instructions affect the Stack and/or Stack Pointer:

PUSH Push Two bytes of Data onto the Stack
POP Pop Two Bytes of Data off the Stack
XTHL Exchange Top of Stack with H & L
SPHL Move content of H & L to Stack Pointer

The I/0 instructions are as follows:

IN Initiate Input Operation
OUT Initiate Output Operation

The Machine Control instructions are as follows:
EI Enable Interrupt System
DI Disable Interrupt System
HLT Halt
NOP No Operations
e) Miscellaneous
i)  STACK
the stack is defined as a set of memory location in R/W memory specified by a program in main memory these main memory are used to store binary information temporarily during execution of the  program. The beginning of the stack in the  program by usin g the  instructin LXI SP,!6 bit address.
Once the stackj  location has been defined it loads the 16 bit address in the stack pointer register.
Some left
ii) Push RP/PSW
·         Store content of register pair in the stack
·         1 byte instruction
·         Copies the content of specified register pair or program status word i.e. PSW, accumulator and flag an the stagment
·         Stack pointer is increment and the content of higher order register is copied .Then it is again decremented and content of lower order is copied. 
iii) POP RP/PSW
retrieve register Pair from stack
1 byte instruction register pair or program status word
Lapes the content of the top to memory locations on the stack into specified register pair or program status word.
 Content of memory location indicated by the SP is copied into low order register and sp is incremented by 1figure ok …………….
Then the content of memory locationspecified by sp is copied into high order register and sp is incremented by one .


Arithmetic Group Instruction , 8085 programming



    b)Arithmetic, 
The microprocessor is performed arithmetic operations like addition subtraction ,increment and decrement . these arthmetc operations have the following mnemonics..
ADD Add to Accumulator
ADI Add Immediate Data to Accumulator
ADC Add to Accumulator Using Carry Flag
ACI Add Immediate data to Accumulator Using Carry
SUB Subtract from Accumulator
SUI Subtract Immediate Data from Accumulator
SBB Subtract from Accumulator Using Borrow (Carry) Flag
SBI Subtract Immediate from Accumulator Using Borrow (Carry) Flag
INR Increment Specified Byte by One
DCR Decrement Specified Byte by One
INX Increment Register Pair by One
DCX Decrement Register Pair by One
DAD Double Register Add; Add Content of Register    b)Arithmetic, 
The microprocessor is performed arithmetic operations like addition subtraction ,increment and decrement . these arthmetc operations have the following mnemonics..
ADD R/M
a)      ADD R
·         1 byte add instruction
·         add the content of accumulator to the content of specified register/memory and stores the result in the accumulator
·         e.g. ADD  B; A   ß  [A]+[B]
let us take a example :
MVI   A,20h    ;Stores 20h data in Accumulator
MVI   B,30h     ;Stores 30h in register B
ADD  B            ;Adds the content of a  Accumulator with content of B register
HLT
The program adds the data 20h and 30h and stores in the Accumulator.
Output
A:50     B:30

b)      ADD M

Adds the data of the memory location pointed by the HL pair with the Accumulator and stores the result in the Accumulator.[A]ß[A] + [[M]]
Lets see an example:
          LXI   H,2040h  ;Loads 2040h in HL pair i.e H:20h L:20h
          MVI  M,60h      ;moves 60h to memory location pointed by Hl pair
          MVI  A,30        ;moves immediate data 20h in Accumulator
          ADD  M            ;adds the data of memory location 2040  i.e 60h with data in Acc.
          HLT
         
ADI

·         BYTE add immediate instruction
·         add the 8-bit data with the content of the accumulator AND stores the result in accumulator. [A]ß
·         eg ADI 54 H . [A]ß[A]+54
·          
SUB R/M
·         1 byte subtract instruction.
·         add the content of accumulator to the content of specified register/memory and stores the result in the accumulator
·         SUB A;
SUI 8 bit data
·         byte subtract immediate instruction
·         Subtract  the 8-bit data with the content of the accumulOR AND stores the result in accumulator.
·         SUI 62H;
INR  R/M
DCR  R/M
-          1 byte Increment decrement  instruction
-          Increment and decrement of the content of the specified register  and memory
-          DCR B;
-          DCR M;
-          INR A;
-          INR M;

INX  Rp
DCX  Rp
-          Byte increment decrement register pair
-          Increment and decrement the content of the register pair by 1.
-          Act as 16 counter made from the content of register pair.
Eg INX  B;
DCX  D;

ADC  R/M (addition with carry -1 byte instruction)
ACI 8 bit data (immediate addition with carry -2 byte)
Adds the content of the register /memory 8 bit data  whatever used with the content of accumulator. And with the previous carry and stores result back to the accumulator.

SBB R/m(Subtraction with borrow/1 byte instruction)
          SBI 8 bit (immediate subtraction with borrow – 2 byte instruction )
Subtracts the content of register or 8 bit data from the content of accumulator taking previous borrow as count.




DAD Rp

-1 byte adition instruction
-add register  pair (B or D or H) with H pair and stores 16 bit result in H pair.


DAA
1 byte Decimal adjustment Accumulator
Used only the addition
The content of accumulator after addition is changed from binary (Hex) to two 4 bits BCD (Binary Coded Decimal) digits

1)      The arithmetic operations  add and subtract are  performed in relation to the content  of accumulator  the features of these  instruction are they assume implicitly that the accumulator is one of operand;
2)      They modify all the flag according to the data conditions of all the result.
3)      they  place the result in accumulator
4)      They do not affect the content of operand register or memory
But the INR  & DCR operations can be performed in any register and memory.
The instruction INX and DCX do not affect the flag.

Data Transfer Group Instruction , microprocessor 8085



a) Data transfer Group

It is the group of instruction in 8085 .this group of instruction copy data from a source location to destination location without modifying content of the source. The transfer of data may b e  between the register or between  the register  memory and memo rot vice versa or between te I/O device and accumulator . None of the instruction change the content flag .the instruction are as follows:.
MOV Move
MVI Move Immediate
LDA Load Accumulator Directly from Memory
LXI Load Register Pair with Immediate data
LDAX Load Accumulator from Address in Register Pair
STA Store Accumulator Directly in Memory
STAX Store Accumulator in Address in Register Pair
LHLD Load H & L Registers Directly from Memory
SHLD Store H & L Registers Directly in Memory
XCHG Exchange H & L with D & E
XTHL Exchange Top of Stack with H & L
a) Data transfer Group
Something you must know before going into it
We have studied about the register their pair in previous chapter, microprocessor architecture I will denote R for the register signally and register pair as Rp. Some revision here , that the registers can be used alone or as a pair so some instruction take register pair([BC][DE][HL])as their operand whereas other take only register( B C D E H L ) as their operand.

Also the concept of bits
          ‘0101’ count the no of 1’s and 0’s you will get the no. four so hat is four bits representation.
          ‘01010000’ no. of 1,s and 0 is 8 so it is 8 bit representation.
8 bits = 1 byte
16 bits =2 bytes

Let’s take 3040h, it’s a hex data and the binary of it is 0111 0000 so, it’s a 8 bit data
8085 assembler converts the 3040 to 8 bit binary value and give to microprocessor.
MOV Move
MVI Move Immediate
LDA Load Accumulator Directly from Memory
LXI Load Register Pair with Immediate data
LDAX Load Accumulator from Address in Register Pair
STA Store Accumulator Directly in Memory
STAX Store Accumulator in Address in Register Pair
LHLD Load H & L Registers Directly from Memory
SHLD Store H & L Registers Directly in Memory
XCHG Exchange H & L with D & E
XTHL Exchange Top of Stack with H & L
1)      MOV (Move)

a)      MOV move register instruction.
·         MOV Rd, Rs                
·         1 byte instruction
·         Carries data from source register (Rs) to another destination register (Rd).
·         Rd and Rs may be A,B,C D,E ,H,L.
·         Eg: MOV   H,A
                  Here ,The content of accumulator is transferred to H register.
                       If Accumulator contain data 20h than program below output as.
                         MOV   H, A
                           HLT             
                                  output
                                   A:20
                                   B: 00          C: J J
                                   D: 00           E: 00
                                   H:20            L:00
b)      Move to  memory from register
·         MOV M,Rs
·         Move the content of the specified register to the memory .Here memory is the location specified by content Of the HL pair registers.
Here we will study actually what M is .
Let [HL] pair contain data 2030 ,then the location 2030 is called as  memory(M) and let  B contains data 40h.If we have the instruction:

 MOV   M,B

Than 2030 location is filled by data in register B and it is summarized as output as:

Output
B: 20h
[2030]:20h

c)      Move to register from memory
·         MOV R,M
·         1 byte instruction
·         Moves the content of the memory location specified by HL pair to specified by HL pair to the specified by HL pair to specified register.
For Example : IF [HL] pair contain data 5060h then instruction MOV D,M transfer the data containing in address 5060  to the register D.


2)      MVI (Move immediate) 

·         MVI R,8 bit data
·         Loads the 8 bits data into the specified register
·         R may be A,B,C,D,E,H ,L
·         Eg: MVI B,20h

In this example the content of register C is moved to B and data in C will also be unchanged.
 If C has data 20h than 20h will be moved to register B.

·          MVI M,8 bit data

3)       LXI ( Load registers pair directly)
·         LXI Rp,2 bytes data
·         byte instruction
·         load immediate 16 bit data to the register pair
·         Rp may be B(BC),D(DE),H(HL),& SP

1st byte op code
2nd byte lower order data
3rd byte higher order data


4)      MVI (Load memory immediately)
a)      MVI  Rd,8 bit data to the
·         Loads the 8 bit data to the register
·         E.g. MVI B,20h
In this example 20h data is loaded  to register B.
Output
B: 20h
b)      MVI M,8 bit data
·         byte instruction
·         loads the 8-bit data to the memory location whose address is specified by the content of the HL pair

                 Eg. MVI M,35H; [HL] ß35 H
In this example 35h is stored in the location specified by the data in register pair HL
If the content of register pair [HL] was 2020 then 35h is stored in memory location 2020
Here
5)      LDA Load accumulator direct
·         LDA 16 bit address
·         2 byte instruction
·         loads the accumulator with the content of memory location whose address is specified by
·         the 16 bit address
·         Eg.LDA 4035;Aß[4035]
In this example the data from the address 4030 will be loaded to the Accumulator.
·         Eg.LDA 4035;Aß[4124]
In this example the data from the address 4124 will be loaded to the Accumulator.
Let’s solve a question
Write program to load the data
6)      LDAX (Load accumulator indirect )
·         LDAX  Rp
·         1 byte instruction
·         Moves the content of the memory location pointed by the content of the register pair to  accumulator
LXI
·         E.g LDAX B; Aß[BC]
Let [BC] pair contains 2020, then the instruction ‘LDAX B ‘ stores the data containing in address pointed by register B(i.e. 2020)
7)      STA (Store accumulator content direct)
·         STA 16 bit address
·         2 byte instruction
·         Stores the content of accumulator to specified address
·         Eg STA FA00,[FA00]ßA;
 In this example the content of accumulator is stored in the address FA00.m

Let’s do a program
MVI   A,20h
STA   5050h
HLT
Here, ‘MVI A, 20h’ stores the 20h in accumulator, and STA stores the content of accumulator to to 5050.

OUTPUT
A:20
           [5050]:20
                  
8)      Store accumulator content indirect
·         STAX Rp;
·         1 byte instruction