1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 4, 2014 Slides.

Slides:



Advertisements
Similar presentations
1 EECS 373 Design of Microprocessor-Based Systems Branden Ghena University of Michigan Lecture 3: Assembly, Tools, and ABI September 9, 2014 Slides developed.
Advertisements

ARM versions ARM architecture has been extended over several versions.
Code Composer Department of Electrical and Computer Engineering
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 3: ISA, Assembly, and Toolchains September 13, 2011.
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
© 2010 Kettering University, All rights reserved..
General information Course web page: html Office hours:- Prof. Eyal.
CS 300 – Lecture 19 Intro to Computer Architecture / Assembly Language C Coding & The Simulator Caches.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
EET 2261 Unit 2 HCS12 Architecture
Slides developed in part by Mark Brehob
Computer Architecture
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
ARM Core Architecture. Common ARM Cortex Core In the case of ARM-based microcontrollers a company named ARM Holdings designs the core and licenses it.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 1: Introduction January 9 th 2014 Slides developed in part.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 8, 2011 Slides.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 2: Architecture, Assembly, and ABI Sept. 5, 2013 Slides developed.
Instruction Set Architecture
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Instruction Set Architecture Assembly Language Programming Software.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 9, 2010.
Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Computer Architecture and Organization
ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory and Memory-Mapped I/O September 16, 2010.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 3: Toolchain, ABI, Memory Mapped I/O January 14 th, 2016 Slides.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September.
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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
List three things that distinguish embedded
Displacement (Indexed) Stack
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
A Closer Look at Instruction Set Architectures
ECE 3430 – Intro to Microcomputer Systems
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Chapter 4 Addressing modes
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
William Stallings Computer Organization and Architecture 8th Edition
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Slides developed in part by Prof. Dutta
ARM Assembly Programming
Slides developed in part by Mark Brehob
Topic 5: Processor Architecture Implementation Methodology
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Topic 5: Processor Architecture
Figure 2- 1: ARM Registers Data Size
Computer Architecture
COMS 361 Computer Organization
Slides developed in part by Mark Brehob
COMS 361 Computer Organization
Overheads for Computers as Components 2nd ed.
Program Assembly.
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 4, 2014 Slides developed in part by Mark Brehob

2 Announcements Website up – Homework 1 posted (mostly a 270 review) Lab and office hours posted on-line. –My office hours: Tuesdays 1:30-3:00 pm in 4773 BBB Projects –Start thinking about them now!

Today… Finish ARM assembly example from last time Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 3

4 Major elements of an Instruction Set Architecture (registers, memory, word size, endianess, conditions, instructions, addressing modes) 32-bits Endianess mov r0, #4 ldr r1, [r0,#8] r1=mem((r0)+8) bne loop subs r2, #1 Endianess

The endianess religious war: 288 years and counting! Modern version –Danny Cohen –IEEE Computer, v14, #10 –Published in 1981 –Satire on CS religious war Historical Inspiration –Jonathan Swift –Gulliver's Travels –Published in 1726 –Satire on Henry-VIII’s split with the Church Now a major motion picture! 5 Memory Value Offset (LSB) (MSB) ====== =========== uint8_t a = 1; 0x FF 00 uint8_t b = 2; uint16_t c = 255; // 0x00FF uint32_t d = 0x ; 0x Little-Endian –LSB is at lower address Big-Endian –MSB is at lower address Memory Value Offset (LSB) (MSB) ====== =========== uint8_t a = 1; 0x FF uint8_t b = 2; uint16_t c = 255; // 0x00FF uint32_t d = 0x ; 0x

Addressing: Big Endian vs Little Endian (370 slide) Endian-ness: ordering of bytes within a word –Little - increasing numeric significance with increasing memory addresses –Big – The opposite, most significant byte first –MIPS is big endian, x86 is little endian

Instruction encoding Instructions are encoded in machine language opcodes Sometimes –Necessary to hand generate opcodes –Necessary to verify assembled code is correct How? Refer to the “ARM ARM” Instructions movs r0, #10 movs r1, #0 ARMv7 ARM Register Value Memory Value 001|00|000| (LSB) (MSB) (msb) (lsb) 0a |00|001|

