Assembly Language Programming

Slides:



Advertisements
Similar presentations
CH10 Instruction Sets: Characteristics and Functions
Advertisements

Chapter 2 Instruction Set Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
INSTRUCTION SET ARCHITECTURES
SUPPLEMENTARY CHAPTER 2 Instruction Addressing Modes
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Memory Locatıons and Addresses (Week 3)
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
CSC 3210 Computer Organization and Programming Introduction and Overview Dr. Anu Bourgeois.
TK 2633 Microprocessor & Interfacing
Execution of an instruction
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Implementation of a Stored Program Computer
1 Instructions and Addressing
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
ECE 265 – LECTURE 4 The M68HC11 Address Modes 8/14/ ECE265.
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Module 10 Adapted By and Prepared James Tan © 2001.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Instruction Set Architecture
Machine Instruction Characteristics
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Chapter 5 A Closer Look at Instruction Set Architectures.
Chapter 2-2 Assembly Instructions Number Systems Number Systems Assembly Instructions Assembly Instructions Branch Branch Next Lecture Next Lecture  Addressing.
Execution of an instruction
Computer Architecture EKT 422
Computer Architecture Lecture 03 Fasih ur Rehman.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
In1210/01-PDS 1 TU-Delft Instructions and addressing.
COMPUTER ORGANISATION Sri.S.A.Hariprasad Sr.Lecturer R.V.C.E Bangalore.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Lecture 5 A Closer Look at Instruction Set Architectures Lecture Duration: 2 Hours.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
What is a program? A sequence of steps
ECE 447 Fall 2009 Lecture 4: TI MSP430 Architecture and Instruction Set.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Memory Access Instructions Load and Store Addressing Modes Memory Addressing. Base addressing mode. Load byte and store byte: lb, lbu, sb Address alignment.
1 Instructions and Addressing Course website:
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
A Closer Look at Instruction Set Architectures
A Closer Look at Instruction Set Architectures
8051 Addressing Modes The way, using which the data source or destination addresses are specified in the instruction mnemonic for moving the data, is.
Microcomputer Programming
A Closer Look at Instruction Set Architectures: Expanding Opcodes
Overview Introduction General Register Organization Stack Organization
Computer Organization and Assembly Language (COAL)
EECE-276 Fall 2003 Microprocessors & Microcontrollers II
ECE 445 CS1251 Computer Organization Carl Hamacher
Chapter 8 Central Processing Unit
68000 Architecture, Data Types and Addressing Modes
ECEG-3202 Computer Architecture and Organization
Introduction to Micro Controllers & Embedded System Design
CNET 315 Microprocessor & Assembly Language
A Closer Look at Instruction Set Architectures Chapter 5
Computer Instructions
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
ECEG-3202 Computer Architecture and Organization
8051 ASSEMBLY LANGUAGE PROGRAMMING
Assembly Language Programming
Central Processing Unit.
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Assembly Language Programming Introduction and Addressing Modes CEG 320/520: Computer Organization and Assembly Language Programming

Intro to Assembly Language: Goals Introduction to Assembly language Basic instructions: MOVE, ADD, EXT, etc. Operand size (B, W, L) Register Transfer Notation (RTN) Addressing Modes Register direct, immediate, absolute long, register indirect, indexed basic, autoincrement, autodecrement When to use the various modes. Assigned Reading HVZ Chapter 2.4, 2.5, 2.6, 3.8, 3.9, 3.10, 3.11 Reference: HVZ Appendix C CEG 320/520: Computer Organization and Assembly Language Programming

Introduction: Basic Instructions Instructions begin with a mnemonic which represents the operation to be performed. MOVE, ADD, SUB, CLR, etc. The mnemonic is followed by a character representing the length of the data to be operated on. Byte (B), Word (W), and Long Word (L) In most instructions, the instruction is followed by one or more operands. How an operand is interpreted depends on the information provided and the addressing mode used for that operand. CEG 320/520: Computer Organization and Assembly Language Programming

Introduction: A Few Example Instructions ADD/SUB/MUL/DIV/AND/OR source, dest Performs operation on dest and source and stores result in dest. NEG location Computes 2’s complement of value in location, then stores it into location. NOT location Computes complement of value in location, then stores it into location. CLR location Sets value of byte/word/long at location to 0. MOVE source, dest Moves value of source to dest location. CEG 320/520: Computer Organization and Assembly Language Programming

