Assembly and machine language programming :

The microprocessor based systems work by reading and executing the program available in its main memory. A program is sequence of instructions written using the instruction set of a microprocessor. The instruction set different from microprocessor to microprocessor. Hence a program written using instruction set of 8085 microprocessor works only on 8085 microprocessor based system, but not on systems based on other microprocessors. The microprocessor instructions are in binary form. The binary patterns for each instruction for a microprocessor is designed by manufacturer and made available to users. We have already studied the instruction formats for 8085 microprocessor. The examples of binary instruction of 8085 are as follows :

10000000             this is an instruction which adds contents of register B to accumulator and stores the result in accumulator.
01110110             this instruction halts the microprocessor.
00101111             this instruction complements the contents of accumulator.

8085 Instruction and Timing/Instruction and Timing

The 8085 defines 8-bit binary code called opcode for each instruction. The 8085 can understand program written only in binary codes as above. The program written using binary codes of instructions is called machine language program. The real difficulty in writing machine language program is to remember binary codes for large instruction set. It is very hard for any person to remember so many binary patterns and then write a program. To solve this problem, the English like words are used for each binary pattern called mnemonics. For example, the binary instructions written earlier are coded now using mnemonics as

ADD B                   add B to A                                                                
HLT                         halt the processor
CMA                      complement accumulator

The program written using mnemonics is called assembly language program. As the mnemonics are easy to remember, the program development will be faster and easier. The microprocessor can not understand program written using assembly language. To execute assembly language program. First it is to be converted to equivalent machine language program by translating mnemonic into binary patterns. The 8085 provides complete table called opcode or machine code table for this purpose, which is given in next section.
We will follow the format given in figure for our 8085 assembly language programs.

Label
mnemonic
operand
comments


It has four columns, the first column is a label to the instruction followed by ‘:’ (colon) which is used only if program uses branch instructions. The second column is used for mnemonics and third column is used for the operands. The last column is comment which is used to write small statements describing the function performed by the instruction. The comment is preceded by ‘;’ (semicolon). The comment is not executable part of program, but used to increase the readability of a program.
The format for machine language program is given in figure. It has two additional columns. The first column specifies the memory location where the corresponding machine code given in fifth column is stored.

The 8085 PIN Function

Memory location
label
Mnemonic
operand
Machine code
comments
                                                          
We can summerise the steps needed for microprocessor programming as follows :
1.       Given a problem, divide it into small steps.
2.       Optionally, develop a flowchart.
3.       Write an assembly language program.
4.       Translate an assembly language program to equivalent machine language program.
5.       Load machine language program in 8085 based kit and execute it.



The following example illustrates the steps in microprocessor programming as listed before.

Addressing modes :

Implied addressing, Register addressing, Immediate addressing, Direct addressing, Indirect addressing, Combined addressing

Implied addressing : in implied addressing, the addressing mode of an instruction is implied by the function of instruction itself, implied instruction generally doesn’t use any register or memory location. For example, STC (set carry flag) sets the CY flag to CMC (complement carry) instruction is another example of implied addressing mode instruction.

Register addressing : the addressing mode of an instruction is register, if it specifies its operands using registers only. For example, MOV A, B uses register B as source register and therefore the accumulator as destination register.  The register instructions are always single byte instructions which occupies only one byte in storage. They are also faster in execution as they are doing not go to refer any memory location for operands. The memory operation is relatively slow operation. Figure shows the execution of MOV A, B instruction. After execution, the accumulator gets the contents of register B. the contents of register B remains unchanged.

Immediate addressing : it store the data immediately after the opcode in the memory. For example, MVI A, 32h stores 8-bit data 32h immediately after the opcode within the memory as
instruction
Memory location
Machine code
MVI A, 32h
2000h
2001h
3Eh (opcode)
32h (data)
The execution of above instruction is shown in figure.
Addressing modes
Immediate Addressing modes

MVI A, 32h is two-byte instruction. Immediate instruction can be three-byte also. LXI H, 3050h is an example of three-byte instruction which uses immediate addressing mode as it stores 16-bit data immediate after opcode as
instruction
Memory location
Machine code
LXI H, 3050h
2000h
2001h
2002h
21h (opcode)
50h
30h
After execution of above instruction 50h is stored in register L and 30h is stored in register H. hence, it loads HL register pair with the contents 3050h.

Direct addressing : the instructions that use direct addressing mode are three-byte instructions. The first byte stores the opcode, while second and third byte specifies the 16-bit direct address as

Opcode
Lower byte of address
Higher byte of address
For example, LDA 3050h loads the contents of memory location specified by 16-bit address into the
Addressing modes
Direct Addressing modes

 accumulator. Figure shows the execution of LDA 3050h instruction. Figure shows how 16-bit direct address given within the instruction itself is employed to urge an operand.
The instruction is stored in program memory. The first byte in program memory is opcode 3Ah followed by the lower-order address 50h in second byte and therefore the higher-order address 30h in third byte. The microprocessor assembles the second byte and third byte into 16-bit memory address 3050h. then the microprocessor accesses the data memory location 3050h and loads its contents 01010101 into the accumulator.



Indirect addressing : The instructions that use the indirect addressing specifies the address of an operand indirectly into the register pair. The execution of MOV A, M instruction is shown in figure shows how register pair is used to specify the address of an operand.
Addressing modes
Indirect Addressing modes

The microprocessor forms the 16-bit address 3050h from the contents of H and L registers. Then the microprocessor moves the contents of knowledge location 3050h into the accumulator.

Combined addressing : sometimes an instruction follows more than  one addressing mode. If an instruction follows quite one addressing mode, it’s referred to as combined addressing. For instance, MVI M, 35h follows immediate and indirect addressing both. because it loads immediate value 35h into memory location, it is immediate addressing. The address of memory location is indirectly given in HL register pair, so it’s also indirect.

Post a Comment

Please do not enter any spam link in the comment box.

Previous Post Next Post