Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.

Similar presentations


Presentation on theme: "ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh."— Presentation transcript:

1 ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh

2 2 ARM University Program Copyright © ARM Ltd 2013 Acknowledgement Some slides from ARM University Program lab-in-a- box Copyright acknowledged

3 Outline Aims ARM processor and registers ARM instructions Issues for compilation –Code size  instruction length –Memory use: read or write? –Location Example compilation

4 Aims Learn to read ARM assembly code in overview Most programmers do not write assembly code but … Reading helpful for –Optimising speed (occasionally) –Debugging Illustrative not comprehensive –Look up opcodes as required

5 Core Concepts (Recap) Variable – location in memory Code processes –Addresses – get the right variable –Data – get the right value Control flow – if, loops, subroutines –Go to correct address –Branch –… or call / return

6 ARM Architecture

7 Microcontroller vs. Microprocessor Both have a CPU Microcontroller has peripherals –Analog –Digital –Timing –Clock generators –Communications point to point network –Reliability and safety

8 Cortex-M0+ Core

9 ARM Processor Core Registers

10 ARM Processor Core Registers (32 bits each) R0-R12 - General purpose, for data processing SP - Stack pointer (R13) –Can refer to one of two SPs Main Stack Pointer (MSP) Process Stack Pointer (PSP) LR - Link Register (R14) –Holds return address when called with Branch & Link instruction (B&L) PC - program counter (R15)

11 ARM Instructions ARM Architecture

12

13 Instruction Set Summary Instruction TypeInstructions MoveMOV Load/StoreLDR, LDRB, LDRH, LDRSH, LDRSB, LDM, STR, STRB, STRH, STM Add, Subtract, Multiply ADD, ADDS, ADCS, ADR, SUB, SUBS, SBCS, RSBS, MULS CompareCMP, CMN LogicalANDS, EORS, ORRS, BICS, MVNS, TST Shift and RotateLSLS, LSRS, ASRS, RORS StackPUSH, POP Conditional branchIT, B, BL, B{cond}, BX, BLX ExtendSXTH, SXTB, UXTH, UXTB ReverseREV, REV16, REVSH Processor StateSVC, CPSID, CPSIE, SETEND, BKPT No OperationNOP HintSEV, WFE, WFI, YIELD

14 Code Size and Thumb 32 bit processor –Longer addresses –Larger code Thumb and thumb-2 –Most instructions 16 bits –High code density

15 Load/Store Register ARM is a load/store architecture, so must process data in registers, not memory LDR: load register from memory –LDR, source address STR: store register to memory –STR, destination address

16 Addressing Memory Offset Addressing –[, ] accesses address + –Base Register can be register R0-R7, SP or PC is added or subtracted from base register to create effective address –Can be an immediate constant –Can be another register, used as index Auto-update –Write effective address back to base register –Pre-indexing –Post-indexing

17 Example

18 void redOn(void) { // set red on without changing anything else // LED is actve low PTB->PCOR |= MASK(RED_LED_POS) ; }

19 Summary Addresses in code Loaded using PC offset addressing Ok to read assembly code


Download ppt "ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh."

Similar presentations


Ads by Google