This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

adding a assembly file to project

Hi all

I want to add Asm file to a 'C' project.
Project has one '.c'and one '.h' file.

Assmbly file to be added is with '.a51' extension.only one routine is added to a51 file,which is called from main.A51 file is getting assembled successfully,but project is not getting compiled as whole.

decleration in main file is :

extern void delay_asm(unsigned char);

void main()
{
   .
   delay_asm(2);
   .
}


Assembly file is as given below

PR?delay_asm?delay_asm SEGMENT CODE

PUBLIC delay_asm

delay_asm:
   USING 0
   mov a,R7
rv:dec A
   Jnz rv
   RET

END

on project compilation:

warning L5:Code space overlap
From:0000H
To:0004H
warning L2:Refrence made to unresolved
external _delay_asm
Target not created.

This warnings where not generated before adding a51 file to project.

i am missing some thing small here,but any help would be appreciated.

Regards
Naresh

  • You need to add an

    RSEG PR?delay_asm?delay_asm
    to tell the linker that the segment is relocatable - see the examples in the Manual

  • The easy and error proof way to do this is to first code a skeleton routine in 'C'. Then use the generated assembler as a template for your assembly code.

    Erik

  • For such a simple loop why don't you stay in "C"

    void Delay (unsigned char Cycles)
    {
        while (--Cycles);
    }
    

    This function generates super efficient code:

    DELAY1: DJNZ R7,DELAY1
    

    If your real question is interfacing to assembler code, be aware of the register passing convention and function naming.

    Unless you state that your function is "alien", the actual assembly must be coded with an "_" (underscore) character preceeding the function name.

  • For such a simple loop why don't you stay in "C"
    This function generates super efficient code

    Maybe and maybe not depending on brand, options and release. There is absolutely no guarantee that C will generate any specific code.

    Thus all timing must be in assembler.

    There is no end to the bitbanging and other time critical routines I have seen fall apart because the Compiler got upgraded/replaced.

    Erik

  • If you really want accurate timing, use a timer.

    Even hand-tweaked assembler loops can fall apart the instant you change parts (12 clocks per instruction? 4? 2?), or oscillator frequency, or perhaps the external memory subsystem timing.

    Any function you put in software -- in whatever language -- will leave you potentialy liable for software maintenance when the environment changes in just the wrong way.

  • Thanks for reply.

    following was the code after modification.

    EXTRN CODE (mod_delay)
    PUBLIC delay_asm
    
    code_asm  SEGMENT CODE
    
    RSEG code_asm
    using 0
    
    delay_asm:
       mov A,R7
    rv:dec A
       Jnz rv
       call mod_delay
       RET
    
    END

    After "Rebuild all" following warning were generated:

    Uncalled segment,ignored for overlay process
    segment: ?pr?mod_delay?main
    warning l1:unresolved external symbol
    symbol:_DELAY_ASM
    MODULE:main.obj(MAIN)

    refrence made to unresolved external
    symbol:_DELAY_ASM
    MODULE:main.obj(MAIN)
    Address:001D


    code was not behaving like it should ???
    what is the way out ?
    do i have to set assmbly file properties ?
    project proerties ?
    (even after giving extension ' .a51 ' to assembly file)

    Thanks & Rgds
    Naresh

  • Rename the label "delay_asm" to "_delay_asm" in your assembly file. The compiler wants to see a leading "_" on any function that passes parameters via registers. Since delay_asm is using r7, it needs a leading "_".

  • Thanks bill

    code is working.
    Asm routine is getting called from main
    and 'C' routine from asm.
    so if no parameters are passed ' _ ' is not required.

    code after adding ' _ 'is:

    EXTRN CODE (mod_delay)
    EXTRN DATA (var_global)
    PUBLIC _delay_asm
    
    code_asm  SEGMENT CODE
    
    RSEG code_asm
    using 0
    
    _delay_asm:
       mov A,var_global
    rv:dec A
       Jnz rv
       call mod_delay
       RET
    
    END

    In routines written above:
    parameter var_global(char) is passed from main,
    To pass interger parameter(var_int),should following be the statements ?
    mov A,R7  ;take low byte of var_int to acc
    ..        ; logic oprns
    mov A,R6  ;take high byte of var_int to acc
    
    can i write
    EXTRN DATA (var_int)
    ....
    mov DPTR,var_int
    

    Thanks & regards
    Naresh

  • can i write

    mov DPTR,var_int

    No - Although the 8051 does a decent job manipulating the 16 bit DPTR, it is an 8 bit processor and just can't do this in one instruction. The DPTR can be loaded with a constant value in one fell sweep, but not with the value contained in a variable.

    Stick with:

    mov A,R7 ;take low byte of var_int to acc
    .. ; logic oprns
    mov A,R6 ;take high byte of var_int to acc

    or, if you want this value in DPTR do:

    mov DPL, R7 ;DPL is low byte of DPTR
    mov DPH, R6 ;DPH is high byte of DPTR

    Bill

  • Hi Bill

    since we have started discussion on
    assembly <----> 'C'

    why don't we discuss other issues which are related to this topic.This can be helpful to all.

    Every body is invited to share different type of problems they experience while workin with C <-> Assembly.

    regards
    Naresh

  • "Every body is invited to share different type of problems they experience while workin with C <-> Assembly"

    Better to make that a new thread - with a relevant Subject line.
    Of course, you'd start with a link to this one!