Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.

Slides:



Advertisements
Similar presentations
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Advertisements

ARM versions ARM architecture has been extended over several versions.
F28PL1 Programming Languages Lecture 2: Assembly Language 1.
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
ARM Microprocessor “MIPS for the Masses”.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 1: Bits, bytes and a simple processor dr.ir. A.C. Verschueren.
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
TK 2633 Microprocessor & Interfacing
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
Chapter 2-2 Assembly Instructions Number Systems Number Systems Assembly Instructions Assembly Instructions Branch Branch Next Lecture Next Lecture  Addressing.
Execution of an instruction
Lecture 8: Control, Procedures, and the Stack CS 2011 Fall 2014, Dr. Rozier.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Unit-2 Instruction Sets, CPUs
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
F28HS2 Hardware-Software Interfaces Lecture 7: ARM Assembly Language 1.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – ARM Addressing Endianness, Loading, and Storing Data – Data Layout Struct Packing.
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
Lecture 10: Load/Store cont. and Integer Arithmetic CS 2011 Fall 2014, Dr. Rozier.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
Computer Architecture & Operations I
Computer Architecture & Operations I
GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language.
Chapter 15: Higher Level Constructs
Control Unit Lecture 6.
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Morgan Kaufmann Publishers
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Making Decisions and Writing Loops
Introduction to Assembly Language
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CSC 3210 Computer Organization and Programming
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Computer Instructions
ECE 3430 – Intro to Microcomputer Systems
Introduction to Microprocessor Programming
Overheads for Computers as Components 2nd ed.
Computer Architecture
Computer Architecture
Branch & Call Chapter 4 Sepehr Naimi
Introduction to Assembly Chapter 2
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr. Rozier (UM)

COURSE PLAN FOR TODAY 1.Lab 1 Introduction 2.Introduction to debugging with GDB 3.Introduction to Instructions 4.Lab 1 GDB demo

LAB 1

Lab 1: Binary Bomb Quick change to the syllabus – Due dates will now be the Monday before the next lab goes out. Gives everyone an automatic extension for all labs. Lab 1 is out today Due Monday, February 3 rd at 11:59pm.

Lab 1: Binary Bomb Your task is to solve a series of six stages by finding the password. You will get a unique compiled binary. You will need to disassemble this binary to find the passwords.

Lab 1: Binary Bomb If you enter a wrong password, the bomb will “explode” and notify us. The bomb has tamper proof protections. Do not try to run it on a non-lab computer, or it will notify us and abort! Each explosion deducts half a point from your lab score.

Lab 1: Binary Bomb Assignment PartPoints Phase 110 Phase 210 Phase 310 Phase 410 Phase 515 Phase 615 Write up10 Explosions-0.5 each 80 pts maximum score

Lab 1: Binary Bomb If you do things right, your bomb should never blow up! Think carefully! Use the debugger gdb to step through and analyze the program. – Figure out what the code is doing to check for a correct result, and how to pass the checks.

Lab 1: Binary Bomb Start early! The lab will not be easy! Bomb download site: – Bomb scoreboard: – ard ard

GDB: THE GNU DEBUGGER

gdb: The GNU Debugger Standard and portable debugger for Unix and Unix-like systems. – Originally written in 1986 – Very active tool. Three software releases in – Still the gold-standard for debugging Enables users to trace, alter, and execute computer programs in a controlled environment.

gdb: The GNU Debugger Most useful features – Step through program execution, line by line, or instruction by instruction. – Examine the values of variables and registers. – Trap system signals. – Set breakpoints to halt execution at any point. – Watch variables to see when they change.

gdb: The GNU Debugger Some commands – run – executes the program – break - sets a breakpoint at label – break * - sets a breakpoint at the address – print - prints the register’s value – stepi – step through one assembly instruction

gdb: The GNU Debugger Some commands – disas - disassemble the code at label. – continue – continue execution after halting at a breakpoint. – info [break| ] - give information about breakpoints or registers – info r – display the value of all registers – x/ - display the value stored at in the format specified by

gdb: The GNU Debugger We will show an example towards the end of class of the debugger in action.

BASIC INSTRUCTIONS

Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets – But with many aspects in common Early computers had very simple instruction sets – Simplified implementation Many modern computers also have simple instruction sets

MIPS vs ARMv6 The book uses the MIPS instruction set. We will be using ARMv6 in our labs. Both are RISC (reduced instruction set computer) architectures. – Many similarities.

MIPS Used in many embedded systems – Routers, gateways – Playstation 2 and PSP Invented by Prof John Hennessy at Stanford, the first RISC architecture.

ARM Introduced in 1985 Focused on low-power friendly operation. Since 2005, over 98% of all mobile phones had at least one ARM processor. Over 37 billion ARM processors in use in Rapidly becoming the dominant processor architecture in the world.

Instructions C code: – f = (g + h) – (i + j); Compile ARM code: – add r0, r3, r4 # temp t0 = g + h – add r1, r5, r6 # temp t1 = i + j – sub r2, r0, r1 # f = t0 – t1

Register Operands Instructions use registers for operands. Registers are extremely fast SRAM locations that are directly accessible by the processor. – Very fast, but very expensive, so very small.

Registers Each register holds a word (4 bytes). Registers r0-r12 are general purpose. NameFunctionNameFunction r0General Purposer8General Purpose r1General Purposer9General Purpose r2General Purposer10General Purpose r3General Purposer11General Purpose r4General Purposer12General Purpose r5General Purposer13Stack Pointer r6General Purposer14Link Register r7General Purposer15Program Counter

