Top Banner
MICROPROCESSOR Microprocessor is a semiconductor device consisting of electronic logic circuits manufactured by using LSI or VLSI technique. Microprocessor is a programmable logic devices with registers, flip-flops & timing elements. – ALU • Arithmetic operations • Logical operations Register unit Control unit Computer Languages - Machine language - Assembly language (Mnemonics, Assemblers) - High-level language (Compilers, interpreters)
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Microprocessor

MICROPROCESSOR

• Microprocessor is a semiconductor device consisting of electronic logic circuits manufactured by using LSI or VLSI technique.

• Microprocessor is a programmable logic devices with registers, flip-flops & timing elements.

– ALU• Arithmetic operations• Logical operations

– Register unit– Control unit

Computer Languages

- Machine language

- Assembly language (Mnemonics, Assemblers)

- High-level language (Compilers, interpreters)

Page 2: Microprocessor

Architecture of Microprocessor

• The process of data manipulation and communication is determined by the logic design of the microprocessor called the architecture.

• Function performed by the microprocessor

– Microprocessor- Initiated operations• I/O Read, I/O Write, MR, MW

– Internal Data operations and registers• Perform A & L operations• Registers• Flags• PC, SP

– Peripherals/Externally Initiated operations• Reset, Interrupt, Read, Hold

Page 3: Microprocessor

Instructions

– An instruction is a command to the microprocessor to perform a given task on specified data.

