University of Tehran 1 Microprocessor System Design Omid Fatemi Machine Language Programming

Slides:



Advertisements
Similar presentations
Programming 8086 – Part IV Stacks, Macros
Advertisements

Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
There are two types of addressing schemes:
MICROPROCESSORS TWO TYPES OF MODELS ARE USED :  PROGRAMMER’S MODEL :- THIS MODEL SHOWS FEATURES, SUCH AS INTERNAL REGISTERS, ADDRESS,DATA & CONTROL BUSES.
Introduction to 8086 Microprocessor
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Princess Sumaya Univ. Computer Engineering Dept. د. بســام كحـالــه Dr. Bassam Kahhaleh.
Azir ALIU 1 What is an assembly language?. Azir ALIU 2 Inside the CPU.
Stack Memory H H FFFFF H FFFFE H SS 0105 SP 0008 TOS BOS BOS = FFFF = 1104F H H 1104F H.
Lecture 6 Machine Code: How the CPU is programmed.
The 8086 Assembly Programming Data Allocation & Addressing Modes
Princess Sumaya University
3-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Intel 8088 (8086) Microprocessor.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
80x86 Processor Architecture
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
The 8086 Microprocessor The 8086, announced in 1978, was the first 16-bit microprocessor introduced by Intel Corporation 8086 is 16-bit MPU. Externally.
An Introduction to 8086 Microprocessor.
Types of Registers (8086 Microprocessor Based)
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
University of Tehran 1 Microprocessor System Design Omid Fatemi 80x86 Addressing modes
8086 Internal Architecture
Computers organization & Assembly Language Chapter 1 THE 80x86 MICROPROCESSOR.
Intel 8086 (8088) Microprocessor Structure
MODULE 5 INTEL TODAY WE ARE GOING TO DISCUSS ABOUT, FEATURES OF 8086 LOGICAL PIN DIAGRAM INTERNAL ARCHITECTURE REGISTERS AND FLAGS OPERATING MODES.
Microprocessor Fundamentals Week 2 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
Internal Programming Architecture or Model
1 x86 Programming Model Microprocessor Computer Architectures Lab Components of any Computer System Control – logic that controls fetching/execution of.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
ΜComputer Structure μProcessor Memory Bus System I/O Ports.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Introduction to 8086 Microprocessor
8086 Microprocessor.
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
ADDRESSING MODES.
Intel 8086 MICROPROCESSOR Architecture.
Assembly Language Programming Part 2
ADDRESSING MODES.
University of Gujrat Department of Computer Science
Intel 8088 (8086) Microprocessor Structure
Chapter 3 Addressing Modes
Basic of Computer Organization
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Intel 8088 (8086) Microprocessor Structure
8086 Registers Module M14.2 Sections 9.2, 10.1.
CS-401 Computer Architecture & Assembly Language Programming
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Symbolic Instruction and Addressing
CNET 315 Microprocessor & Assembly Language
Lecture 06 Programming language.
Computer Architecture CST 250
Unit-I 80386DX Architecture
Chapter 6 –Symbolic Instruction and Addressing
Process.
CSC 497/583 Advanced Topics in Computer Security
Intel 8086.
Presentation transcript:

University of Tehran 1 Microprocessor System Design Omid Fatemi Machine Language Programming

University of Tehran 2 Review Microprocessors History Numbering systems & arithmetic operations Micro architecture Programs

University of Tehran 3 Outline Programs for 80x86 Machine language, Assembly, … Registers, segments Instruction set Simple program

University of Tehran 4 Microprocessors They accept programs

University of Tehran /8 Internal Organization ALU AH BH CH AL BL CL DL BP DI SI SP DH FLAGS Internal Data Bus EU ADD CS ES SS DS IP Addr generation Bus Controller Instruction Queue BIU Data BusAddress Bus Processor Model

University of Tehran 6 Registers (Temporary Storage) One or two bytes 8-bit register: 16-bit register: Registers: –AX, BX, CX, DX –AH, AL, BH, BL, CH, CL, DH, DL D15 D14 D2 D1 D0 015 D7D2 D1 D0 07

University of Tehran 7 Registers by Category CategoryBitsRegister Names General16AX, BX, CX, DX 8AH, AL, BH, BL, CH, CL, DH, DL Pointer16SP (stack pointer), BP (base pointer) Index16SI (source index), DI (destination index) Segment16CS (code segment), DS (data segment), SS (stack segment), ES (extra segment) Instruction16IP (instruction pointer) Flag16FR (flag register)

University of Tehran 8 Assembly Programming CPU works in binary All instructions, data are in binary Binary instructions (0, 1) are Machine Language –Or even hexadecimal representation Assembly language –Mnemonics –Low level Assembler Linker

University of Tehran 9 Assembler versus Machine Code ADDAX, BX;AX gets value AX+BX SUBAX, BX;AX gets value AX-BX ANDAX, BX;AX gets bitwise AND of AX and BX INCAX;AX gets its original value plus 1 DECBX;BX gets its original value minus 1 MOVAX, BX;AX gets values in BX 01 D8 29 D8 21 D8 40 4B 8B C3 01 D8 29 D8 21 D8 40 4B 8B C3 01 D8 29 D8 21 D8 40 4B 8B C3 a19fe a19ff a1a00 a1a01 a1a02 a1a03 a1a04 a1a05 a1a06 a1a07 93ee:db1e 93ee:db1f 93ee:db20 93ee:db21 93ee:db22 93ee:db23 93ee:db24 93ee:db25 93ee:db26 93ee:db27 logical address physical memory physical address ASSEMBLER LINKERLOADER

