The Intel x86 Hardware Organization - PowerPoint PPT Presentation

About This Presentation
Title:

The Intel x86 Hardware Organization

Description:

offsets are expressed as 16-bit unsigned binary numbers. UHD:CS2401: A. Berrached ... The IP register always Points to the next instruction to be executed. ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 39
Provided by: aliber
Learn more at: http://cms.dt.uh.edu
Category:

less

Transcript and Presenter's Notes

Title: The Intel x86 Hardware Organization


1
The Intel x86 Hardware Organization
2
The 8086 Processor
Execution Unit
Bus Interface Unit
Bus Control Unit
System Bus
Internal Bus
Control Unit
Instruction Queue
3
Internal Memory
  • 256 KB of ROM and 768 KB of RAM

Starting Address
960K F0000
768K C0000
640K A0000
9FFFF
0 00000
4
  • The Internal memory of the 8086 can be up to
  • 1 M bytes large.
  • How many bits are needed to express memory
    addresses ?
  • Answer
  • 1 Meg 220
  • gt 20-bit addresses

5
The 8086 Register Set
  • Segment Registers CS, DS, SS, ES
  • General-Purpose Registers AX, BX, CX, DX
  • Pointer Registers SP, BP
  • Index Registers SI, DI
  • Instruction Pointer IP
  • A Flags Register
  • For the 8086, all registers are 16-bits large
  • Bits in registers are numbered right to left,
    starting from 0.

6
Registers

Low-order byte
High-order byte
Example Store 17F6H in register
1
7
F
6
7
General-Purpose Registers
  • AX, BX, CX, DX all 16-bits large
  • AX Accumulator register
  • BX Base register
  • CX Count register
  • DX Data register
  • You can address them as one word or 1 byte.
  • E.g.
  • All other registers must be accessed as the
    16-bit.

8
Using General-Purpose Registers
  • MOV instruction copies data from one location
    into another.
  • MOV Destination, Source Copy source to dest.
  • E.g. MOV DX, CX
  • Copies contents of register CX into register DX.
  • The MOV instruction does not effect the source
    operand
  • But Source and destination must be of same size.
  • MOV AH, BH
  • MOV AH, BX Cant do

9
Unising General-Purpose Registers
  • MOV AX, 3D2BH load 3D2BH into AX
  • MOV BH, 42H load 42H in high byte of BX
  • ADD AL, 32H add 32H to AL
  • Note 80386 and later processor have 32-bit
    extended versions EAX, EBX, ECX, and EDX
  • MOV EAX, FF22AA00H (386 up)

10
Program Segments
  • A segment is an area in memory that includes up
    to 64K bytes and begins on a paragraph boundary
    ie. on an address evenly divisible by 16.
  • Note When an address is evenly divisible by 16
    (i.e. 10H), its least significant four bits are
    0s.
  • gt How many bits are needed for segment starting
    address?
  • 16-bits
  • A program usually has one code segment (for the
    code), a data segment (for the data used by the
    program) and a stack segment.

11
Program Segments
  • The three types of segments are
  • code segment contains machine instructions that
    make up the program. The starting address of the
    code segment is stored in the Code Segment (CS)
    register
  • data segment contains the data used by the
    program. The address of the data segment is
    stored in the Data Segment (DS) register.
  • stack segment the stack is used for temporary
    storage to save data temporarily or during
    subroutine calls. The address of the stack
    register is stored in the Stack Segment (SS)
    register.

12
Segment Registers
  • So when writing a program you always need to
  • load CS with the starting address of the code
    segment
  • load DS with the starting address of the data
    segment
  • load SS with the starting address of the stack
    segment
  • All addressing within the program is done
    relative to segment registers.

13
Relative Addressing--Offset Address
  • The distance in bytes from a segment address to
    another location within the segment is called the
    offset address.
  • the first byte of a segment is at offset address
    0
  • the second byte is at offset 1
  • An offset can range from 0 to 65,535 (0000-FFFF)
  • gt offsets are expressed as 16-bit unsigned
    binary numbers.

14
Relative Addressing--Logical Address
  • Generally, memory locations are expressed as
  • Segment_RegisterOffset
  • meaning that the address is Offset bytes from
    the starting address of the segment. This is
    what is called the logical address.
  • Example
  • DS17H

15
Relative Addressing--Physical Address
  • The physical address is the actual RAM or ROM
    address. In the 8086, it is a 20 bit address.
  • How to compute the physical address of
    Seg_RegOffset ?
  • Shift the Seg_Reg left one Hex digit (pad with 0
    at the right).
  • Add the Offset.

16
Relative Addressing Example
  • Data segment starting address is 027A0H
  • gt DS register
  • Because segment starting addresses must be evenly
    divisible by 16, the leftmost hexadecimal digit
    is always 0.
  • gt The leftmost hex digit of a segment starting
    address is not stored in the segment register.

17
  • Assume we need to access data stored in the 24th
    byte of data segment
  • gt offset 17H
  • Logical address DS17H
  • Physical address
  • Start with DS 027A
  • Shift left DS 027A0
  • Add offset 17
  • --------------
  • 027B7 H

18
Pointer Registers
  • Instruction Pointer (IP) register
  • Stack Pointer (SP) register
  • Base Pointer (BP) register

