CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Assemble language subroutin with parameters?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

Assemble language subroutin with parameters?
PostPosted: Mon Apr 04, 2005 2:19 pm     Reply with quote

I know it is not right to ask this question here, and I should be able to find it somewhere in the web, however, I just want to communicate with you guys and make me understand it deeply and fast.

My question is how to define a subroutine in assemble language with parameter? such as the following code, How to understand it, what is the parameters, and how do I call it in a program? I did not have background on assemble, any help will be appreicated!


Code:

  ;--- procedure compact_C_F_cf_write_byte ---
   compact_C_F_cf_write_byte:
0039   BCF   STATUS,RP1
003A   BCF   STATUS,RP0
003B   MOVF   compact_C_F_cf_write_byte_param_dataport,W
003C   MOVWF   FSR
003D   MOVF   compact_C_F_cf_write_byte_param_bdata,W
003E   MOVWF   INDF
003F   L_compact_C_F_5:
003F   MOVF   compact_C_F_cf_write_byte_param_ctrlport,W
0040   MOVWF   FSR
0041   CLRF   STACK_0
0042   BTFSC   INDF,7
0043   INCF   STACK_0,F
0044   COMF   STACK_0,W
0045   MOVWF   STACK_0
0046   MOVLW   255
0047   SUBWF   STACK_0,W
0048   BTFSS   STATUS,Z
0049   GOTO   L_compact_C_F_6
004A   L_compact_C_F_4:
004A   nop
004B   GOTO   L_compact_C_F_5
004C   L_compact_C_F_6:
004C   CALL   delays_delay_1us
004D   BCF   STATUS,RP1
004E   BCF   STATUS,RP0
004F   BCF   INDF,6
0050   CALL   delays_delay_1us
0051   BCF   STATUS,RP1
0052   BCF   STATUS,RP0
0053   BSF   INDF,6
0054   CALL   delays_delay_1us
0055   RETURN
   ;---endproc---
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 04, 2005 2:58 pm     Reply with quote

Look at the sample code in this post. It shows how to pass a
parameter to ASM code.
http://www.ccsinfo.com/forum/viewtopic.php?t=21520
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

PostPosted: Mon Apr 04, 2005 2:59 pm     Reply with quote

See pic datasheet. It lists all instructions.

You need to use CALL to call a subroutine.

CALL 039 //should call this routine

although, if you are not on the same page, extra coding is required.
_________________
-Matt
Guest








PostPosted: Mon Apr 04, 2005 3:26 pm     Reply with quote

ThnK YOU PCM:

So in order to call the function, I have to define a function as the following:
Code:

void cf-write_byte(Byte Dataport, Byte ControlPort, Byte bdata)
{

byte compact_C_F_cf_write_byte_param_dataport;
byte compact_C_F_cf_write_byte_param_bdata;
byte compact_C_F_cf_write_byte_param_ctrlport;
compact_C_F_cf_write_byte_param_dataport=Dataport
ompact_C_F_cf_write_byte_param_bdata=bdata;
compact_C_F_cf_write_byte_param_ctrlport=ControlPort;
#asm
0039   BCF   STATUS,RP1
003A   BCF   STATUS,RP0
003B   MOVF   compact_C_F_cf_write_byte_param_dataport,W
003C   MOVWF   FSR
003D   MOVF   compact_C_F_cf_write_byte_param_bdata,W
003E   MOVWF   INDF
003F   L_compact_C_F_5:
003F   MOVF   compact_C_F_cf_write_byte_param_ctrlport,W
0040   MOVWF   FSR
0041   CLRF   STACK_0
0042   BTFSC   INDF,7
0043   INCF   STACK_0,F
0044   COMF   STACK_0,W
0045   MOVWF   STACK_0
0046   MOVLW   255
0047   SUBWF   STACK_0,W
0048   BTFSS   STATUS,Z
0049   GOTO   L_compact_C_F_6
004A   L_compact_C_F_4:
004A   nop
004B   GOTO   L_compact_C_F_5
004C   L_compact_C_F_6:
004C   CALL   delays_delay_1us
004D   BCF   STATUS,RP1
004E   BCF   STATUS,RP0
004F   BCF   INDF,6
0050   CALL   delays_delay_1us
0051   BCF   STATUS,RP1
0052   BCF   STATUS,RP0
0053   BSF   INDF,6
0054   CALL   delays_delay_1us
0055   RETURN
#endasm

}

or just define the three data byte compact_C_F_cf_write_byte_param_dataport;
byte compact_C_F_cf_write_byte_param_bdata;
byte compact_C_F_cf_write_byte_param_ctrlport;
defined in main program, right? 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 04, 2005 4:37 pm     Reply with quote

The variables that are in the function parameter list should be
used within the ASM code. You don't need to create another
group of variables and copy the parameters to them, as you
are doing.

I was sort of hoping that you would figure everything out
by yourself, once I pointed you to the sample code.

There are a few other things that have to be done to make
the code work. You should take out all the bank select code.
The compiler will insert its own bank select code, to access
the variables. You should take out the Return statement
at the end. The compiler will handle returning from the function.

The truth is, the code in that function is so simple that it could,
and should, be re-written in C. There's no reason for it to be
in assembly language. But I don't want to do that for you.
You should do it.
Guest








PostPosted: Tue Apr 05, 2005 6:53 am     Reply with quote

Thank you PCM:

I am trying to learn the skill by you suggestion.

In the code, How Stack_0 was defined.
Guest








PostPosted: Tue Apr 05, 2005 8:12 am     Reply with quote

Hi PCM:

From my question, you might already how I am lack of the knowlwdge of Assembly, and how hard it would be for me to start working on it, If you could kindly help me with this for both writing it in assembly and c, I will be much more appreciated.

I have many other subroutins like this, I just hope I could learn this one and do the others by my self
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Apr 06, 2005 9:04 am     Reply with quote

Hi:

After struggling and asking questions from other forums, I am able to understand assembly language. I believe I will be able to transfer them to any other language including c. I will continuously fight with the code and find the pleasure after digging it out, certainly with you guys help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group