University of Tehran 10 MOV Instructions MOV instruction –MOV des, src; copy source to destination –Examples: »MOV CL,55H »MOV DL, CL »MOV AH, DL »MOV CX,EF28H »MOV AX, CX »MOV DI, AX »MOV BP,DI –No MOV for flag register –No immediate load to segment register (only registers) –Same size (destination and source)

University of Tehran 11 ADD Instruction ADD instruction –ADD des, src; add the source to destination –Examples: »MOV AL,55H »MOV CL,23H »ADD AL,BL; »MOV DH,25H »ADD DH,34H; immediate operand »MOV CX,345H »ADD CX,679H –No MOV for flag register –No immediate load to segment register (only registers) –Same size (destination and source)

University of Tehran 12 Debug program R A U or U G T F or F D or D E

University of Tehran 13 Program Segments Code Data Stack 80x86 segment registers –DS, CS, SS, ES Logical address, physical address –Physical: 20bit –Offset: 16 bit –Logical: segment+offset How to convert? Examples of code and data segments Memory Map of IBM PC

University of Tehran 14 Segmented Memory CS ES SS DS Data Segment Stack Segment Extra Segment Code Segment Registers Logical, Segmented Address: 0FE6:012Bh Offset, Index Address: 012Bh Physical Address: 0FE60h  Bh  299 0FF8Bh  System Memory 00000h FFFFFh

University of Tehran 15 The Stack The stack is a memory area intended for storing temporary values. The stack is accessed by the SS:SP segment/offset combination (StackSegment: StackPointer) Some instructions make use of the stack area during execution (push, pop, call, ret, many others) If you need to store temporary values in memory, the stack is the best place to do so.

University of Tehran 16 Data Storage via the Stack The word ‘stack’ is used because storage/retrieval of words in the stack memory area is the same as accessing items from a stack of items. Visualize a stack of boxes. To build a stack, you place box A, then box B, then box C. AA B A B C Notice that you only have access to the last item placed on the stack (the Top of Stack – TOS). You retrieve the boxes from the stack in reverse order (C then B then A).

University of Tehran 17 Storing data on X86 stack via PUSH The SP (Stack Pointer) register is used to access items on the stack. The SP register points to the LAST value put on the stack. The PUSH operation stores a value to the stack: PUSH AX ; SP= SP-2, M[SP]  AX The “push AX” instruction is equivalent to: sub SP, 2 ; decrement SP by 2 for word operation mov [SP], AX ; write value to stack. Stack access only supports 16-bit or 32-bit operations

University of Tehran 18 Visualizing the PUSH operation lastval ue ???? high memory low memory  SP before PUSH AX lastval ue ahal ???? high memory low memory  SP (new SP = old SP-2) after PUSH AX View memory as being 16 bits wide since stack operations are always 16 bit or 32 bits.

University of Tehran 19 Multiple Pushes lastval ue ???? high memory low memory  SP before lastval ue ax bx cx ???? high memory  SP after all pushes PUSH AX PUSH BX PUSH CX low memory

University of Tehran 20 Reading Data from X86 stack via POP The POP operation retrieves a value from the stack: POP AX ; AX  M[SP], SP= SP+2 The “pop AX” instruction is equivalent to: mov AX, [SP] ; read value from top of stack add sp, 2 ; increment SP by 2 for word operation

University of Tehran 21 Visualizing the POP operation FF65 23AB ???? high memory low memory  SP before POP AX FF65 23AB ???? high memory low memory  SP AX = 23AB after POP AX View memory as being 16 bits wide since stack operations are always 16 bit or 32 bits.

University of Tehran 22 Visualizing multiple POP operations FF65 23AB 357F D21B 38AC 23F4 ???? high memory low memory  SP before FF65 23AB 357F D21B 38AC 23F4 ???? high memory low memory  SP AX = 38AC BX = D21B CX = 357F after all POPs pop AX pop BX pop CX

University of Tehran 23 Stack Overflow, Underflow If you keep pushing data on the stack without taking data off the stack, then the stack can eventually grow larger than your allocated space –Can begin writing to memory area that your code is in or other non-stack data –This is called stack OVERFLOW If you take off more data than you placed on the stack, then stack pointer can increment past the ‘ start ’ of the stack. This is stack UNDERFLOW. Bottom line: You should allocate sufficient memory for your stack needs, and pop off the same amount of data as pushed in.

University of Tehran 24 Stack (summary) Temporary storage Segment and pointer SS:SP Push and Pop (LIFO) SP : top of the stack After push SP is decremented

University of Tehran 25 Homework 1 Problems: 12,13,14,15,16 chapter 0 of Mazidi (Volume I) Problems: 14,16,18,19 chapter 1 of Mazidi (Volume I)

University of Tehran 26 Summary Programs for 80x86 Machine language, Assembly, … Registers, segments Instruction set Debug program Stack Good News: No class on Monday