Inline Assembly

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

Why would we want to write Assembler within C?

  • Outsmart gcc logic 

  • Specific optimisations 

  • Close to the hardware programming (drivers)

  • Embed existing code fragments 

  • Performance

2
New cards

Compilation Example

knowt flashcard image
3
New cards

Breaking Down Function Execution

  • Caller stores arguments in registers or memory

  • Function call: caller transfers flow control to the callee

  • Callee acquires/allocates memory for doing work

  • Callee executes the function body

  • Callee stores the result in ‘some’ register

  • Callee deallocates memory

  • Function return: callee returns control the caller

4
New cards

Inline Assembly

  • GCC allows inline assembler 

  • The compiler inserts assembler code in the code of its caller 

  • This removes function call overheads (recall, function prolog)

  • The key word asm or asm is used to include code: 

    • asm("assembly code"); 

  • Assembly is architecture-specific

    • You ARM assembly will not be transcoded into x86

  • You can also compile an assembly file into an obj file

5
New cards

Basic Inline Assembler

knowt flashcard image
6
New cards

Extended Inline Assembler

The embedded assembler code must interact with C code 

  • Parameters must be passed on to the assembler program

  • Results must be passed on to C code

<p>The embedded assembler code must interact with C code&nbsp;</p><ul><li><p>Parameters must be passed on to the assembler program</p></li><li><p>Results must be passed on to C code</p></li></ul><p></p>
7
New cards

Input/Output Operands

knowt flashcard image
8
New cards

Register Allocation

A compiler must assign variables into processor register

  • Any two variable must not be assigned to the same register at any point

  • Use Spilling to store variable values

  • Coalescing will aim to optimize register allocation to reduce value copying

  • Graph colouring problem and liveness analysis

9
New cards

Volatile

Used for instructions with processor side-effects

  • Disable compiler optimizations, which might lead code block removal (compiling with flag -O1 or higher)

    • volatile asm("assemler"); 

    • __volatile__ asm(“assembler”);

10
New cards

Clobbered Register

  • r0 after the third colon tells GCC that the value of r0 is to be modified inside "asm", so GCC won’t use this register to store any other value

  • the list can also contain special arguments:

    • "cc": The instruction modifies the condition code flags (save psr)

    • "memory": The instruction accesses unknown memory addresses

<ul><li><p>r0 after the third colon tells GCC that the value of r0 is to be modified inside "asm", so GCC won’t use this register to store any other value</p></li><li><p>the list can also contain special arguments:</p><ul><li><p>"cc": The instruction modifies the condition code flags (save psr)</p></li><li><p>"memory": The instruction accesses unknown memory addresses</p></li></ul></li></ul><p></p>
11
New cards

Usage Example - MACRO

knowt flashcard image
12
New cards

Usage Example - Interrupts

knowt flashcard image