Assembly example data:.byte 0x12, 20, 0x20, -1 func: mov r0, #0 mov r4, #0 movw r1, #:lower16:data movt r1, #:upper16:data top: ldrb r2, [r1],#1 add r4, r4, r2 add r0, r0, #1 cmp r0, #4 bne top 8

Instructions used mov –Moves data from register or immediate. –Or also from shifted register or immediate! the mov assembly instruction maps to a bunch of different encodings! –If immediate it might be a 16-bit or 32-bit instruction Not all values possible why? movw –Actually an alias to mov “w” is “wide” hints at 16-bit immediate 9

From the ARMv7-M Architecture Reference Manual (posted on the website under references) 10 There are similar entries for move immediate, move shifted (which actually maps to different instructions) etc.

Directives #:lower16:data –What does that do? –Why? 11

12

Loads! ldrb -- Load register byte –Note this takes an 8-bit value and moves it into a 32-bit location! Zeros out the top 24 bits ldrsb -- Load register signed byte –Note this also takes an 8-bit value and moves it into a 32-bit location! Uses sign extension for the top 24 bits 13

Addressing Modes Offset Addressing –Offset is added or subtracted from base register –Result used as effective address for memory access –[, ] Pre-indexed Addressing –Offset is applied to base register –Result used as effective address for memory access –Result written back into base register –[, ]! Post-indexed Addressing –The address from the base register is used as the EA –The offset is applied to the base and then written back –[ ],

So what does the program _do_? data:.byte 0x12, 20, 0x20, -1 func: mov r0, #0 mov r4, #0 movw r1, #:lower16:data movt r1, #:upper16:data top: ldrb r2, [r1],#1 add r4, r4, r2 add r0, r0, #1 cmp r0, #4 bne top 15

Today… Finish ARM assembly example from last time Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 16

17 An ISA defines the hardware/software interface A “contract” between architects and programmers Register set Instruction set –Addressing modes –Word size –Data formats –Operating modes –Condition codes Calling conventions –Really not part of the ISA (usually) –Rather part of the ABI –But the ISA often provides meaningful support.

ARM Architecture roadmap 18 +M4 : DSP ISA

A quick comment on the ISA: From: ARMv7-M Architecture Reference Manual 19

20 ARM Cortex-M3 ISA Register SetAddress Space Branching Data processing Load/Store Exceptions Miscellaneous Instruction Set 32-bits Endianess

21 Mode dependent Registers SP_main (MSP) used by: -OS kernel -Exception handlers -App code w/ privileded access SP_process (PSP) used by: -Base app code (when not running an exception handler) Note: there are two stack pointers!

22 Address Space

23 Instruction Encoding ADD immediate

24

25 Branch

26 Data processing instructions Many, Many More!

27 Load/Store instructions

28 Miscellaneous instructions

Addressing Modes (again) Offset Addressing –Offset is added or subtracted from base register –Result used as effective address for memory access –[, ] Pre-indexed Addressing –Offset is applied to base register –Result used as effective address for memory access –Result written back into base register –[, ]! Post-indexed Addressing –The address from the base register is used as the EA –The offset is applied to the base and then written back –[ ],

options An immediate constant –#10 An index register – A shifted index register –, LSL # Lots of weird options…

31 ARMv7-M Architecture Reference Manual ARMv7-M_ARM.pdf

Application Program Status Register (APSR)

Updating the APSR SUB Rx, Ry –Rx = Rx - Ry –APSR unchanged SUBS –Rx = Rx - Ry –APSR N, Z, C, V updated ADD Rx, Ry –Rx = Rx + Ry –APSR unchanged ADDS –Rx = Rx + Ry –APSR N, Z, C, V updated

Overflow and carry in APSR unsigned_sum = UInt(x) + UInt(y) + UInt(carry_in); signed_sum = SInt(x) + SInt(y) + UInt(carry_in); result = unsigned_sum ; // == signed_sum carry_out = if UInt(result) == unsigned_sum then ’0’ else ’1’; overflow = if SInt(result) == signed_sum then ’0’ else ’1’; 34

