Mix Assembly and C (JSR and BRSET compatibility)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mix Assembly and C (JSR and BRSET compatibility)

2,455 Views
powegila
Contributor I
I have problem mixing assembly and C. Please advice me if anyone know the solution! Thanks in advance!
 
In the assembly code, the two parts I'd like to use in C are: (code are typed in italics)
 
PART 1:
 
temp_diag:
 jsr diag_disp_sub
 rts
 
 
PART 2:
 xdef diag_disp_sub
diag_disp_sub equ $ 
  brset _diag_t_flg,80h,d_cnt_chk
  jsr diag_disp_csw
  rts
 
As you can see, both of them do the same thing.
PART 1 has a jump directives which jump to the PART 2.
 
I use these function in C code as below:
 
 if( flg != 0 ){ 
  
    temp_diag();  
   }
 else{
  diag_disp_sub();
 }
 
As you can see, PART 1 is executed if flg22_flg11 is not equal zero and PART 2 is executed if flg22_flg11 is equal zero.
Of course, in the header file, I declare both the functions as below
 
void temp_diag(void);
void diag_disp_sub(void);
 
When I run the program, i.e., I set the flg so the PART 1 is executed then I cleared the flg so the PART 2 is executed., the PART 1 executed successfully but PART 2 not!
if the routine run into PART 2, the CPU reset itself!
or if CW(debugger) and CPU is connecting, the debugger immediately disconnect from CPU!
 
WHY???
Labels (1)
0 Kudos
3 Replies

457 Views
blood
Contributor III
What are you doing with that brset. Where does it actually branch to?
0 Kudos

457 Views
bigmac
Specialist III
Hello,
 
I am not sure what you mean by your reference to a "jump directive".  I can only see use of a JSR assembly instruction within part 1.  Equally valid would have been the use of a JMP instruction (without requiring the RTS).
 
Are part 1 and part 2 within the same .asm file, or different files?
 
I suspect your C function declarations should be extern, and that there should also be an XDEF temp_diag directive within part 1.
 
When you "make" your project with CW, do you currently get any compiler, assembler or linker warnings?  When you use full chip simulation to debug your code, does the debugger clarify the reason for the reset occurring?
 
Regards,
Mac
 
0 Kudos

457 Views
JimDon
Senior Contributor III
powegila  - I don't see anything wrong with what you have posted.

Could you show all the code?


Message Edited by JimDon on 2008-01-07 08:25 PM
0 Kudos