Assembly: Operand size Because the 68000 is capable of performing operations on bytes, words and long words: In 68000 assembly language, a size indicator is appended to the instruction mnemonic (W=word, B=byte, L=long word): MOVE.W, MOVE.B, MOVE.L, ADD.W, ADD.B, and ADD.L are examples of this. If the size indicator is omitted, a WORD operation is assumed. CEG 320/520: Computer Organization and Assembly Language Programming

Assembly: Common Instructions - Examples MOVE MOVE.L D1, D2 D2 = D1 Contents of long word in D1 is copied into D2. Destroys contents of D2! Contents of D1 do not change! ADD/SUB/MUL/DIV ADD.W D1, D2 D2 = D1 + D2 Sum of words in D1 and D2 is placed into D2. CEG 320/520: Computer Organization and Assembly Language Programming

Assembly: Common Instructions - EXT 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 EXT.W extends a byte to a word Bit 7 is copied into bits 8-15. EXT.L extends a word into a long word Bit 15 is copied into bits 16-31 CEG 320/520: Computer Organization and Assembly Language Programming

Assembly: Common Instructions - EXT Sign extension does not change the value of positive or negative 2’s complement numbers! 0000 0011 = 3 EXT.L : 0000 0000 0000 0011 = 3 1111 1101 = 3 EXT.L : 1111 1111 1111 1101 = 3 CEG 320/520: Computer Organization and Assembly Language Programming

Register Transfer Notation: Introduction Symbolic and precise way to describe the effect of an instruction. Example: MOVE D3,D2 The contents of register D3 are copied to register D2. A common notation to designate this is: D2  [D3] Brackets around D3 indicate “contents of” Left arrow indicates “receives” CEG 320/520: Computer Organization and Assembly Language Programming

