Newest Viewed Downloaded

Exercises Embedded Systems

Exercises Embedded Systems

1.1 The C-function

We should document our code. You can find a flowchart tool in Word or Powerpoint. This could be useful for lab reports. int fac_c(int x) x < = 0 f = 0 f = 1 x > 1 f = f * x x = x-1 End return f if else N Y Y N while int fac_c(int x) { int f; if(x <= 0) f = 0; else { f = 1; while(x > 1) { f = f * x; x--; } } return f; } fac_c(5) calculates 1*5*4*3*2*1=120 Flowchart

main in C

#include extern int fac_asm(int); int fac_c(int); int main(void) { int c_result, asm_result; int x; while(1) { printf(”Enter a number: ”); scanf(”%d”, &x); c_result = fac_c(x); asm_result = fac_asm(x); printf(”C-result: %d\n”, c_result); printf(”Asm-result: %d\n”,asm_result); } return 0; } Message to the linker: fac_asm() is an external function (from an other file).

Structure diagram?

To document the program structure, a structure diagram could be useful. It could be directly translated into structured programming. ( while, if, else … ) But in assembler, we are not interested in the program structure, but in the program flow.

The Flowchart

The flowchart could be directly translated to assembler code.

How to program the Nios processor?

The Nios processor is the Altera version of a MIPS processor. It is designed to make efficient use of the resources in a FPGA. It comes in three versions: Small – Medium – Large …

Nios II registers 0…15

Use as constant ”0”! If you call a subroutine, save the contents of the registers you’ve used on stack!

Nios II registers 16…31

Points to the stack!

Register operations, R-type instructions

Program constants, I-type instructions

Some pseudoinstructions: movi rB, IMMED  addi rB,r0,IMMED movia rB,label  orhi rB,r0,%hiadj(label) addi rB,r0,%lo(label)

I-type, Branch

Pseudoinstruction: ble branch if less than or equal signed bge is the ble with register A and B swapped! The IMM16 adress is effectively a 18 Byte-adress because instructions must be word-aligned.

Conditional operators of C

All C-language conditional operators have assembly instructions (or pseudoinstructions). Compare two registers and branch relative if the expression is true.

Memory content, Load and Store

Store in memory … stw r6, 100(rA)

The call and ret instructions

From Flowchart to assembler

Assembler

.global fac_asm .text # Parameter in r4 (and if needed in r5, r6, r7) # Return value in r2 (and r3 if long or double) # we can use r2 and r3 for calculations until return # r8 … r15 must be saved by caller of a sub fac_asm: # int r2 fac_asm(int r4 x), the function prototype # r3 : for constant ”1” if: ble r4, r0, else # if(x <= 0) movi r3, 1 # constant ”1” mov r2,r3 # f = 1 while: ble r4,r3, endsub # while(x>1){ mul r2,r2,r4 # f = f*x sub r4,r4,r3 # x = x - 1 br while # } else: mov r2, r0 # f = 0 endsub: ret # return r2 .end fac_asm has to be made known to other files

Exercises Embedded Systems

2.1 Prioritized interrupts

Exercises Embedded Systems

2.2 Input/Output

R/W reverses the direction of the databuss. CS Chip Select enables the chip Connect a 8 register memory-mapped peripheral to the CPU. The CPU has 8 bit address and data busses. The peripheral should have registeraddresses 0x10…0x17.

Showing 1 - 20 of 37 items Details

Name: 
ws_EmbSysTut1
Author: 
N/A
Company: 
N/A
Description: 
Exercises Embedded Systems
Tags: 
cach | memori | word | tag | line | int | fac | asm
Created: 
9/4/2009 2:36:28 PM
Slides: 
37
Views: 
7
Downloads: 
0
Rating: 
0


> Comment



Share this presentation
|

Comments

Share this presentation:

|
Sitemap