Docsity

Programming - Introduction to Microprocessor Systems - Lecture Sli, Lecture notes of Computer Science

Partial preview of the text

Download Programming - Introduction to Microprocessor Systems - Lecture Sli and more Lecture notes Computer Science in PDF only on Docsity!

• ARM7TDMI Programming

– LUTs

– Branches and Loops

• Structured Programming

– Flowcharts

• Stacks

– Hardware versus Memory Stacks

– ARM7TDMI Stack Management

Topics

Look-Up Tables

• In an embedded system, the code area is usually

in nonvolatile memory (ROM)

• Data in the code area will also be placed in ROM

– so the data is constant

• Look-up tables (LUTs) are used to translate a

value from one domain to another when…

– There is no convenient mathematical relationship

between the two domains

– The calculations are too expensive for the

application constraints

Branches

• Branches redirect program flow by loading a new PC

value

– In many processors, a branch that does not return is called

a jump

• ARM7TDMI branch instructions

– B target_address

• Target_address is a label

• Instruction encodes a signed 24-bit offset

– BX

• Branch address is in a register

• Can be used to jump to Thumb code

• Jump tables

– Be sure index is bounds-checked!

Conditional Branches and Looping

  • Conditional branches allow program flow to change

in response to conditions

  • Action is based on current state of flags
  • Prior instruction must be used to set flags
  • Can use backwards conditional jumps to create a

loop that can be terminated -

  • By a condition
  • After a predetermined number of iterations
  • Or a combination of both
  • Looping examples
  • Incrementing loops
  • Decrementing loops

Stack Implementation

• The stack is a LIFO data structure

• What is the stack used for?

• Two basic stack operations

– PUSH

– POP (aka PULL)

• Hardware stacks vs. memory stacks

– Hardware stack

– Memory stack

• Stack pointer (SP)

• Stack topologies and SP operation

ARM7TDMI Stack Operation

• By convention, the stack pointer is R

• ARM stack terminology

– Empty versus full

– Ascending versus descending

• Allocating stack space

– SP initialization

• Stack operations

– LDR/STR

– LDM/STM

– PUSH/POP

• ARM operating modes and stacks

PIC16F84 Hardware Stack

Jump Tables

start

MOV R0, ??? ; assume index is in R

ADR R1, jmptbl ; get base address

LDR R0, [R1,R0,LSL #2] ; do look-up

BX R0 ; branch to target

task0 ; stub

NOP

B start

task1 ; stub

NOP

B start

jmptbl DCD task0, task1; ...

BL Instruction Reference

• Syntax

– BL{} <target_address>

• RTL

– if (cond is true)

• R14  next instruction address

• PC  PC + offset

• Flags are not affected

cond 1 0 1 1 signed_immediate_

BX Instruction Reference

• Syntax

– BX{}

• RTL

– if (cond is true)

• T flag  Rm[0]

• PC  Rm & 0xFFFFFFFE

• Flags are not affected

• In ARM v5 and higher, there is also a BLX instruction

cond 0 0 0 1 0 0 1 0 SBO SBO SBO 0 0 0 1 Rm