Documente Academic
Documente Profesional
Documente Cultură
Andrews Samraj
Assembler and Cross-Assembler directives ( ORG, END, EQU, DB,DW,DS) Usage of constants in assembly language program (Hexadecimal, Binary, Octal and Decimal constants usage)
1
SA
Dr.Andrews Samraj
SA
Dr.Andrews Samraj
Direct addressing Here the address of the operand is explicitly specified within the instruction itself. LDA, STA, IN, OUT instructions are some of the examples, which use direct addressing mode. Example: LDA 4500H Load the accumulator with the contents of the address location 4500H. Here the operand is in the memory location 4500H and address is mentioned in the instruction 3 bytes instruction OUT 45H Transfer the contents of accumulator to the output device with the port address 45 H. Here the operand in accumulator is copied to the buffer having the address 45 H. 2 bytes instruction Register indirect Addressing Here the operand is in memory location. The address of memory locations is stored in register pair and the name of the register pair is mentioned in the instruction. The contents of the specified registers are assumed to be the address of the operand. Here a register pair is specified to contain the 16-bit address of the operand. MOV,ADD, LDAX ,STAX are some examples of instructions using this addressing mode. These instructions occupy 1 byte each Examples: ADD M Add the accumulator contents with memory location contents whose address is in HL register pair- Here M indicates HL register pair. The second operand is in memory location whose address is stored in HL register pair. STAX B Store the accumulator contents with the data stored in memory location whose address is specified in BC register pair. Implicit Addressing There are certain instructions that operate only on one operand. Such instructions assume that the operand is in the accumulator and therefore require no address specification. RLC, RRC, CMA are some examples of instructions using implicit addressing mode. All are 1-byte instructions. RLC Here the operand is in accumulator. It is implicit. It is not explicitly mentioned in the instruction. Rotate the accumulator contents left by one position. CMA Complement the contents of accumulator (1s complement) Here the accumulator is not mentioned in the instruction. It is assumed.
SA
Dr.Andrews Samraj
2. Specific data byte to a register or 2. Load register B with the data byte a memory location. 32H. (MVI B,32H) 3. Between a memory location and 3. From a memory location 2000H to a register. register B. (LXI H,2000H MOV B,M)
4. Between an I/O device and the 4.From an input keyboard (43H) to the accumulator. accumulator. ( IN 43H )
ARITHMETIC OPERATIONS
Addition - Any 8-bit number, or the contents of a register or the contents of a memory location can be added to the contents of the accumulator and the sum is stored in the accumulator. No two other 8-bit registers can be added directly (e.g., the contents of register B cannot be added directly to the contents of the register C). The instruction DAD is an exception; it adds 16-bit data directly in register pairs.
SA 4
Dr.Andrews Samraj
Examples:
1. ADI 43H ([Accumulator] + 43H [Accumulator]) 2. ADD B ([A]+[B] [A]) 3. ADD M (A + [[HL]] [A] ) 4. DAD B ( [HL] + [ BC] [HL] )
Subtraction - Any 8-bit number, or the contents of a register, or the contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2's compliment, and the results if negative, are expressed in 2's complement. No two other registers can be subtracted directly. Examples: 1. SUI 67H ( [A] 67H [A] ) 2. SUB C ( [A] [C] [A] ) 3. SUB M ( [A] [[HL]] [A] ) Increment/Decrement - The 8-bit contents of a register or a memory location can be incremented or decrement by 1. Similarly, the 16-bit contents of a register pair (such as BC) can be incremented or decrement by 1. These increment and decrement operations differ from addition and subtraction in an important way; i.e., they can be performed in any one of the registers or in a memory location. Examples: 1. INR D ( [D] + 01 H 2. INR M ( [[HL]] + 01H 3. INX D ( [DE] + 01H [D]) [[HL]] ) [DE] )
LOGICAL OPERATIONS
These instructions perform various logical operations with the contents of the accumulator. AND, OR Exclusive-OR - Any 8-bit number, or the contents of a register, or of a memory location can be logically ANDed, Ored, or Exclusive-ORed with the contents of the accumulator. The results are stored in the accumulator. Examples: 1. ANI 78H ( [A] AND 78H [A] ) 2. ORA E ( [A] OR [E] [A] ) 3. XRA M ( [A] XOR [[HL]] [A] )
Rotate- Each bit in the accumulator can be shifted either left or right to the next position through carry or without carry. Examples: RLC Rotate accumulator left by one position. (8 bit) RAR Rotate accumulator right through carry ( 9 bit )
SA
Dr.Andrews Samraj
Compare- Any 8-bit number, or the contents of a register, or a memory location can be compared for equality, greater than, or less than, with the contents of the accumulator. Examples: CPI 45H ( [A] 45H ) According to the result, the flags will be set or reset. CMP B ( [A] [B] ) CMP M ( [A] [[HL]] ) Complement - The contents of the accumulator can be complemented. All 0s are replaced by 1s and all 1s are replaced by 0s. CMA ( [A] [A] )
BRANCHING OPERATIONS
This group of instructions alters the sequence of program execution either conditionally or unconditionally. Jump - Conditional jumps are an important aspect of the decision-making process in the programming. These instructions test for a certain conditions (e.g., Zero or Carry flag) and alter the program sequence when the condition is met. In addition, the instruction set includes an instruction called unconditional jump. Examples: 1. 3070H JMP 4050H Program control is jumped unconditionally to location 4050H from 3072H 2. 3070H JZ 4050H Next instruction is fetched from location 4050 H if zero flag is set. If it is reset, next instruction is fetched from 3073H (normal sequence)
Call, Return, and Restart - These instructions change the sequence of a program either by calling a subroutine or returning from a subroutine. The conditional Call and Return instructions also can test condition flags. Examples: CALL 6030 H, RET, CC 6030H, RZ
SA
Dr.Andrews Samraj
Copy the contents of the accumulator MOV in the register C. Add the contents of register B to the ADD contents of the accumulator. Invert (compliment) each bit in the CMA accumulator.
These instructions are 1-byte instructions performing three different tasks. In the first instruction, both operand registers are specified. In the second instruction, the operand B is specified and the accumulator is assumed. Similarly, in the third instruction, the accumulator is assumed to be the implicit operand. These instructions are stored in 8-bit binary format in memory; each requires one memory location. To understand how the binary code for the instruction is designed, MOV Rd, Rs Rd <-- Rs copies contents of Rs into Rd. Coded as 01 ddd sss where ddd is a code for one of the 7 general purpose registers, which is the destination of the data, sss is the code of the source register. Example: MOV A, B Coded as 01 111 000 = 78H All internal registers of 8085 are identified as follows:
SA 7
Dr.Andrews Samraj
Register Pairs BC DE HL SP
TWO-BYTE INSTRUCTIONS In a two-byte instruction, the first byte specifies the operation code and the second byte specifies the operand. Source operand is a data byte immediately following the opcode. For example: Task Opcode Operand A, Data Binary Code
0011 1110
Hex Code 3E
First Byte
DATA
Data
Second Byte
Assume that the data byte is 32H. The assembly language instruction is written as Mnemonics Hex code MVI A, 32H 3E 32H
The instruction would require two memory locations to store in memory. THREE-BYTE INSTRUCTIONS In a three-byte instruction, the first byte specifies the opcode, and the following two bytes specify the 16-bit address. Note that the second byte is the low-order address and the third byte is the high-order address. For example: Task Opcode
Operand
Binary code
Hex Code
Transfer JMP 2085H the C3 First byte 1100 0011 program 1000 0101 sequence 85 Second to memory 0010 0000 location 20 Third Byte 2085H. This instruction would require three memory locations to store in memory.
SA 8
Dr.Andrews Samraj
SA
Dr.Andrews Samraj
Example: END Description: End of Assembly. The HLT instruction suggests the end of a program, but that does not necessarily mean it is the end of the assembly EQU (Equate) Examples: 1. PORT1 EQU 01H Description: The value of the term PORT 1 is equal to 01H. Generally, this means the PORT 1 has the port address 01H. 2. INBUF EQU 2099H Description: The value of the term INBUF is 2099H. This may be the memory location used as Input Buffer. 3. STACK EQU INBUF+1 Description: The equate can be expressed by using the label of another equate. This example defines the stack as next location of INBUF. DB (Define Byte) Example: DATA: DB A2H,9FH Description: Initializes an area byte by byte. Assembled bytes of data are stored in successive memory locations until all values are stored. This is a convenient way of writing a data string. The label is optional. DW (Define Word) Example: DW 4050H Description: Initializes an area two bytes at a time DS (Define Storage) Example: OUTBUF:DS 4 Description: Reserves a specified number of memory locations. In this example, four memory locations are reserved for OUTBUF.
10
SA
Dr.Andrews Samraj
SA
11