Go Down

Topic: Watchdog ISR in assembly language (Read 8 times) previous topic - next topic

stimmer

#15
Feb 15, 2011, 01:16 am Last Edit: Feb 15, 2011, 02:24 am by stimmer Reason: 1
Can't you use the assembler .include directive? This works for me in Linux (I don't know about Windows).

Code: [Select]
asm (".include \"/full/path/to/sketch/asm.h\" \n");

extern "C" int func();

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 Serial.println(func());
}


asm.h:
Code: [Select]
.section .text

.equ elo, 105
.equ ehi, 122

.global func
func:
 ldi r24,elo
 ldi r25,ehi
 ret
 


I use a .h file so the IDE doesn't complain, it's a bit of a hack. You seem to have to use an absolute path to .include, and you have to remember to save it in the IDE each time you change it before compiling.

Graynomad

asm("#define   SREG   0x3f\n");
asm("    in       r16,SREG\n");  // fails with "Error: constant value required"
asm("    in       r16,0x3f\n");  // works

@CB
I tried with and without \n, no difference. I often wondered about the \n in these assembler examples, it's the sort of thing you do when generating HTML code that has to be read by a human but you wouldn't expect it to be required here.

@Rob
I did the same with the small exception that I don't have python installed  :), I'll go and get it.

@stimmer
That approach produced 964

at com.oroinc.text.regex.Perl5Matcher._match(Perl5Matcher.java)

errors.

However I noticed your .equ syntax is different

asm(".equ SREG,0x3f\n");
asm("    in       r16,SREG\n");  // this works

but

asm(".equ r_temp1,r16\n");
asm("    push    r_temp\n"); // this doesn't work,  Error: register name or number from 0 to 31 required
asm("    in    r_temp,SREG\n"); // same error

Is this the ASM equivelant of "lvalue required"?

Anyway that's where I left it at 2AM last night. I'm back on deck now so will continue with this.


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

stimmer

I don't know if you can properly use .equ or = to rename registers.

But it just happens to work under certain circumstances. In particular, don't make the first letter of the symbol 'r' and omit the 'r' from the register. ie:

.equ q_temp1,16

which is the same as

q_temp1 = 16

should 'work', at least for now.

westfw

I'll have to check the mechanics of having assembler included in your sketch when I'm at home with the source code.
I thought you could add a .S tab to your sketch just the way you can add .h, .c, or .cpp modules.  It may have to be capitalized...

westfw

Huh.  It looks like the "Compiler" part of the IDE understands .S files, but the editor refuses to add such files to the sketch, or pass them to the compiler.  Hmmph.

Go Up