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.

Adding assembly in c

Status
Not open for further replies.

namees22

Junior Member level 2
Joined
Aug 30, 2012
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Ernakulam
Activity points
1,430
hi
i am using RIDE ide..for programming 8052 i need to add some ASM codes to it.so some one pls help me in doing it.!
 

Kurenai_ryu

Advanced Member level 2
Joined
Jun 10, 2006
Messages
671
Helped
159
Reputation
316
Reaction score
99
Trophy points
1,308
Location
Bolivia
Activity points
5,911
you can use the macro assembler ma51 and have your ASM functions coded in there...

or you can use the ASM pragma directive inside a C program...

Code:
/* example of RC51 file using ASM control */
main( )
{
printf("This program will indefinitely loop");
#pragma ASM
jmp $;
#pragma ENDASM
}
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,349
Reputation
4,692
Reaction score
2,275
Trophy points
1,413
Location
Southwest, USA
Activity points
62,377
i am using RIDE ide..for programming 8052 i need to add some ASM codes to it.so some one pls help me in doing it.!

Actually the required techniques largely depend on the compiler in use, rather than the IDE.

If you are using the SDCC compiler, for example:


Code C - [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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
unsigned char __far __at(0x7f00) buf[0x100];  
unsigned char head, tail;  
#define USE_ASSEMBLY (1)  
  
#if !USE_ASSEMBLY  
  
void to_buffer( unsigned char c )  
{  
    if( head != (unsigned char)(tail-1) )  
        buf[ head++ ] = c;  
}  
  
#else  
  
void to_buffer( unsigned char c )  
{  
    c; // to avoid warning: unreferenced function argument  
    __asm  
        ; save used registers here.  
        ; If we were still using r2,r3 we would have to push them here.  
; if( head != (unsigned char)(tail-1) )  
        mov  a,_tail  
        dec  a  
        xrl  a,_head  
        ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)  
        jz   t_b_end$  
        ;  
; buf[ head++ ] = c;  
        mov  a,dpl       ; dpl holds lower byte of function argument  
        mov  dpl,_head   ; buf is 0x100 byte aligned so head can be used directly  
        mov  dph,#(_buf>>8)  
        movx @dptr,a  
        inc _head  
        ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)  
t_b_end$:  
        ; restore used registers here  
    __endasm;  
}  
#endif





If you are utilizing another compiler other than SDCC, please specify and include version.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top