UNDERSTANDING ASSEMBLY LANGUAGE Instruction A microprocessor executes instructions

UNDERSTANDING ASSEMBLY LANGUAGE

Instruction • A microprocessor executes instructions given by the user. • Instructions should be in a language known to the microprocessor. • Microprocessor understands the language of 0’s and 1’s only. This language is called Machine Language. • An instruction is a binary pattern designed inside a microprocessor to perform a specific function. • Intel 8085 has 246 instructions. • Each instruction is represented by an 8 -bit binary value.

Instruction • The instruction set is a collection of pre-defined machine codes, which the CPU is designed to expect and be able to act upon when detected. • Each machine code of an instruction set consists of two separate fields: • The OPCODE is a short code which indicates what operation is expected to be performed. Each operation has a unique opcode. • The OPERAND, or operands, indicate where the data required for the operation can be found and how it can be accessed (the addressing mode, which is discussed in full later).

Instruction • The length of a machine code can vary - common lengths vary from one to twelve bytes in size. • Opcodes are also given mnemonics (short names) so that they can be easily referred to in code listings and similar documentation.

Microprocessor understands Machine Language only! • Microprocessor cannot understand a program written in Assembly language. • A program known as Assembler is used to convert an Assembly language program to machine language. • Assembly language is the language in which the mnemonics (shorthand of instructions) are used to write a program.

Examples Opcode Operand MOV C, A ADD B MVI A, 32 H MVI B, F 2 H

A Machine language program to add two numbers 00111110 000000100 10000000 ; Copy value 2 H in register A ; Copy value 4 H in register B ; A = A + B

Assembly Language of 8085 • It uses English like words to convey the action/meaning called as MNEMONICS • For e. g. – MOV – ADD – SUB to indicate data transfer to add two values to subtract two values

Assembly language program to add two numbers Note: • Assembly language is specific to a given processor

Instruction Set of 8085 • Consists of – 74 operation codes, e. g. MOV – 246 Instructions, e. g. MOV A, B • 8085 instructions can be classified as 1. Data Transfer (Copy) instructions 2. Arithmetic instructions 3. Logical and Bit manipulation 4. Branching instructions 5. Machine Control instructions

Example Data Transfer (Copy) Operations / Instructions 1. Load a 8 -bit number 4 F in register B 2. Copy from Register B to Register A 3. Load a 16 -bit number 2050 in Register pair HL 4. Copy from Register B to Memory Address 2050 5. Copy between Input/Output Port and Accumulator MVI B, 4 FH MOV A, B LXI H, 2050 H MOV M, B OUT 01 H IN 07 H

Example Arithmetic Operations / Instructions 1. Add a 8 -bit number 32 H to Accumulator 2. Add contents of Register B to Accumulator 3. Subtract a 8 -bit number 32 H from Accumulator 4. Subtract contents of Register C from Accumulator 5. Increment the contents of Register D by 1 6. Decrement the contents of Register E by 1 ADI 32 H ADD B SUI 32 H SUB C INR D DCR E

Example Logical & Bit Manipulation Operations / Instructions 1. Logically AND Register H with Accumulator 2. Logically OR Register L with Accumulator 3. Logically XOR Register B with Accumulator 4. Compare contents of Register C with Accumulator 5. Complement Accumulator 6. Rotate Accumulator Left ANA H ORA L XRA B CMP C CMA RAL

Addressing Modes of 8085 • Addressing modes specify the way in which the address of the operand is given in the instruction. • Opcode E. g. : is [Operands] [; comments] MVI B, 05 : Here MVI (Move Immediate) is the opcode part and the rest is the operand part. MOV A , B : Here MOV is the opcode part and the rest the operand part. ADD B : Here ADD is the opcode part and the rest is the operand part.

Addressing Modes of 8085 • • The various formats of specifying operands are called addressing modes. Addressing modes of 8085: 1. Register Addressing 2. Immediate Addressing 3. Memory Addressing 4. Input/Output Addressing

1. Register Addressing • In this addressing mode, a register contains the operand. Depending upon the instruction, the register may be the first operand, the second operand or both. • Operands are one of the internal registers of 8085. • Examples: MOV A, B ADD C

2. Immediate Addressing • In the immediate addressing mode, direct data is given in the operand which move the data in accumulator. It is very fast. • Value of the operand is given in the instruction itself • Examples: MVI A, 20 H LXI H, 2050 H ADI 30 H SUI 10 H