Conditional execution: Append to many instructions for conditional execution

36 The ARM architecture “books” for this class

37 The ARM software tools “books” for this class

38... start: movs r0, #1 movs r1, #1 movs r2, #1 sub r0, r1 bne done movs r2, #2 done: b done... Exercise: What is the value of r2 at done?

39... start: movs r0, #1// r0  1, Z=0 movs r1, #1// r1  1, Z=0 movs r2, #1// r2  1, Z=0 sub r0, r1// r0  r0-r1 // but Z flag untouched // since sub vs subs bne done// NE true when Z==0 // So, take the branch movs r2, #2// not executed done: b done// r2 is still 1... Solution: What is the value of r2 at done?

Today… Finish ARM assembly example from last time Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 40

41 How does an assembly language program get turned into a executable program image? Assembly files (.s) Object files (.o) as (assembler) ld (linker) Memory layout Memory layout Linker script (.ld) Executable image file Binary program file (.bin) Disassembled code (.lst) objcopy objdump

42 What are the real GNU executable names for the ARM? Just add the prefix “arm-none-eabi-” prefix Assembler (as) –arm-none-eabi-as Linker (ld) –arm-none-eabi-ld Object copy (objcopy) –arm-none-eabi-objcopy Object dump (objdump) –arm-none-eabi-objdump C Compiler (gcc) –arm-none-eabi-gcc C++ Compiler (g++) –arm-none-eabi-g++

43 $ arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o How are assembly files assembled? $ arm-none-eabi-as –Useful options -mcpu -mthumb -o

44.equSTACK_TOP, 0x text.syntaxunified.thumb.global_start.typestart, %function _start:.wordSTACK_TOP, start start: movs r0, #10 movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end A “real” ARM assembly language program for GNU

45.equSTACK_TOP, 0x /* Equates symbol to value */.text/* Tells AS to assemble region */.syntaxunified/* Means language is ARM UAL */.thumb/* Means ARM ISA is Thumb */.global_start/*.global exposes symbol */ /* _start label is the beginning */ /*...of the program region */.typestart, %function/* Specifies start is a function */ /* start label is reset handler */ _start:.wordSTACK_TOP, start/* Inserts word 0x */ /* Inserts word (start) */ start: movs r0, #10/* We’ve seen the rest... */ movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end What’s it all mean?

46 all: arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o arm-none-eabi-ld -Ttext 0x0 -o example1.out example1.o arm-none-eabi-objcopy -Obinary example1.out example1.bin arm-none-eabi-objdump -S example1.out > example1.lst A simple (hardcoded) Makefile example

47 What information does the disassembled file provide?.equSTACK_TOP, 0x text.syntaxunified.thumb.global_start.typestart, %function _start:.wordSTACK_TOP, start start: movs r0, #10 movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end example1.out: file format elf32-littlearm Disassembly of section.text: : 0: word0x : word0x : 8:200a movsr0, #10 a:2100 movsr1, # c : c:1809 addsr1, r1, r0 e:3801 subsr0, #1 10:d1fc bne.nc : 12:e7fe b.n12 all: arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o arm-none-eabi-ld -Ttext 0x0 -o example1.out example1.o arm-none-eabi-objcopy -Obinary example1.out example1.bin arm-none-eabi-objdump -S example1.out > example1.lst

48 How does a mixed C/Assembly program get turned into a executable program image? Assembly files (.s) Object files (.o) as (assembler) gcc (compile + link) Memory layout Memory layout Linker script (.ld) Executable image file Binary program file (.bin) Disassembled Code (.lst) objcopy objdump ld (linker) Library object files (.o) C files (.c)

Today… Finish ARM assembly example from last time Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 49

50

ABI quote A subroutine must preserve the contents of the registers r4-r8, r10, r11 and SP (and r9 in PCS variants that designate r9 as v6). 51

52 Questions? Comments? Discussion?