Microprocessors used in Personal Computers The Memory Map





















- Slides: 21

Microprocessors used in Personal Computers

The Memory Map of a Personal Computers • Transient Program Area (TPA): Holds the operating system (interrupt vectors, DOS BIOS, devices drivers, Command. com) and application programs. • System Area: Holds the ROM BIOS, the video buffer area, and the BASIC language ROM. • Extended Memory: Memory above the 1 M conventional memory found in AT compatible computers. Its size depends on the RAM installed on the motherboard, and is limited by the size of the processor’s address bus.

The 80 x 86 Programming Model

The Flag Register • Z (zero): This flag is set to one if the result of the last arithmetic or logic instruction is zero. • S (sign): This flag is set to one if the MSBit of the result of the last arithmetic or logic instruction is one, indicating a negative number. • C (carry): This flag is set to one if the last arithmetic instruction gave a carry out or a borrow in. • O (overflow): This flag is set to one if the result of the last arithmetic operation on signed numbers exceeded the capacity of the destination register.

80 x 86 Modes of operation • Protected mode – Programs are given separate memory areas (segments) – Programs are not allowed to access memory outside of their segments • Real-address mode – Environment of 8086 processor – Direct access to system memory and hardware devices – The operating system could crash • System management mode – Provides an operating system for implementing power management and system security functions (computer manufacturers)

Segmentation • Segmentation is used to allow relocation of programs, i. e. programs can be loaded on different memory areas and still run correctly. • Segmentation is used in the 8088/8086 microprocessors to allow the generation of 20 -bit addresses using 16 -bit registers. • In the Real Mode Operation a 20 -bit address (effective address) is obtained by shifting the segment address 4 bits to the left (X 10 H) and then adding the offset address. • The offset address is specified in the program. The segment address is specified by the operating system whenever the program is loaded. • The code segment holds the machine codes of the program. The Instruction Pointer specifies the offset address in the code segment. • The data segment holds the data used by the program. Most data references are specified in the data segment. • The stack segment holds the stack of the program. The offset address in the stack segment is specified with the registers SP and BP. • The extra segment is used as a data segment by some data movement instructions.

Segmentation (Example) If DS =1600 H find the maximum area occupied by the data segment. Find also the effective address, if the offset address is 1 F 00 H. Starting address = DS X 10 H = 1600 H X 10 H = 16000 H Ending address = Starting address + FFFF = 16000 H + FFFFH = 25 FFFH Effective address = Segment: Offset = 1600: 1 F 00 = Segment address X 10 H + Offset = 1600 H X 10 H + 1 F 00 H = 16000 H + 1 F 00 H = 17 F 00 H

Assembler Directives · Directives are instructions given by the programmer to the assembler on how to assemble the program. · Directives are not part of the instruction set of the microprocessor. · The use of directives might vary from assembler to assembler. · Some of the MASM 6. 12 assembler directives are: – ORG (Origin): Tells the assembler where to store the machine code of the next instruction. – EQU (Equate): Tells the assembler to assign a value to an identifier. – SEGMENT: Tells the assembler to begin a new segment. – ASSUME: Tell the assembler to associate a segment with a segment register. – PROC (Procedure): Tells the assembler to begin a new procedure. – MACRO: Assigns the sequence of instructions to an identifier. – END: Ends a program, segment (ENDS), a procedure (ENDP), or a macro (ENDM).

Data Definition Directives • Data Definition directives tell the assembler to store the specified data in the next memory locations. Data that occupies more than one location is stored with the LSByte in the lower address. – (DB) Define Byte (1 byte or 8 bits - Same as BYTE) – (DW) Define Word (2 bytes or 16 bits - Same as WORD) – (DD) Define Double Word (4 bytes or 32 bits - Same as DWORD) – (DQ) Define Quad Word (8 bytes or 64 bits - Same as QWORD) – (DT) Define Ten Bytes (10 bytes or 80 bits - Same as TBYTE) Examples: • • ABC XYZ YOU VAL X 1 X 4 N 1 DB DB DB DW DB DB DB 26 H 35 H, 87 H, 0 A 4 H ‘JOHN’ 1254 H ? 3 DUP(20 H) 123 H ; ABC=26 H ; XYZ= {35 H, 87 H, A 4 H} ; YOU = ‘JOHN’ ; VAL = 1254 H ; X 1 = UNSPECIFIED ; X 4 = {20 H, 20 H} ; INVALID