Register Transfer Notation: Instructions DEST  Result SUB D5, D7 can be described by: D7  [D7] - [D5] ADD D2, $001004 Here, $001004 is a memory address. The same notation still suffices: $001004  [$001004] + [D2] CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Direct MOVE D2, D3 Register Direct: directly accesses the contents of the indicated register. RTN: D3  [D2] Most efficient addressing mode because it requires no memory access to fetch the operand. Uses: loop counters, accumulators, operation results of all kinds. The data is already in your mailbox, you just need to get it. CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Direct Examples Registers D2 $1234 5678 D3 $XXXX XX78 A0 $0000 2000 Register Direct: directly accesses the contents of the indicated register. MOVE.B D2, D3 Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2000 Registers D2 $1234 5678 D3 $XXXX 5678 A0 $0000 2000 MOVE.W D2, D3 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 A0 $0000 2000 MOVE.L D2, D3 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Absolute Long MOVE $001020, D2 Absolute Long: accesses the contents of the indicated memory location. RTN: D2  [$001020] Motorola 68k also provides an Absolute Short addressing mode, but we will not be using it. Uses: moving stored variables from memory into registers for processing, storing results back to memory. You know the actual address ($001020) of the data, so you need to get it from there. CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Absolute Long Examples Registers D2 $XXXX 1234 D3 $XXXX XXXX A0 $0000 2000 Absolute Long: accesses the contents of the indicated memory location. MOVE.W $002000, D2 Registers D2 $XXXX XXXX D3 A0 $0000 2000 Registers D2 $XXXX XX12 D3 $XXXX XXXX A0 $0000 2000 MOVE.B $002000, D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2000 MOVE.L $002000, D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Immediate MOVE #X, D2 Immediate: an actual number X is provided. RTN: D2  X Immediate value is assumed to be decimal unless indicated otherwise (ie by $ for hexadecimal or @ for octal). Uses: incrementing loop counters, working with immediate values. You know the actual value of the data CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Immediate Examples Registers D2 $XXXX XX0C D3 $XXXX XXXX A0 $0000 2000 Immediate: an actual number X is provided. MOVE.B #12, D2 Registers D2 $XXXX XXXX D3 A0 $0000 2000 Registers D2 $XXXX 0012 D3 $XXXX XXXX A0 $0000 2000 MOVE.W #$12, D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $0000 000C D3 $XXXX XXXX A0 $0000 2000 MOVE.L #12, D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Indirect MOVE (A0), D2 Register Indirect: accesses the contents of the memory location in the indicated register. Effective Address: [A0] RTN: D2  [[A0]] Uses: repeated access to the same memory location You have a friend (A0) who knows the address of the data. You can ask her where it is in memory, then get it from that location in memory. CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Indirect Examples Registers D2 $XXXX XX12 D3 $XXXX XXXX A0 $0000 2000 Register Indirect: accesses the contents of the memory location in the indicated register. MOVE.B (A0), D2 Registers D2 $XXXX XXXX D3 A0 $0000 2000 Registers D2 $XXXX 1234 D3 $XXXX XXXX A0 $0000 2000 MOVE.W (A0), D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2000 MOVE.L (A0), D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Indirect – Indexed Basic MOVE X(A0), D2 Indexed Basic: An index value X is added to the memory address in the indicated register to form the effective address, then the contents of the effective address are accessed. Effective Address: [A0] + X RTN: D2  [[A0] + X] X is a decimal integer index value Motorola 68k also provides an Indexed Full addressing mode, but we will not be using it. CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Indexed Basic Examples Registers D2 $XXXX ABCD D3 $XXXX XXXX A0 $0000 2002 Indexed Basic: An index value is added to the memory address to form the effective address. MOVE.W 2(A0), D2 Registers D2 $XXXX XXXX D3 A0 $0000 2002 Registers D2 $XXXX 1234 D3 $XXXX XXXX A0 $0000 2002 MOVE.W -2(A0), D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2002 MOVE.L -2(A0), D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Indexed Basic Example Struct Student { int grade1; int grade2; int grade3; }; Struct Student Joe, Bob, Mary; Avg_Joe = Joe.grade1 + Joe.grade2 + Joe.grade3; Avg_Joe = Avg_Joe / 3; Memory Address Value $002000 95 $002002 89 $002004 83 MOVE.L #002000, A0 CLR.L D1 ADD.W (A0), D1 ADD.W 2(A0), D1 ADD.W 4(A0), D1 DIV.W #3, D1 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Indirect – Post-increment MOVE (A0)+, D2 Post-increment or Autoincrement: Operand is accessed indirectly, then address register is incremented. Effective Address: the contents of A0 RTN: D2  [[A0]] A0  [A0] + the number of bytes accessed Increment size: BYTE = 1, WORD = 2, LONG = 4 Uses: moving through an array, popping from stack CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Post-increment Examples Registers D2 $XXXX XX12 D3 $XXXX XXXX A0 $0000 2001 Post-increment: Operand is accessed indirectly, then address register is incremented. MOVE.B (A0)+, D2 Registers D2 $XXXX XXXX D3 A0 $0000 2000 Registers D2 $XXXX 1234 D3 $XXXX XXXX A0 $0000 2002 MOVE.W (A0)+, D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2004 MOVE.L (A0)+, D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Register Indirect – Pre-decrement MOVE.W –(A0), D2 Pre-decrement or Autodecrement: Address register is decremented, then operand is accessed indirectly. Effective Address: (the contents of A0) – (number of bytes accessed) RTN: A0  [A0] – (number of bytes accessed) D2  [[A0]] Decrement size: BYTE = 1, WORD = 2, LONG = 4 Uses: moving through an array, pushing onto stack CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Pre-decrement Examples Registers D2 $XXXX XX78 D3 $XXXX XXXX A0 $0000 2003 Pre-decrement: Address register is decremented, then operand is accessed indirectly. MOVE.B -(A0), D2 Registers D2 $XXXX XXXX D3 A0 $0000 2004 Registers D2 $XXXX 5678 D3 $XXXX XXXX A0 $0000 2002 MOVE.W –(A0), D2 Memory $002000 $1234 $002002 $5678 $002004 $ABCD Registers D2 $1234 5678 D3 $XXXX XXXX A0 $0000 2000 MOVE.L –(A0), D2 CEG 320/520: Computer Organization and Assembly Language Programming

Addressing Modes: Post-increment/Pre-decrement In the 68000, the increment/decrement depends on the operand size Suppose A0 = $00002000 MOVE.B (A0)+,D0  A0 = $00002001 MOVE.W (A0)+,D0  A0 = $00002002 MOVE.L (A0)+,D0  A0 = $00002004 CEG 320/520: Computer Organization and Assembly Language Programming

Assembly Language: In-Class Exercises Assembly Language and Addressing Modes Exercise Big Endian (Memory) vs Little Endian (Registers) CEG 320/520: Computer Organization and Assembly Language Programming

Intro to Assembly Language: You Should Know… Introduction to Assembly language Basic instructions: MOVE, ADD, EXT, etc. Operand size (B, W, L) Register Transfer Notation Addressing Modes Register direct, immediate, absolute long, register indirect, indexed basic, autoincrement, autodecrement When to use the various modes Assigned Reading HVZ Chapter 2.4, 2.5, 2.6, 3.8, 3.9, 3.10, 3.11 Reference: HVZ Appendix C CEG 320/520: Computer Organization and Assembly Language Programming