1 of 12

EE 319K�Introduction to Embedded Systems

Lecture 6b:�Exam 1 Review

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

6-1

2 of 12

Agenda

  • Exam 1
    • Exam 1, Fri 3/4 7-8:30pm.
    • You MUST upload your solution by 8:30pm.

  • Topics
    • Memory access
    • Registers and stack
    • Arithmetic operations
    • Shift operations
    • Logic operations
    • Control structures
    • Functions
    • Arrays

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

6-2

3 of 12

Exam 1 What to study?

  • Videos (posted on Canvas pages)
    • 2) video on AAPCS
    • 4) two videos on arrays
  • Book sections 1.11, 2.4.6-2.4.10, 4.4
  • eBook sections 7.5, 9.1, 9.3, 9.4, 9.5
  • Worksheets
    • WS_02.doc (Q4,Q5,Q6,Q10)
    • WS_04.doc (Q1,Q2,Q5, Q6)
    • WS_05.doc (all but Q10,Q11)
  • Four practice exams
  • Familiarize reference sheet/back of book

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

Do at least one to install LM3S pack

6-3

4 of 12

Exam 1 Process

  • download zip file with project, unzip
  • open project in Keil 5.x
  • add your EID into code in exam1.s file
  • run in simulator, see low grade
  • edit exam1.s, build, debug over and over until time is up or get a 100
  • Right-click the UART window, select all and execute Copy to clipboard, paste into appropriate field of the Exam 1 on Canvas.
  • upload your exam1.s assembly file in the assignments section on Canvas

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

6-4

5 of 12

Memory Access

  • Signed or Unsigned
  • 8/16/32 bits
    • LDRB
    • LDRSB
    • LDRH
    • LDRSH
    • LDR

    • STRB
    • STRH
    • STR

What do the following instructions do?

LDRH R1,[R2]

LDRH R1,[R2,#2]

LDRH R1,[R2],#2

LDRH R1,[R2,#2]!

What is the difference?

LDR R0,=100

MOV R0,#100

6-5

6 of 12

AAPCS, Registers and stack

  • Save LR before calling another function

  • Input parameters in R0,R1,R2,R3
  • Output parameter in R0
  • Balance the stack
  • PUSH {R4,R5} same as PUSH {R5,R4}
  • Freely use R0,R1,R2,R3,R12
  • Save, use, restore R4-R11

Fun1 PUSH {R4,LR}

BL Fun2

POP {R4,PC}

Fun3 PUSH {R4-R11}

;stuff using R4-R11

POP {R4-R11}

BX LR

6-6

7 of 12

Arithmetic, logical, shift

ADD

SUB

SUBS

MUL

SDIV

UDIV

LSL

LSR

ASR

AND

ANDS

ORR

BIC

EOR

How do you tell what operands are possible?

ADD R0,R1,#3

AND R0,R1,#3

MUL R0,R1,#3

UDIV R0,R1,#3

LSL R0,R1,#3

6-7

8 of 12

Control Operations

  • If-then

  • If-then-else

  • Do-while

  • While

CMP R0,#0

Bxx Target

CMP R0,#0

Bxx Yes

No ;not true

;

B done

Yes ;true

;

done

loop

;body

CMP R0,#0

Bxx loop

loop CMP R0,#0

Bxx done

;body

B loop

done

BEQ

BNE

BLO

BLS

BHI

BHS

BEQ

BNE

BLT

BLE

BGT

BGE

6-8

9 of 12

Special cases

  • If-then with bit mask

  • Do-while with counter

ANDS R0,#4

BEQ Target

ANDS R0,#4

BNE Target

loop

;stuff

SUBS R0,#1

BNE loop

6-9

10 of 12

Arrays

  • Base
    • Pointer passed in a register
  • Precision
    • 8 bits n=1 byte
    • 16 bits n=2 bytes
    • 32 bits n=4 bytes
  • Size
    • Fixed and known
    • Passed in another register
  • Value
    • Character
    • Unsigned integer
    • Signed integer

0 ≤ I < Size

Base+n*I

6-10

11 of 12

Examples

  • Simple programs
    • Clear, set, toggle, swap bits
    • Check if a bit is high or low
    • Logic, shift
    • Add, sub, multiply, and divide
  • Array programs
    • Min, max, sum, product, difference, average
    • Search for element
    • Replace one element with another
    • Copy from one to another

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

6-11

12 of 12

Strategies

  • Know the inputs
    • Put a breakpoint on your first line
    • Look at R0, R1, … as passed to you
  • Know the expected outputs
    • Comments
    • Grader output
  • Know AAPCS
  • Actually debug
    • Single step your code
    • Look at registers, memory
    • Debug the nth call to your code
  • Understand complexity
    • If-then
    • Single loop
    • Double loop

Bard, Erez, Gerstlauer, Valvano, Holt, Yerraballi, Telang, Cuevas, Tiwari

6-12