19
Instruction Pointer
  • The IP register always Points to the next
    instruction to be executed.
  • I.e. its contains the offset address of the next
    instruction that is to execute.
  • The address of the next instruction to be
    executed is formed by adding the content of IP to
    that of CS.
  • CSIP
  • The IP register is always associated with the CS
    register.

20
Stack Pointer register
  • The SP contains the offset address of the top of
    the stack
  • The SP register is always associated with the SS
    (Stack Segment) register
  • SSSP

21
Base Pointer register
  • The BP register is used to facilitate referencing
    parameter (on function calls)
  • The BP register is also associated with the SS
    register.

22
Flags Register
  • A 16-bit register
  • 80386 and later processor have a 32-bit flags
    register
  • Each bit indicates a certain status
  • example Overflow, Carry, Interrupt
  • Many instructions change the status of the flags
  • Some instruction test for certain bits of the
    flag register before taking action
  • example JO jump if overflow bit is set

23
Addressing of operation and data
  • An instruction consists of
  • at least one operation (e.g., ADD, MOVE)
  • zero, one or more operands (to reference the
    data)
  • Generally, the first operand is the destination
  • example
  • MOV AX, 25 Immediate operand
  • MOV BX, AX register to register

24
Addressing of operation and data
  • More examples
  • MOV AL, 0034 indexed addressing
  • Physical address of operand DS34H
  • gt the indicate that the physical address
    of the operand is computed by taking whats
    between the
  • as an offset and adding it to DS

25
Addressing - Cont.
  • An instruction may access more than one byte at a
    time
  • e.g., MOV AX, 35F3H
  • MOV 1500, AX
  • This instruction will copy the contents of AX
    (i.e. 35F3H) in two 2 memory locations starting
    at address DS1500.
  • How are the two bytes arranged?
  • Little endian convention low order byte in low
    order memory address

26
Little endian convention
  • Assume DS 31460H
  • gt DS1500 32960H

Memory
.
.
F3
35
32960
32961
AX
35
F3
AH
AL
27
Instruction Operands
  • Some More Examples
  • X1 DW 0 Define X1 as a word
  • ..
  • MOV CX, X1 Move X1 to CX
  • MOV CX, 25 Move 25 to CX
  • MOV CX, DX Move content of DX to CX
  • MOV CX, DX Indexed addressing
  • gt to get actual address of operand use content
    of DX as an offset and add it to DS
  • gt actual address DS DX

28
Debug program
  • A debugger program for x86 Assembly
  • used to
  • enter machine code
  • enter assembly code
  • write small programs (.COM files)
  • debug assembly programs

29
DEBUG Commands
  • A Assemble assembler instructions into machine
    code
  • D Display contents of memory at a specific
    address
  • E Enter data/instruction into memory
  • G (Go) run the program
  • T Trace
  • P Proceed execute a set of instruction
  • R display contents of Registers
  • W Write (I.e. save) a program into disk
  • Q Quit
  • See Appendix E of Text book.

30
DEBUG
  • Few Basic Rules
  • case insensitive
  • uses the colon format (e.g., segmentoffset)
  • uses hexadecimal notation
  • use a space to separate parameters

31
Debug - Cont.
  • Examples
  • D DS200 ltRTNgt
  • E CS100 B8 23 01 01 05 25 00 ltRTNgt
  • R ltRTNgt
  • AX BX ..
  • ..
  • nnnn0100 B82301 MOV AX, 0123

32
D Display Memory Content
  • Address Hex representation ASCII
  • xxxxxx10 xx....xx-xx....xx x.x
  • xxxxxx20 xx....xx-xx....xx x.x
  • xxxxxx30 xx....xx-xx....xx x.x
  • ...
  • xxxxxx80 xx....xx-xx....xx x.x

33
Machine Language Example
  • Machine Lang Assembly Lang
  • B82301 MOV AX, 0123
  • 052500 ADD AX, 0025
  • 8BCB MOV CX, BX
  • 90 NOP

34
Debug Operations
  • Keying in program instructions
  • Executing program instructions
  • Displaying memory contents
  • Correcting an entry

35
ML Example Defined data
  • E CS100 A1 00 02 03 06 02 02
  • .
  • E DS0200 23 01 25 00 00 00
  • .
  • To view code D CS100,105 ltRTNgt
  • To view data D DS200,205 ltRTNgt

36
An assembly Language Example
  • Assemble Command
  • A 100 ltRTNgt
  • MOV CL, 42
  • MOV DL,2A
  • ADD CL, DL
  • NOP

37
An assembly .. - Cont.
  • Unassemble command
  • U 100,106 ltRTNgt
  • xxxx0100 B142 MOV CL, 42
  • xxxx0102 B22A MOV DL, 2A
  • xxxx0104 00D1 ADD CL,DL
  • xxxx0106 90 NOP

38
More on Debug
  • If you are executing a program again within the
    DEBUG make sure to reset IP register to 100.
  • R IP
  • 100
  • Saving a program from within debug
  • use A or E to key in the code
  • N filename.COM
  • clear BX
  • replace CX with the size of the program
  • W
Write a Comment
User Comments (0)
About PowerShow.com