– Types• 1-byte instructions (MOV C,A CMA (complement)• 2-byte instructions ( MVI A, data)• 3-byte instructions (JMP 2010)

Operations

• Data transfer operations• Arithmetic operations• Logic operations• Branch operations

Interfacing

Interfacing devices are semiconductor chips that are needed to connect peripherals to the bus system.

Ex: Tri-state devices, Decoders, Encoders

Page 4: Microprocessor

8085 Microprocessor

Intel’s 8085 is an 8bit general purpose microprocessor capable of addressing 64k of memory

8085 pin out diagram

Signal classification1. Address bus2. Data/address bus3. Control & Status signal4. Power & Frequency signals5. Interrupts & peripheral initiated signals6. Serial I/O ports.

Functional Block Diagram of 8085

1. ALUFlags :S - Sign flag (if D7=1 –ive no. If D7=0 +ive no.)Z – Zero flag (if result is 0 then Z is set)AC – Auxiliary Carry flag (if D3 passed carry to D4 then AC is set)P – Parity flag (after A & L if result has even no. of 1s then P is set)CY – Carry flag ( A & L operations results in a carry the CY is set )

Page 5: Microprocessor

2. Timing & Control Unit

This unit synchronizes all the microprocessor operations with clock and generates the control signals necessary for communication between microprocessor and IO devices.

3. Instruction Register (IR) & Decoder

IR - When instruction is fetched from memory, it is loaded in the instruction register.

Decoder – decodes the instruction and establishes the sequence of events to follow.

4. Register Array

A - accumulator

B,C,D,E, H,L

W,Z – temporary registers (not accessible for user)

Page 6: Microprocessor

8086 Microprocessor• Limitations of 8085• Intel’s 8086 was the first 16-bit microprocessor launched in 1978.

Architecture of 8086:

8086 is divided into two units – Bus Interface Unit (BIU), Execution Unit (EU)

Execution Unit:

1. Control circuit – which directs internal operations.

2. Instruction Decoder – translates instructions fetched from memory into a series of actions which the EU carries out.

3. ALU – Add, sub, increment, decrement, complement, shift binary numbers. 4. General Data Registers

AX = (AH+AL) AccumulatorBX - used as an offset storage for forming physical addressCX - default counter in case of string and loop instructionsDX – implicit operand or destination register in case of a few instruction

Page 7: Microprocessor

5. Flag Registers

A flag is a flip-flop that indicates some condition produced by the execution of an instruction or controls certain operations of the EU.

A 16-bit flag register in the EU contains 9 active flags, 6 flags indicate some condition produced by an instruction, 3 flags are control flags.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

O – Overflow FlagD – Direction I – Interrupt FlagT – Trap FlagS – Sign FlagZ – Zero FlagAc – Auxiliary Carry FlagP – Parity FlagCy – Carry FlagX – Not used

X X X X O D I T S Z X Ac X P X Cy

Page 8: Microprocessor

6. Pointers and Index Registers

Pointers contain offset within the particular segments. IP – Instruction Pointer register holds the 16-bit address or

offset of the next code byte within code segment .20 bit address = offset of IP + Segment base address in CS.

BP – Base Pointer contains Source Index (SI) register and Destination Index (DI) register

SP – Stack Pointer register in the Execution Unit holds the 16-bit offset from the start of the segment to the memory location where a word was most recently stored on the stack (i.e top of stack).

SP,SI,DI – these 3 register are used for temporary storage of data.

Page 9: Microprocessor

Bus Interface Unit:

Segment Registers

8086 has segmented memory. 1MB memory is divided into 16 logical segments (16x64K)

CS – Code Segment register used for addressing a memory location in the code segment of the memory where the executable program is stored.

SS – Stack Segment register refers to stack segment of stack data

DS – Data Segment register point to the data segment of the memory, where the data is resided.

ES – Extra Segment register also refers to a segment which essentially is another data segment of the memory. (It also points to data segment).

Page 10: Microprocessor

Addressing Modes of 8086

The way in which an operand is specified is called its addressing mode.

I. Data-related addressing modes

II. Branch addressing modes

I. Data-related addressing modes

1. Immediate addressing modeThe datum is either 8 bits or 16 bits long and is part of the instruction.

2. Direct addressing modesThe 16 bit effective address (EA) of the datum is part of the instruction

3. Register addressing modesThe datum is in the register that is specified by the instruction.

Page 11: Microprocessor

4. Register Indirect The effective address of the datum is in the base register BX or an index register that is specified by the instruction.

5. Register Relative The effective address is the sum of an 8 or 16 bit displacement and the contents of a base register or an index register.

6. Based Indexed the effective address is the sum of a base register and an index register.

7. Relative Based IndexedThe effective address is the sum of an 8 or 16-bit displacement and a based indexed address.

Page 12: Microprocessor

II. Branch Addressing Modes

1. Intrasegment DirectThe effective branch address is the sum of an 8- or 16-bit displacement and the current contents of IP.It may be used with either conditional or unconditional branching, but a conditional branch instruction can have only an 8-bit displacement.

2. Intrasegment IndirectThe effective branch address is the contents of a register or memory location that is accessed using any of the data-related addressing modes. This mode is used only in Unconditional branch instructions.

3. Intersegment DirectReplaces the contents of IP with part of the instruction and the contents of CS with another part of the instruction. The purpose of this mode is to provide a means of branching from one code segment to another.

4. Intersegment DirectReplaces the contents of IP and CS with the contents of two consecutive words in memory that are referenced using any of the data-related addressing modes except the immediate and register modes.

Page 13: Microprocessor

Assembler Directives• An assembler is a program used to convert an

assembly language program into the equivalent machine code modules which may further be converted to executable codes.

• It decides the address of each label and substitutes the values for each of the constant and variables. It then forms the machine code for the mnemonics and data in the assembly language program (ALP).

• The logical errors or other programming errors are not found out by the assembler. To know errors hints are required from the programmer.

• The hints are given to the assembler using some predefined alphabetical strings called Assembler Directives, which help the assembler to correctly understand the ALPs to prepare the codes.

Page 14: Microprocessor

1. SEGMENT, ENDS DirectivesThe SEGMENT and ENDS directives are used to identify a group of data items or a group of instructions that we want to be put together in a particular segment.

A group of data statements or a group of instruction statements contained between SEGMENT and ENDS directives is called a logical segment.

ex: DATA_HERE SEGMENT------ logical ------ segmentDATA_HERE ENDS

2. DB – Define ByteDB Directive is used to reserve byte / bytes of memory locations in the available memory.

3. DW – Define WordDW is used to specify that the data is of type word (16-bits).

Page 15: Microprocessor

4. DD – Define Double WordDD is used to specify that the data is of type double word (32-bits).

5. DQ – Define Quadword

This directive us used to direct the assembler to reserve 4 words (8 bytes) of memory for specified variable and may initialize it with the specified values.

6. DT – Define Ten Bytes

The DT directive directs the assembler to reserve 10 bytes of memory for specified variable and may initialize it with the specified values.

Page 16: Microprocessor

7. ASSUME – Assume Logical Segment Name

The ASSUME directive is used to inform the assembler, the names of the logical segments to be assumed for different segments used in the program. The ASSUME statement is a must at the starting of each assembly language program.

Ex: ASSUME CS:CODE directs the assembler that the machine codes are available in a segment named CODE, and hence the CS register is to be loaded with address (segment) allotted by the operating system for the label CODE, while loading.

8. END – END of ProgramThe END directive marks the end of an ALP.

In ALP, the subroutines are called procedures.

• ENDP – END of ProcedureThe ENDP directive is used to indicate the end of a procedure.

Ex: PROCEDURE STAR--------

STAR ENDP

Page 17: Microprocessor

10. EVEN – Align on Even Memory Address

The EVEN directive updates the location counter to the next even address.

Ex: EVENPROCEDURE ROOT

---------

ROOT ENDP

11. EQU – Equate

The directive EQU is used to assign a label with a value or a symbol.While assembling, whenever the assembler comes across the label , it substitutes the numerical value for that label and finds out the equivalent code.

12. LABEL – LabelThe Label directive is used to assign a name to current content of the location counter.

Page 18: Microprocessor

13. EXTRN – External and PUBLIC : Public

The directive EXTRN informs the assembler that the names, procedures and labels declared after this directive have already been defined in some other assembly language modules.While in the other module, where the names, procedures and labels actually appear, they must be declared public, using the PUBLIC directive.

Ex: MODULE1 SEGMENTPUBLIC FACTORIAL FARMODULE1 ENDSMODULE2 SEGMENTEXTRN FACTORIAL FARMODULE2 ENDS

14. GROUP – Group the Related Segments

This directive is used to form logical groups of segments with similar purpose or type.The assembler passes an information to the linker/loader to form the code such that the group declared segments or operands must lie within a 64KB memory segment.

Ex: PROGRAM GROUP CODE, DATA, STACKASSUME CS:PROGRAM, DS:PROGRAM, SS:PROGRAM

Page 19: Microprocessor

15. LOCAL

The lables, variables, constants or procedures declared LOCAL in a module are to be used only by that particular module.

Ex: LOCAL a,b,DATA, ARRAY

16. OFFSET – Offset of a Label

When the assembler comes across the OFFSET operator along with a label, it first computes the 16-bit displacement of the particular label, and replaces the string ‘OFFSET LABEL’ by the computed displacement. This operator is used with arrays, strings, labels and procedures to decide their offsets in their default segments.

17. ORG – Origin

The ORG directive directs the assembler to start the memory allotment for the particular segment, block or code from the declared address in the ORG statement.

While starting the assembly process for a module, the assembler initializes a location counter to keep track of the allotted addresses for the module.

If an ORG statement is not written in the program, the location counter is initialized to 0000.

Page 20: Microprocessor

18. PROC – Procedure

The PROC directive marks the start of a named procedure in the statement.Also, the types NEAR or FAR specify the type of the procedure, i.e whether it is to be called by the main program located within 64k of physical memory or not.

19. FAR PTR

This directive indicates the assembler that the label following FAR PTR is not available within the same segment and the address of the label is of 32-bits i.e 2 bytes offset followed by 2 bytes segment address.

20. NEAR PTR

This directive indicates the assembler that the label following NEAR PTR is in the same segment and needs only 16-bit i.e 2 byte offset to address it.

Page 21: Microprocessor

Assembler OperatorsAnother type of hint which helps the assembler to assign a particular constant with a label or initialize particular memory locations or labels with constants is an operator.

1. PTR – Pointer

The PTR operator is used to declare the type of a label, variable or memory operand. The operator PTR is prefixed by either BYTE or WORD.

2. SEG – Segment of a Label

The SEG operator is used to decide the segment address of the label, variable, or procedure and substitutes the segment base address in place of “SEG” label.

3. SHORT

The SHORT operator indicates to the assembler that only one byte is required to code the displacement for a jump i.e displacement is within -128 to +127 bytes from the address of the byte next to the jump opcode. This method of specifying the jump address saves the memory.

Page 22: Microprocessor

4. TYPE

The TYPE operator directs the assembler to decide the data type of the specified label and replaces the ‘TYPE’ label by the decided data type.

Ex: MOV AX, TYPE STRING

moves the value 0002h in AX.

5. GLOBAL

The labels, variables, constants or procedures declared GLOBAL may be used by other modules of the program.

Ex: ROUTINE PROC GLOBAL

6. ‘ + & - ‘ Operators

These operators represent arithmetic addition and subtraction respectively and are typically used to add or subtract displacement (8 or 16 bit) to base or index registers or stack or base pointers.

Ex: MOV AL, [SI +2]

Page 23: Microprocessor

8086 Stack• The Stack is a section of memory we set aside for storing

return address. And used to save the contents of registers for the calling program while a procedure executes. It also used to hold data or addresses that will be acted upon by a procedure.

• 8086 contains stack segment (SS) register and stack pointer (SP) register.

• SS reg. is used to hold the upper 16 bits of the starting address we give to the stack segment. SP reg. is used to hold the offset of the last word written on the stack.

• 8086 produces the physical address for a stack location by adding the offset contained in the SP reg. to the stack segment base address represented by the 16-bit number in the SS reg.

• SP reg. is automatically decremented by 2 before a word is written to the stack i.e. initialize the SP reg to point to the top of the memory you set aside as a stack.

Page 24: Microprocessor

• If the CALL is to a procedure in the same code segment then the CALL is NEAR, and the Instruction Pointer (IP) contents will be saved on the stack.

• A RET at the end of the procedure copies IP value from the stack back to the IP to return execution to the calling program.

• If the CALL is to a procedure in another code segment, the CALL is FAR, and both the IP & CS register contents will be saved on the stack.

• A RET instruction at the end of the procedure copies these values from the stack back into the IP & CS registers to return execution to the mainline program.

Page 25: Microprocessor

Procedures

• Procedure is a group of instructions used at several different points in a program.

Procedure name PROC arguments--------RETENDP

• CALL instruction is used to call a particular procedure

• RET instruction at the end of the procedure returns execution to the next instruction

• CALL instruction executes, it automatically stores the return address in the stack memory.

Page 26: Microprocessor

Passing parameters to procedure

1. Passing parameters in RegistersDATA SEGMENTBCD_INPUT DB 20HBIN_VALUE DB ?DATA ENDS

CODE SEGMENT---MOV AL, BCD_INPUT ;Moving input into AL reg.CALL BCD_BIN ; call procedure BCD_BIN---NOP

;Procedure to convert BCD to Binary no.BCD_BIN PROC NEAR-------RETBCD_BIN ENDP---CODE ENDSEND

Page 27: Microprocessor

2. Passing parameters in General Memory

DATA SEGMENTBCD_INPUT DB 20HBIN_VALUE DB ?DATA ENDSCODE SEGMENT---CALL BCD_BIN; call procedure BCD_BIN---NOP;Procedure to convert BCD to Binary no.BCD_BIN PROC NEAR----MOV AL, BCD_INPUT ;Load input from memory------MOV [DI], AL ; Store result in memoryRETBCD_BIN ENDP----CODE ENDSEND

Page 28: Microprocessor

3. Passing Parameters using Pointers

DATA SEGMENTBCD_INPUT DB 20HBIN_VALUE DB ?DATA ENDS

CODE SEGMENT---MOV SI, OFFSET BCD_INPUT ;create pointer to BCD

inputMOV DI, OFFSET BIN_VALUE ; Store resultCALL BCD_BIN ; call procedure BCD_BIN---NOP

Page 29: Microprocessor

;Procedure to convert BCD to Binary no.

BCD_BIN PROC NEAR----MOV AL, [SI] ;Load input from memory ------MOV [DI], AL ; Store result in memory----RETBCD_BIN ENDP----CODE ENDSEND

Page 30: Microprocessor

MACROS

• A macro is group if instructions we bracket and give a name to at the start of our program. Each time we “call” the macro in our program, the assembler will insert the defined group of instructions in place of the “call”.

• Every time a macro name in the program, replace it with the group of instructions defined as that macro at the start of the program. This process is known as expanding the macro or macro expansion.

• Using a macro avoids the overhead time involved in calling, returning from a procedure.

• A disadvantage of generating in-line code each time a macro is called is that this will make the program take up more memory than using a procedure.

Page 31: Microprocessor

Defining a MACRO:

Macro_name MACRO dummy parameters-----------

ENDM

Ex: Move_ASCII MACRO Number,Source,DestinationMov CX,Number ; No. of characters to be moved in CX

LEA SI,Source ; Point SI at ASCII source

LEA DI,Destination ; Point DI at ASCII destination

CLD ; Autoincrement pointer after move

REP MOVSB ; Copy ASCII string to new location

ENDM

A macro may be defined in another macro or a macro may be called from inside a macro. This type of

macro is called a nested macro.