MIX C and Assembly in AtmelStudio

Status
Not open for further replies.

Majid soltani

New Member
Hi my friend...

I declare this variable :

const unsigned char screen_pattern[8*8] PROGMEM = {
10,20,0,11,0,125,255,13,
10,20,0,0,0,125,255,13,
10,20,115,90,0,125,255,13,
10,20,0,0,0,125,255,13,
10,47,0,0,0,125,255,13,
10,120,0,80,0,125,255,13,
10,200,0,0,0,125,255,13,
10,20,0,127,0,125,255,13
};

now ... i want mix C and Assembly code and send screen_pattern to PORTD with assembly code .... please help me...
 
In the documentation it will show how to use assembly within the C environment... It will be quite straight forward...

I don't use avr studio so I'm not sure....
 
you use which compiler ? ... please you say your solution maybe i could use that.
I use Pic's.... I don't think my compiler would be much use to you.. I haven't a copy of the GNU C compiler to hand...

Are you using AVR studio???
 
OK thank you.... Yes , I use atmelStudio 6

now i solved my problem

first i set an assembly name to screen_pattern[] :

const unsigned char screen_Pattern[8*8] asm("sc_p") PROGMEM = {
67,20,0,11,0,125,255,13,
10,20,0,0,0,125,255,13,
10,20,115,90,0,125,255,13,
10,20,0,0,0,125,255,13,
10,47,0,0,0,125,255,13,
10,120,0,80,0,125,255,13,
10,200,0,0,0,125,255,13,
10,20,0,127,0,125,255,13
};


then use this codes :


asm ("PUSH R16 ");
asm ("PUSH R30 ");
asm ("PUSH R31 ");

// Z Register is ( R31:R30)

asm ("LDI r30,lo8(sc_p)"); // R30 = LOW(sc_P)

asm ("LDI r31,hi8(sc_p)"); // R31 = HIGH(sc_P)

asm ("LPM R16 , Z "); // LPM (Load program memory) R16 = [Z] Z = first cell of screen_Pattern[]
asm ("OUT 0x12 , R16 "); // 0x12 is address of PORTD ; PORTD=R16

asm ("POP R31 ");
asm ("POP R30 ");
asm ("POP R16 ");
 
Why are you wanting to use C... If you are going to program in ASM just use an assembler??
 
Okay... Some of my functions are just ASM wrappers as well.... When the fastest code possible is needed..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…