MIX C and Assembly in AtmelStudio

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...
 
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 ");
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…