Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to mix assembly language in c with MPLAB c30 C compiler?

Status
Not open for further replies.

kinjal_ic

Newbie level 5
Joined
Jun 23, 2008
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,363
c30 asm

Hi,
My question is that how we can mix assembly language in c with MPLAB c30 C compiler. :?:

for example

Code C - [expand]
1
2
3
4
#asm{
               xxxxxx;
               xxxxxx;
         }


for example I want to place a function in my C program for eeprom writing (not dependent on any .h file), say write(int address,int data) then is it possible to pass these variables to any assembly function such as that found in dspic30f4011 data sheet, which is as under:

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
; Setup a pointer to data EEPROM
MOV #tblpage(EE_ADDR),W0
MOV W0,TBLPAG
MOV #tbloffset(EE_ADDR),W0
; Write data value to holding latch
MOV EE_DATA,W1
TBLWTL W1,[ W0]
; NVMADR captures write address from the TBLWTL instruction.
; Setup NVMCON for programming one word to data EEPROM
MOV #0x4004,W0
MOV W0,NVMCON
; Disable interrupts while the KEY sequence is written
PUSH SR
MOV #0x00E0,W0
IOR SR
; Write the key sequence
MOV #0x55,W0
MOV W0,NVMKEY
MOV #0xAA,W0
MOV W0,NVMKEY
; Start the write cycle
BSET NVMCON,#WR
;Re-enable interrupts, if needed
POP SR



-------------------
(Sorry for my bad english)
 
Last edited by a moderator:

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,863
__builtin_mac

The compiler supports the simple form of inline assembly

Code:
asm ("instruction");

and also an extended form

Code:
asm("template" [ : [ "constraint"(output-operand) [ , ... ] ]
[ : [ "constraint"(input-operand) [ , ... ] ]
[ "clobber" [ , ... ] ]
]
]);

You need to read the user guide to get details on using the extended form.

There is nothing stoping you from writing the code for eeprom read/write in C.
The compiler has several 'built in' functions for common assembly operations, again, the user guide is the place to find details on all the built in functions

Built-In Function List
__builtin_addab __builtin_movsac __builtin_tbloffset
__builtin_add __builtin_mpy __builtin_tblrdh
__builtin_btg __builtin_mpyn __builtin_tblrdl
__builtin_clr __builtin_msc __builtin_tblwth
__builtin_clr_prefetch __builtin_mulss __builtin_tblwtl
__builtin_divf __builtin_mulsu __builtin_write_NVM
__builtin_divmodsd __builtin_mulus __builtin_write_OSCCONL
__builtin_divmodud __builtin_muluu __builtin_write_OSCCONH
__builtin_divsd __builtin_nop __builtin_write_RTCWEN
__builtin_divud __builtin_psvpage
__builtin_dmaoffset __builtin_psvoffset
__builtin_ed __builtin_readsfr
__builtin_edac __builtin_return_address
__builtin_fbcl __builtin_sac
__builtin_lac __builtin_sacr
__builtin_mac __builtin_sftac
__builtin_modsd __builtin_subab
__builtin_modud __builtin_tblpage

Another approach is to compile the assembly code into a library and link in when building your program.
This is a good option for commonly used functions.

Added after 3 hours 19 minutes:

I see you are starting to use the Microchip 16-bit processors.
This is quite a fast and powerful processor family with lots of varieties in the series.
I have written a small rtos for use with the dsPic30/33 and Pic24 micros.
Full source code and docs are included. Please take a look.
Maybe you could use it in one of your future projects.
It is posted on eda board here.
 

    kinjal_ic

    Points: 2
    Helpful Answer Positive Rating

D_A_V_E

Member level 5
Joined
Nov 13, 2007
Messages
91
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,736
_asm instruction in mplab c30

Hi Does anyone knows how to use the VDI in MPLAB.

I am using a PIC24 and i thought it would be nice to use VDI. But some how i can not use the peripherals i selected.

Yours,

Dave
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top