Embedded Systems Programming

Slides:



Advertisements
Similar presentations
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 4.
Advertisements

Computer Science Education
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.
ARM versions ARM architecture has been extended over several versions.
Appendix D The ARM Processor
Overheads for Computers as Components 2nd ed.
Embedded Systems Architecture
Multiplication – Microprocessor
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
© 2000 Morgan Kaufman Overheads for Computers as Components ARM instruction set zARM versions. zARM assembly language. zARM programming model. zARM memory.
Chapter 2 Instruction Sets 金仲達教授 清華大學資訊工程學系 (Slides are taken from the textbook slides)
1 ECE 5465 Advanced Microcomputers Group 11: Brian Knight Benjamin Moore Alex Williams.
Embedded System Design Center ARM7TDMI Microprocessor Data Processing Instructions Sai Kumar Devulapalli.
SPARC Architecture & Assembly Language
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
ARM Microprocessor “MIPS for the Masses”.
Thumb Data Processing Instructions and Breakpoint Instructions 02/18/2015 Mingliang Ge Yi (Leo) Wu Xinuo (Johnny) Zhao.
Embedded Systems Programming ARM assembler. Creating a binary from assembler source arm=linux-as Assembler Test1.S arm-linux-ld Linker Arm-boot.o Executable.
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.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
ARM Assembly Programming Computer Organization and Assembly Languages Yung-Yu Chuang 2007/11/19 with slides by Peng-Sheng Chen.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Lecture 4. ARM Instructions Prof. Taeweon Suh Computer Science & Engineering Korea University COMP427 Embedded Systems.
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION – ARM
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Unit-2 Instruction Sets, CPUs
Lecture 4: Load/Store Architectures CS 2011 Fall 2014, Dr. Rozier.
Arithmetic and Logic Chapter 5
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
ARM Shifts, Multiplies & Divide??. MVN Pseudo Instructions Pseudo Intruction: Supported by assembler, not be hardware.
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.
ARM Instruction Set Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
Revision questions CENG2400 v.14b 1 CENG2400 Revision, Question 1 A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module.
Smruti Ranjan Sarangi, IIT Delhi Chapter 4 ARM Assembly Language
ARM Assembly Language Programming
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Assembly Language Assembly Language
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
EE 319K Introduction to Embedded Systems
Processor Instructions set. Learning Objectives
Chapter 4 Addressing modes
Arithmetic and Logic Chapter 5
ARM Memory.
Architecture CH006.
Topic 6: Bitwise Instructions
Multiplication by small constants (pp. 139 – 140)
Arithmetic and Logic Chapter 5
Optimizing ARM Assembly
The ARM Instruction Set
Computer Organization and Assembly Languages Yung-Yu Chuang 2008/11/17
CORTEX-M0 Structure Discussion 1
Branching instructions
Overheads for Computers as Components 2nd ed.
Computer Architecture
CS501 Advanced Computer Architecture
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
Introduction to Assembly Chapter 2
An Introduction to the ARM CORTEX M0+ Instructions
Arithmetic and Logic Chapter 3
Presentation transcript:

Embedded Systems Programming ARM assembler

@ A simple input output program using the StrongARM uart @ ----------------------------------------------------------------------- @ Constant values used in this program .set SP1, 0x80010000 @ Base of the Microcontroller I/O space .set UTDR, 0x14 @ Offset to the Serial Data Register .set UTSR0, 0x1c @ Offset to SP status reg 0 .set UTSR1, 0x20 @ Offset to the Serial Status port .set UTSR1_TNF, 0b00000100 @ Mask to check Tx FIFO Not Full .set UTSR1_RNE, 0b00000010 @ Mask to check Rx FIFO Not Empty .set UTSR1_TBY, 0b00000001 @ Mask to check Tx Busy @ ----------------------------------------------------------------------- @ Assembly-language preamble .text @ Executable code follows .balign 4 .global _start @ "_start" is required by the linker .global main @ "main" is our main program _start: b main

