Lecture 6 Machine Code: How the CPU is programmed.

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

Chapter 2 (cont.) An Introduction to the 80x86 Microprocessor Family Objectives: The different addressing modes and instruction types available The usefulness.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Azir ALIU 1 What is an assembly language?. Azir ALIU 2 Inside the CPU.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
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.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
An Introduction to 8086 Microprocessor.
6.828: PC hardware and x86 Frans Kaashoek
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Types of Registers (8086 Microprocessor Based)
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
1 ICS 51 Introductory Computer Organization Fall 2009.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Functions/Methods in Assembly
Computers organization & Assembly Language Chapter 1 THE 80x86 MICROPROCESSOR.
University of Tehran 1 Microprocessor System Design Omid Fatemi Machine Language Programming
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
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.
1 x86 Programming Model Microprocessor Computer Architectures Lab Components of any Computer System Control – logic that controls fetching/execution of.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
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.
Assembly Language Addressing Modes. Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Stack Operations Dr. Hadi AL Saadi.
Assembly language.
Instruction set Architecture
Part of the Assembler Language Programmers Toolbox
Introduction to 8086 Microprocessor
Computer Organization & Assembly Language Chapter 3
Introduction to Compilers Tim Teitelbaum
Basic Microprocessor Architecture
Assembly IA-32.
University of Gujrat Department of Computer Science
Chapter 3 Addressing Modes
Basic of Computer Organization
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.
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
CS 301 Fall 2002 Computer Organization
MIPS Procedure Calls CSE 378 – Section 3.
Computer Architecture and the Fetch-Execute Cycle
The Microprocessor & Its Architecture
Symbolic Instruction and Addressing
Lecture 06 Programming language.
Computer Architecture CST 250
X86 Assembly Review.
CSC 497/583 Advanced Topics in Computer Security
Computer Architecture and System Programming Laboratory
Presentation transcript:

Lecture 6 Machine Code: How the CPU is programmed

Registers Intel: General Purpose, e.g. Pentium EAX register –There are also EBX, ECX, EDX registers, as above, all 32 bits –Intel processors are backwards compatible – so Pentiums can run programs which only use the old 8086 AX, BX.. sub-registers. Things like this are called Legacy issues. Intel: General purpose –EDI, ESI, EBP, ESP – all 32 bits and all with 8086 sub parts (DI,SI,BP,SP). The first 3 of these are generally used to set up relative or indexed addresses. The Stack Pointer ESP or SP is quite special and we will look at this separately. AX (16 bits, old 8086 size) AHAL (AH and AL are usable 8 bit sub-divisions of AX) EAX (32 bits, full Pentium size)

Registers (2) Intel: Control registers –PC Program counter – address of the next instruction (sometimes called IP) –SR Status register (each bit records some status info, eg for overflow). Sometimes called Condition Codes CC register. –MAR and MBR buffer registers for address or data used by the adress or datat bus. –IR buffer register for the current instruction Intel: Segment registers –CS, DS, SS segment addresses for code, data, stack –ES, FS, GS other segment registers Other processors from other manufactures have different register arrangements, e.g. the Power PC (IBM, Apple) has simply 32 general purpose 32 bit registers (along with the same kind of PC, SP and control registers etc)

Intel’s logical addressing system Intel has always divided memory into logical segments. This helps with organizing memory – different segments can be for different things e.g. machine code instructions can go in a code segment, data can go in data segments, the stack can use a stack segment and so on (and extra segments can be set by the programmer). So, for logical purposes, Intel addresses get divided into two parts a segment address and an offset address within the segment: e.g. 0151: 6F79 –There are segment registers (CS, DS etc) to keep track of the current segments being used. –A physical 32 bit address still has to be presented to the Address bus, so there is some translation to be done between Intel’s logical Segment:Offset address and a straight 32 bit physical address. NB Not all manufactures use the segmentation idea – e.g. in the Power PC all address are just simple 32 bit addresses – this gives flexibility – there is no pre-organisation of memory Address of the segment Offset from the start of the segment

Addressing modes All CPU’s provide a range of different addressing modes. These are flexible and convenient ways which allow programmers to access the correct data for their programs. Without these different addressing modes, programming would be hard (maybe sometimes impossible) and very inefficient. Knowing all about a particular CPU’s many addressing modes in detail is for fairly advanced machine code programmers. But all CPU’s share a few very similar basic addressing modes which any computer engineer should be reasonably familiar with, as follows: Register addressinge.g. MOV AX, BX Here the CPU doesn’t make any reference to memory but just works with its own registers Immediate addressinge.g. MOV DX, 45 Here the data needed is in the instruction itself (and so is in the Code Segment) and so the CPU again does not have to fetch anything from data memory (since it has already fetched the instruction). Direct or Absolute Addressinge.g. MOV BX, [1001] Here the address of the data in memory (in the Data Segment) is given in the instruction, so in this example the data at DS:1001 is copied to BX. Indirect addressinge.g. MOV AX, [BX] Here the address of the data is in another register. So here the CPU takes the value in BX, and uses it as an offset address in the Data Segment from which to copy data into AX.

A simple example

Stacks Provide temporary storage for things. –In our simple examples, just the return addresses for Sub-Routines and Interrupt Service Routines. –But in modern programming stacks are used very extensively – for example when a new object is created in Java (or in other OOP languages), all the variables and other information for the object is pushed onto a stack and accessed from there. The stack memory used can be re- used once the object is not needed any more. Are last in first out queues (LIFO) PUSH places bytes (2 bytes for 8086 or larger words depending on the computer) POP retrieves bytes (2 for 8086) from the stack Grow to lower memory Have a stack pointer (SP) for the address of the last byte added with a PUSH (and also the next byte that would be removed with a POP) PUSH decrements SP by 1, then stores the bytes identified in the PUSH instruction POP reads the bytes from the stack and then increments SP by 1 Remember the SP points to the bottom of the stack

Sub-routine call and return This example from Coope et al’s book uses three levels on the stack - each time a sub-routine is called, the address of the instruction to come back to is pushed onto the stack. This is called the Return Address (RA). Address LabelAssembler code comments // Code for the ‘main’ program CS:0500etcsome instruction before calling the PRINT_TAX sub-routine CS:0503CALL PRINT_TAXpushes RA (0506) onto stack, then sets IP to the to the first instruction of PRINT_TAX CS:0506 CARRY_ONetcthe next instructions after the call // Code for the PRINT_TAX subroutine CS:0600 PRINT_TAXCALL CALC_TAXpushes RA (0603), then sets IP to the to the first instruction of CALC_TAX. CS:0603 CALL PRINTpushes RA (0606), then sets IP to the to the first instruction of PRINT, a standard O/S sub- routine. Note that PRINT will itself end with a RET, and so will POP the 0606 address into IP, coming back to the next instruction, which is the RET of PRINT_TAX CS:0606 RETpops a new value for IP, to return from PRINT_TAX // Code for the CALC_TAX subroutine CS:0700 CALC_TAXMOV CX,175 CS:0706MUL CX CS:0709RET

Some machine code examples Example of an unconditional branch instruction (BRA) start:CALL read_user_input CALL calc_next_position CALL redraw_screen BRA start Example of a conditional branch (BNE. In this example, TABLE is an address in memory, in the DATA segment). LEA means Load the Effective Address. LEA BX,TABLE // copy the address of TABLE into BX MOV CX,10// use CX for a counter MOV AX,0// use AX for a running total loop:ADD AX,[BX] ADD BX,2// move address on to next part of table DEC CX CMP CX,0 BNE loop