EE2007 Microprocessor systems Tutorial 1 Semester 1 AY 2010-11 Ganesh Iyer ganesh.vigneswara@gmail.com (facebook, gtalk) http://ganeshniyer.com
About Me I have 3 years of Industry work experience in Bangalore, India. I have finished my masters from NUS in 2008. Currently doing PhD under the guidance of Assoc/Prof. Bharadwaj Veeravalli. Research interests: Cloud computing, Game theory, Wireless Networks Office: Computer Networks and Distributed Systems Lab, E4, Level 6, Room 12 Appointment: Details are available in my webpage: http://ganeshniyer.com Interests: Kathakali, Teaching, Travelling, Photography
(1a) Typical CPU architecture Macro view.
Introduction Bus Address bus Used to specify a physical address (memory and I/O) Data bus Carries data between CPU/memory, 8086 is 16 bit processor means data bus is 16 bit wide in 8086
Introduction Register High speed storage area inside CPU All data must be kept in register before processing 16 bit CPU means registers are 16-bit wide e.g. 8086 16-bit CPU, each register is 16 bit wide and each CPU instruction can manipulate 16 bit data
Introduction Executing a high level program High-level program (e.g. C, C++, JAVA) void main() { int a=10,b=20; --- } Object code Assembly code (e.g. 8086, pentium) MOV AX, 10 MOV BX,20 ----- Executable Binary (0 s and 1 s) 01010100011 10011101010 ----
(2) Memory components
(1b) Typical CPU architecture Micro view.
(7) Instruction Execution Fetching the instruction Store in Instruction Queue Decode the instruction Execute the instruction
(3) Memory map of IBM PC Vendor s Firmware No installed memory Video Display Memory Top of RAM (= 0x000A0000) ROM-BIOS Video-ROM VRAM Extended BIOS Data 64+ kbytes 128 kbytes Volatile Program Memory RAM Different Segments (CS,DS,ES, SS) are created here 1-MB 0x00007E00 0x00007C00 0x00000500 0x00000400 0x00000000 BOOT_LOCN RBDA IVT 512 bytes 256 bytes 1024 bytes
(5,12,13) Registers General Purpose Data Registers: AX Accumulator, interrupt, general use; BX Base addressing; CX Counter; and DX Data in I/O operations Segment Registers: CS Code segment : Program Instructions SS Stack segment : Stack DS Data segment : Data area ES Extra segment : General addressing, destination segment in string ops Pointers and Index Registers: SP Stack pointer : Current stack offset (SS) BP Base pointer : Base for referencing values stored on stack (SS) SI Source index : General addressing, source offset in string ops (DS) DI Destination index : General addressing, destination in string ops (ES) AX 16 bit AH 8 bits MSB AL 8 bits LSB
(4) Segments Code Segment (CS): Program instructions Data Segment (DS): Data residing Area Stack Segment (SS): Used as Stack Extra Segment (ES): Special purposes, usually with data in string manipulations 1MB of space is divided evenly into 16 logical segments (2 20 / 2 4 )= 2 16 = 2 6. 2 10 = 64Kbytes => each segment s length
(9) How much memory can be active at a given time in the 8088 microprocessor? 4 x 64K 4 segments = CS, DS, SS, and ES each of size 64K
(15) A data segment is to be located from address A0000 to AFFFF; what value must be loaded into DS? A000h
(6) If CS = 1253H, what is the starting physical address of your code/program? What will be loaded into the IP register prior to the execution of the first instruction? Describe the function of IP Starting Physical address = CS*10h+Offset IP: 0000H (IP is the offset) = 1253*10h+0000h = 12530h IP works on CS space by pointing to the instruction to be executed next; After an instruction is fetched by the CPU, during the execution of the current instruction, IP is incremented to point to the next instruction to be executed.
(10) If the current values in CS and IP are 0200 and 01AC respectively, what is the address of the next instruction? CS*10h+IP = 0200h*10h+01ACh = 02000+01AC = 021ACh
(8) Show how the double word 12345678 will be stored in memory starting at address A001. A004 12 A003 34 A002 56 A001 78
(14a) Flags in 8086
(14b) How are status flags used by software? Use as decision to branch to other parts of the program Eg: JC Jump Carry jump if CF = 1 JNZ Jump No Zero jump if ZF = 0
(16 & 17) Addressing Modes in 8086 with MOV example
(18) Load 1234H and 1200H in data registers and add them. Store the result in the register DX, Also store the result in a location whose offset is 1279H. - - - - - - MOV AX, 1234H MOV BX, 1200H ADD AX,BX MOV DX,AX MOV [1279H],AX - - - - - -
(11) What is stored at address FFFF0 and what is so important about this address? Reset Address Reset Address - is a pre-set address that all processors will point to each time the reset pin is active. There is a jump instruction at this location (ROM BIOS CHIP) that will point to the beginning of the ROM BIOS program.
DUP operator If you need to declare a large array you can use DUP operator. The syntax for DUP: number DUP ( value(s) ) number - number of duplicate to make (any constant value). value - expression that DUP will duplicate. Data1 db 6 DUP(10h) Fill 6 bytes with 10 Data2 db 10 DUP(?) Reserve 10 bytes Data4 db 3 DUP(00,01) 6 bytes of alternate 00,01
BONUS!!!! If the current values in CS and IP are 0200h and 01AEh respectively, what is the address of the next instruction? Address of next instruction = 10h*0200h + 01AEh = 021AEh where 10h* operation represents a left-shift of 1 hexadecimal digit or a left-shift of 4 bits. (16 in decimal = 10 in hexa)
BONUS!!! The last stored items in the stack are the following hexadecimal values: 08, FA, 14, 92, 5E, 38 (very last), etc. Assume SS=00E0h and SP=01CBh. What is the physical address of the location containing 38? Item 38 is at the top of the stack since it is stored very last. The physical address of top of the stack = SS: SP or 10h*SS + SP = 00E00 + 01CB = 00FCBh.
BONUS!!! The size of your memo.txt file on your 8088- based PC is 365 bytes. Suppose this file is placed at the memory address DS:SI = 1200:25FF, what should be the address of last byte of this file? The starting address of the file is 12000+25FF = 145FFh. 365 bytes in Hex is 16D bytes. The last byte of this file should locate at 145FF + 16D 1 = 1476Bh.
BONUS!!! Which flag determines whether the address for a string operation is incremented or decremented? And which flag determines if interrupt to the micro-processor is enabled? Direction flag DF, and the interrupt flag IF
BONUS!!! What are the word sizes of the 8086/8088 and the 80386? 16-bit and 32-bit, respectively.
Thank you! http://ganeshniyer.com