@ ----------------------------------------------------------------------- @ Start of the main program main: ldr r1, =SP1 @ Use R1 as a base register for uart @ Read a character from the internal serial port 1: ldrb r0, [r1, #UTSR1] @ Read the Serial Status port tst r0, #UTSR1_TNF @ Check if a character is available beq 1b @ No: wait until a character comes in ldrb r0, [r1, #UTDR] @ Read the actual character into R0 @ Send the character to the internal serial port wb1: ldrb r2, [r1, #UTSR1] @ Check the Serial Status port again tst r2, #UTSR1_TNF @ Can a character be sent out? beq wb1 @ No: wait until port is ready strb r0, [r1, #UTDR] @ Send the actual character out b 1b @ Do this forever (or until stopped) @ ----------------------------------------------------------------------- .end

The example assembler program Layout is very important Labels must come first & use a colon : Followed by instructions Followed by comments Separate comments start with @ sign

Pseudo operands There are 2 general types of data in an assembler program Instructions Pseudo operands Instructions which directly generate code mov r0, #10 Pseudo operands which don’t. .text .balign 4

Pseudo operands .ascii & asciz .balign n^2 .code 16|32 Create an ascii string + 0 byte .balign n^2 Align address by n^2 bytes .code 16|32 Set instruction for Thumb or ARM .include <filename> .macro <name> arg1, arg2, argn Create a macro with args Ended with .endm

Pseudo operands .section <section name> {flags} Sections are .text, .data .bss .set var_name, value Set variable to value – same as .equ .rept N Repeat block N times end with .endr .word word1, word2, wordn Insert a list of 32 bit words

ARM data instructions Basic format: Immediate operand: ADD r0,r1,r2 Computes r1+r2, stores in r0. Immediate operand: ADD r0,r1,#2 Computes r1+2, stores in r0.

ARM data instructions ADD, ADC : add (w. carry) SUB, SBC : subtract (w. carry) RSB, RSC : reverse subtract (w. carry) MUL, MLA : multiply (and accumulate) AND, ORR, EOR BIC : bit clear LSL, LSR : logical shift left/right ASL, ASR : arithmetic shift left/right ROR : rotate right RRX : rotate right extended with C

Data operation varieties Logical shift: fills with zeroes. Arithmetic shift: fills with ones. RRX performs 33-bit rotate, including C bit from CPSR above sign bit.

ARM comparison instructions CMP : compare CMN : negated compare TST : bit-wise AND TEQ : bit-wise XOR These instructions set only the NZCV bits of CPSR.

ARM move instructions MOV, MVN : move (negated) MOV r0, r1 ; sets r0 to r1

ARM load/store instructions LDR, LDRH, LDRB : load (half-word, byte) STR, STRH, STRB : store (half-word, byte) Addressing modes: register indirect : LDR r0,[r1] with second register : LDR r0,[r1,-r2] with constant : LDR r0,[r1,#4]

ARM ADR pseudo-op Cannot refer to an address directly in an instruction. Generate value by performing arithmetic on PC. ADR pseudo-op generates instruction required to calculate address: ADR r1,FOO

Example: C assignments x = (a + b) - c; Assembler: ADR r4,a ; get address for a LDR r0,[r4] ; get value of a ADR r4,b ; get address for b, reusing r4 LDR r1,[r4] ; get value of b ADD r3,r0,r1 ; compute a+b ADR r4,c ; get address for c LDR r2,[r4] ; get value of c SUB r3,r3,r2 ; complete computation of x ADR r4,x ; get address for x STR r3,[r4] ; store value of x

Example: C assignment C: Assembler: ADR r4,a ; get address for a z = (a << 2) | (b & 15); Assembler: ADR r4,a ; get address for a LDR r0,[r4] ; get value of a MOV r0,r0,LSL 2 ; perform shift ADR r4,b ; get address for b LDR r1,[r4] ; get value of b AND r1,r1,#15 ; perform AND ORR r1,r0,r1 ; perform OR ADR r4,z ; get address for z STR r1,[r4] ; store value for z

Additional addressing modes Base-plus-offset addressing: LDR r0,[r1,#16] Loads from location r1+16 Auto-indexing increments base register: LDR r0,[r1,#16]! Post-indexing fetches, then does offset: LDR r0,[r1],#16 Loads r0 from r1, then adds 16 to r1.

ARM flow of control All operations can be performed conditionally, testing CPSR: EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE Branch operation: B #100 Can be performed conditionally.

Example: if statement C: Assembler: if (a > b) { x = 5; y = c + d; } else x = c - d; Assembler: ; compute and test condition ADR r4,a ; get address for a LDR r0,[r4] ; get value of a ADR r4,b ; get address for b LDR r1,[r4] ; get value for b CMP r0,r1 ; compare a < b BLE fblock ; if a ><= b, branch to false block

If statement, continued ; true block MOV r0,#5 ; generate value for x ADR r4,x ; get address for x STR r0,[r4] ; store x ADR r4,c ; get address for c LDR r0,[r4] ; get value of c ADR r4,d ; get address for d LDR r1,[r4] ; get value of d ADD r0,r0,r1 ; compute y ADR r4,y ; get address for y STR r0,[r4] ; store y B after ; branch around false block

If statement, continued ; false block fblock ADR r4,c ; get address for c LDR r0,[r4] ; get value of c ADR r4,d ; get address for d LDR r1,[r4] ; get value for d SUB r0,r0,r1 ; compute a-b ADR r4,x ; get address for x STR r0,[r4] ; store value of x after ...

Example: Conditional instruction implementation ; true block MOVLT r0,#5 ; generate value for x ADRLT r4,x ; get address for x STRLT r0,[r4] ; store x ADRLT r4,c ; get address for c LDRLT r0,[r4] ; get value of c ADRLT r4,d ; get address for d LDRLT r1,[r4] ; get value of d ADDLT r0,r0,r1 ; compute y ADRLT r4,y ; get address for y STRLT r0,[r4] ; store y

Conditional instruction implementation, continued. ; false block ADRGE r4,c ; get address for c LDRGE r0,[r4] ; get value of c ADRGE r4,d ; get address for d LDRGE r1,[r4] ; get value for d SUBGE r0,r0,r1 ; compute a-b ADRGE r4,x ; get address for x STRGE r0,[r4] ; store value of x