05.07.2013 Views

Script for Laboratory: Designing embedded ASIPs - CES

Script for Laboratory: Designing embedded ASIPs - CES

Script for Laboratory: Designing embedded ASIPs - CES

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

instruction, as different custom instructions usually need different strategies <strong>for</strong> identifying<br />

them in the internal representation. The second possibility is to use inline assembly. Inline<br />

assembly is a porting of assembly code that is explicit written into the C-Code at the place,<br />

where it should be used. This way we can insert any custom instruction right into the C-Code<br />

without modifying the compiler. We can also insert small subroutines in a hand-optimized<br />

assembly version into the C-code. This possibility is time consuming while preparing the<br />

application, but <strong>for</strong> very complex custom instructions it is much faster than extending the<br />

compiler to automatically identify the instruction.<br />

First we will give a small example <strong>for</strong> the basic syntax <strong>for</strong> the CoSy specific version of inline<br />

assembly and later we will go into further details how the <strong>embedded</strong> assembly code can be<br />

parameterized.<br />

asm int example(int parameter1, int parameter2)<br />

{<br />

@[<br />

// Some later explained directives can be placed here<br />

]<br />

; This comment is written to the created assembly file<br />

nop<br />

nop<br />

nop<br />

add @{}, @{parameter1}, @{parameter2}<br />

nop<br />

nop<br />

nop<br />

; The @{parameter1} and @{parameter2} will be replaced by<br />

; the used registers <strong>for</strong> those parameters. The @{} referrs<br />

; to the register <strong>for</strong> the return value.<br />

}<br />

void main() {<br />

int a=5, b=7, c;<br />

c = example(a, b);<br />

}<br />

The created assembly file would look similar to the following (changes by the register<br />

allocations are marked):<br />

...<br />

addi r1, r0, $5<br />

addi r2, r0, $7<br />

nop<br />

nop<br />

nop<br />

; This comment is written to the created assembly file<br />

add r3, r1, r2<br />

nop<br />

- 77 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!