Data Definitions (Example) Show the content of the memory based on the following data definitions: ORG VAL 1 AB 10 NEW LOT XY 11 A 123 B 561 VAL 2 100 H EQU DB DB DB DD DB DB 21 H 37 23 H, 56 H, ’$’ DW 1245 H ‘NEXT’ 123 H 4 DUP(40 H) VAL 1

Format of DOS programs • All programs must have a code and a stack. – Code is the part of the program that contains the instructions of the program. – Stack is an area in the RAM used by the system to store return addresses, and by the programmer to store temporarily data. It is a Last In First Out (LIFO) buffer. • Programs can also have a data area, where all data (variables) is stored. • There are two basic types of programs: – Commands (. COM). The data and the stack of the program are part of the Code segment. The stack is always located at the end of the segment. The first 256 bytes of the segment are reserved. – Executable (. EXE). The code and stack and data of the program are located in different segments.

Format of the. COM programs CSEG SEGMENT PARA 'CODE’ ; Start a Code segment ASSUME CS: CSEG, DS: CSEG, SS: CSEG ORG 100 H ; Reserve first 256 locations START: JMP MAIN ; Skip data area {Place the data of the program here} MAIN PROC NEAR ; Beginning of main procedure {Place the code of the program here} RET MAIN ENDP CSEG ENDS END START ; Get return DOS address ; End of main procedure ; End of the segment ; End of the program

Addressing Modes Addressing mode refers to the way the data needed by an instruction is specified.

Immediate Addressing Mode • The data needed is specified as a number in the machine code of a program. The data is specified by the programmer: – as a numeric operand in the instruction, e. g. MOV AL, 87 H ; AL 87 H MOV CX, 34 A 6 H ; CX 34 A 6 H MOV BL, 8 C 2 H ; Invalid (Data Mismatch) – or as a label. The actual value is determined by the assembler. e. g. MOV VAL 3 BX, OFFSET VAL 3 MOV AH, CON 1 ; BX Address of ; AH CON 1

Immediate Addressing Mode (Example)

Register Addressing Mode • Both of the operands are the contents of registers. e. g. MOV AL, BH ; AL BH MOV BX, CX ; BX CX MOV AX, DL ; Invalid (Data Mismatch) • Example:

Direct Addressing Mode • One of the operands is the contents of the memory location that is specified directly in the instruction. e. g. MOV AL, [1008 H] ; AL [1008 H] MOV BX, VALUE ; BX [VALUE]

Register Indirect Addressing Mode • One of the operands is the contents of the memory location that is specified by a register, or a combination of registers and an offset, in the instruction. - Index: Use of SI or DI to specify a memory location. e. g. - ; AL [SI] MOV AH, [BP] ; AL [BP] Base Relative: Use of BX or BP in combination with an offset to specify a memory location. e. g. - AL, [SI] Base: Use of BX or BP to specify a memory location. e. g. - MOV AL, [BX+ 2] ; AL [BX + 2] Base Relative plus Index: Use of BX or BP in combination with an index register (SI or DI) and an offset to specify a memory location. e. g. MOV AL, [BX+SI+8] ; AL [BX+SI+8] MOV BX, ARR[BX+DI] ; BX ARR[BX+DI]

Register Indirect Addressing Mode (Example)

Addressing Modes (Example)

Examples Indicate whether or not each of the following MOV instructions is valid or invalid • MOV AX, BX • MOV ECX, 6 F 23458 H • MOV DX, BL • MOV SI, -1 • MOV ECX, EDX • MOV DS, 1000 H • MOV SI, DI • MOV DS, AX • MOV AL, 100 H • MOV AL, DH • MOV 123, DH • MOV AX, DH • MOV 0 FABH, AX • MOV IP, AX • MOV SI, CL • MOV EDX, AX • MOV EDX, ESI • MOV AX, ES • MOV AX, 16 • MOV DX, 7 F 65 H • MOV EDX, -2