2003-11-06 12:17 AM
2003-06-17 11:29 PM
Hello everyone,
I want to write a small part of the code of my program in assembler, the rest is written in C. Doing this is no problem in Cosmic, but... The assembler part writes data into a variable that is used in the C code. How can i manage that C an assembler use the same memory place for this variable? Thanks...2003-06-18 01:45 AM
You can do this by two methods:
1)Use absolute addressing for declaring variables volatile unsigned char i @0x80; Above instruction will declare i at memory lacation 0x80 and in your assembly you can use this address 2) use _asm function _asm(''SRA A\n LD $80,a\n'',j); This instruction will load variable j in A and shift it right, next it will load the result in A at 0x80 Hope this helps Regards, PraveenG[ This message was edited by: praveenG on 18-06-2003 15:15 ]2003-06-18 03:04 AM
The correct way would be:
unsigned char data; // c variable void somefunc(void) { #asm ld a, #10 ld _data, a #endasm } If the variables are declared in another file then use the XREF keyword,eg. #pragma asm xref _data #pragma endasm Regards Spen2003-06-18 03:04 AM
Hi,
I've tried this : int waarde; void main(){ #asm LD A, #100 LD _waarde,A #endasm schrijfPWM(3,waarde); } but it didn't work, anyone an idea what i did wrong??? When i write ex. '' waarde = 255;'' it works fine, so ''schrijfPWM()'' works well. thanks.[ This message was edited by: joble on 18-06-2003 15:51 ]2003-06-18 03:41 AM
Hi again,
Finally it works! The variable should be a char (like in the example sjo gave) instead of an int. I do not understand why, but it seems to be that way... Thanks both for your help!2003-06-18 04:39 AM
If you need to use an int, then remenber you have to work on both chars, eg.
int data; void somefunc(void) { #asm ld a, #10 ld _data, a ; msb of int clr _data+1 ; lsb of int #endasm } Regards Spen2003-11-05 10:57 PM
Quote:
How about declaring the variable ''data'' in somefunc() as a local variable? I tried. But it didn't work and showed _data undefined. I can't find the helpful information in documentation. Thanks a million! slin2003-11-06 12:17 AM
This is not possible on local variables because of the way the compiler treats locals, eg.
Depending on memory model, options etc a variable declared locally such as: unsigned char var is actually internal as _main$L-1. (using memory stack) Have a look inside the listing file to see what I mean. Regards sjo