Registers Registers r13 – r15 have special purposes The PC, r15, is very dangerous. NameFunctionNameFunction r0General Purposer8General Purpose r1General Purposer9General Purpose r2General Purposer10General Purpose r3General Purposer11General Purpose r4General Purposer12General Purpose r5General Purposer13Stack Pointer r6General Purposer14Link Register r7General Purposer15Program Counter

Registers The register r13 holds the stack pointer – Also called sp – Points to a special part of memory called the stack. – More about this later.

Registers The register r14 holds the link register – Also called lr – Holds the value of a return address that allows for fast and efficient implementation of subroutines.

Registers The register r15 holds the program counter – Also called pc – Holds an address of an instruction. Keeps track of where your program is in its execution of machine code. – PC holds the address of the instruction to be fetched next.

Registers One additional register, the “current program status register” Four most significant bits hold flags which indicate the presence or absence of certain conditions …87654…0 NZCVReservedIFTMODE

Registers N – negative flag Z – zero flag C – carry flag V – overflow flag …87654…0 NZCVReservedIFTMODE

Registers N – set by an instruction if the result is negative (set equal to the two’s complement sign bit) N – negative flag Z – zero flag C – carry flag V – overflow flag …87654…0 NZCVReservedIFTMODE

Registers Z – set by an instruction if the result of the instruction is zero. N – negative flag Z – zero flag C – carry flag V – overflow flag …87654…0 NZCVReservedIFTMODE

Registers C – set by an instruction if the result of an unsigned operation overflows the 32-bit register. Can be used for 64-bit arithmetic N – negative flag Z – zero flag C – carry flag V – overflow flag …87654…0 NZCVReservedIFTMODE

Registers V – works the same as the C flag, but for signed operations. N – negative flag Z – zero flag C – carry flag V – overflow flag …87654…0 NZCVReservedIFTMODE

MORE ABOUT THESE LATER…

The Memory Hierarchy

Load-Store Architecture RISC architectures, like ARM and MIPS utilize a load-store architecture. Memory cannot be part of arithmetic operations. – Only registers can do this Access memory is through loads and stores.

Register Memory Architecture Featured on many CISC architectures, like x86 Allows direct access to memory by instructions.

Load Store and ARM Register space is pretty cramped!!! LoaD to a Register with LDR SToRe to memory with STR ldr, [ {, }] – Loads a byte from + into str, [ {, }] – Stores a byte from into +

Load Store and ARM Example – ldr r0, [r1,r2] Load data from location r1+r2 into r0. – ldr r0, =string Load data from label string into r0. Special cases exist, see ARM manual – Example: ldrb loads a single byte, padded with zeros.

Constants or Immediates Operands can contain registers, or immediate values. – An immediate is like a constant – Represent immediates as follows: #20 add r0, r1, #20 – adds 20 to the value of r1 and stores it in r0.

Arithmetic Instructions Addition – add, adc, adds, etc Subtraction – sub, sbc, rsb, subs, etc Multiply – mul, mla, etc

Move Instruction mov, – mov r0, r1 – copy the contents of r1 into r0. – mov r0, #20 – copy an immediate value of 20 into r0. mvn, – Move negative, negates operand before copying it.

Compare Instructions cmp, cmn, Don’t change the operands, update special status register flags. cmp – subtracts operand2 from operand1 and discards the result. cmn – adds operand2 to operand1 and discards the result.

Status Register Flags Compare instructions and the special “S” versions of instructions (adds, subs, movs) set the status register flags. Can be used with conditional suffixes to make conditionally executed instructions.

Conditional Execution Just as the special “S” suffix can be added to set status flags, other suffixes can be added to act on status flags.

EQ: Equal Z=1 Using the EQ suffix on an instruction will cause it to only be executed if the zero flag is set. cmp r0, Set flags based on r0-r1 adds r0, r1, Set flags based on r0 = r1 + r2 movs r0, Set flags based on r0 = r1

EQ: Equal Z=1 Using the EQ suffix on an instruction will cause it to only be executed if the zero flag is set. Example cmp r0, Set flags based on r0-r1 addeq r2, r0, Conditional addition

NE: Equal Z=0 Using the NE suffix on an instruction will cause it to only be executed if the zero flag is not set.

Other conditional suffixes VS – overflow set, V=1 VC – overflow clear, V=0 MI – minus set, N=1 PL – minus clear, N=0 CS – carry set, C=1 CC – carry clear, C=0 AL – always, unconditional NV – never, unconditional

Multiple Conditional Suffixes HI – higher (unsigned), C=1 and Z=0 – Unsigned greater than LS – lower (unsigned), C=0 and Z=1 – Unsigned less than GE – greater or equal (signed), N=1, V=1 OR N=0, V=0 – Signed greater than or equal to LT – less than (signed), N=1, V=0, OR N=0,V=1 – Signed less than

Multiple Conditional Suffixes GT – greater than (signed), N=1, V=1, OR N=0, V=0 AND Z=0 – Signed greater than LE – less than or equal (signed), N=1, V=0, OR N=0, V=1, OR Z=1 – Signed less than or equal to

LAB 1 GDB DEMO

WRAP UP

For next time Read Chapter 2, Sections 2.6 – 2.8 Learn about control, branch, loops, etc.