3. Memory Addressing • One of the operands is a memory location • Depending on how address of memory location is specified, memory addressing is of two types: 1. Direct addressing 2. Indirect addressing

3(a) Direct Addressing • In the direct addressing mode, address of the operand is given in the instruction and data is available in the memory location which is provided in instruction. We will move this data in desired location. • 16 -bit Address of the memory location is specified in the instruction directly. • Examples: LDA 2050 H ; load A with contents of memory location with address 2050 H STA 3050 H ; store A with contents of memory location with address 3050 H

Direct Addressing Diagram Instruction Opcode Address A Memory Operand

3(b) Indirect Addressing • In the indirect addressing mode, the instruction specifies a register which contain the address of the operand. Both internal RAM and external RAM can be access via indirect addressing mode. • A memory pointer register is used to store the address of the memory location. • Example: MOV M, A ; copy register A to memory location whose address is stored in register pair HL A 30 H H L 20 H 50 H 2050 H 30 H

Indirect Addressing Diagram Instruction Opcode Address A Memory Pointer to operand Operand

HL Register • The HL register is the only register that can be used to specify a memory address. • It is called a pointer register because it points to a memory location. • The H register contains the high byte of the address, and the L register the low byte. • High and low bytes may be unfamiliar to you. Consider the decimal number 47. From convention we know that 4 is the number of "tens", and the 7 is the number of "units", high and then low. • For the hex number 47, 4 is the number of "sixteens", and 7 is the number of "units". • In the same way for the number 4768, 47 is the number of "two-hundred-fifty-sixes", and 68 is the number of "units". • We split it this way because the first two digits can fit in the high byte (register) and the second two can fit in the low register.

MOV Instruction • This instruction is used to copy the data from one place to another. • The MOV instruction takes two operands. Syntax: • Syntax of the MOV instruction is: • The MOV instruction may have one of the following five forms:

MOV Instruction Examples: • MOV Rd, Rs (This instruction copies the content of Rs to Rd) • MOV M, Rs (This instruction copies the content of register Rs to memory location pointed by HL Register) • MOV Rd, M (This instruction copies the content of memory location pointed by the HL register to the register Rd. ) • *Note: the contents of the source register are not altered.

MVI Instruction • MVI: move immediate date to a register or memory location. Examples: • MVI Rd, #30 H (30 h is stored in register Rd) • MVI M, #30 H (30 h is stored in memory location pointed by HL Reg)

4. Input/Output Addressing • 8 -bit address of the port is directly specified in the instruction • Examples: IN 07 H OUT 21 H

5. Instruction & Data Formats 8085 Instruction set can be classified according to size (in bytes) as: 1. 1 -byte Instructions 2. 2 -byte Instructions 3. 3 -byte Instructions

1. One-byte Instructions • Includes Opcode and Operand in the same byte Examples: Opcode Operand Binary Code Hex Code Task MOV C, A 0100 1111 4 FH Copy the contents of the accumulator in the register C. ADD B 1000 0000 80 H Add the contents of register B to the contents of the accumulator. 0111 0110 76 H HLT

2. Two-byte Instructions • First byte specifies Operation Code • Second byte specifies Operand Examples: Opcode Operand Binary Code Hex Code MVI A, 32 H MVI B, F 2 H 0011 1110 0011 0010 0000 0110 1111 0010 3 EH 32 H 06 H F 2 H

3. Three-byte Instructions • First byte specifies Operation Code • Second & Third byte specifies Operand Examples: Opcode LXI LDA Operand Binary Code H, 2050 H 0010 0001 0101 0000 0010 0000 3070 H 0011 1010 0111 0000 0011 0000 Hex Code 21 H 50 H 20 H 3 AH 70 H 30 H

An example assembly language program Address Instruction 202 A 202 C 202 E MVI ADD A, 21 B, 2 A B 202 F STA 41 FF 2032 HLT ; Copies 21 into accumulator ; Copies 2 A into B register ; Adds B reg content with Acc and stores the result in Acc. ; Stores the Acc (the sum) into the memory location 41 FF. ; Stops the program

Another example assembly language program Address Instruction 2020 2022 2023 2024 MVI INR MOV SUB B, 24 B A, B B 2025 STA 5 F FF 2028 HLT ; Copies 24 into accumulator ; Increment B reg content by 1 ; Copies B register into Acc. ; Subtracts B reg content from Acc and stores the result in Acc. ; Stores the Acc content into the memory location 5 F FF. ; Stops the program
- Slides: 33