 |
 |
| View previous topic :: View next topic |
| Author |
Message |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 12:41 pm |
|
|
| s_mack wrote: | | #import looks like it may have been the ticket I was missing. Thanks. |
Then again... maybe not. It looked promising
Here's what I did: I started a new project with MPASM as the toolset and added the two ASM files. Then I assembled them, producing a couple of .o files. So far so good.
I added those .o files to my main project. Then I used this line near the top of my main c file:
| Code: | | #import (FILE=PIDint.o) |
compiled (with ccs) and outcame this nonsense: | Code: | *** Error 146 "test.c" Line 66(8,14): Import error Bad file format: "@¡>¡JP2axV4ЀDÍ€;*v È• jjjjjjjjjjjjjjjjjjjjjjjjjjjjjj n n n"
|
back to hair pulling for now.[/code] |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 12:57 pm |
|
|
I'd imagine it's because CCS's .o format may have additional information than MPASM. I don't know the standards there.
Ask CCS.
Look at #export and I would also imagine some clarity might come as to why the #import as it stands doesn't work.
As I mentioned before, doing the .O output might require a little bit off CCS'ing of the .ASM files. (Still a lot less than the rewrite.)
If worst comes to worst, I'll dig in deep with you on it.. but I have a project sitting on my desk that I've really got to get on..
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 1:01 pm |
|
|
I appreciate the offer, but at this point I'm still going hard trying to figure it out.
I got a quick response from CCS and they gave me a tip to add the COFF option. That gets rid of the gobble-dee-gook error and replaces it with: | Code: | *** Error 148 "test.c" Line 65(8,14): Linker Error: COFF file 'C:\Users\Steven Morehouse\Documents\business\Area 451 Parts Ltd\Cruise Control\Firmware\Blank test - Copy\PIDint.o' is corrupt; recompile module.
|
At least its readable  |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 3:20 pm |
|
|
I wonder now if its a version problem.
Just an update. Tech support got back to me a few times but ultimately said they couldn't look at it until next week. Which is cool, but its going to drive me nuts all weekend.
I started to play around and I tried an extremely basic example.
First, I started a new project and use MPASM tools as the suite. I created this stupidly simple ASM file: | Code: | ;********************************************************
;nothing but comments
end
|
and saved it as asmtest.asm.
Build-All and everything was hunky dorey. It generated an asmtest.o file that I stuck over in my main directory.
So I open up my main project and add the o file in. I make this stupidly simple c file
| Code: | #include <18F4480.h>
#import(FILE=asmtest.o, COFF)
void main()
{
} |
build-all. Alls not well. Again, I get this frustrating error: | Quote: | *** Error 148 "main.c" Line 2(8,14): Linker Error: COFF file 'C:\Users\Steven Morehouse\Documents\business\Area 451 Parts Ltd\Cruise Control\Firmware\wtf\asmtest.o' is corrupt; recompile module.
|
I've tried assembling the ASM file with the Generate relocatable code first, as per tech support's suggestion, and also as Absolute code. Same difference.
Removing the COFF option in the import call just produces the same garbage that I posted earlier today.
So I wonder if its the combination of my ccs and mplab versions?
ccs version I tried 4.084 first and then 4.093.
mplab is 8.36
mpasm is 5.33
mplink is 4.33
maybe an older combo works and somewhere along the way this got broken on one end or another? |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 5:24 pm |
|
|
I'm going to try something at this end involving ASM code that has been CCS'ized when I was helping them add the 18F46J11 family to PCH.
With those routines, I'll compile them with CCS as an object and then see how that imports.. but I'll have to work on it this weekend (maybe tomorrow sometime)
In the meantime, here's a fun chunk you could try out:
| Code: | //////// Program memory: 32764x16 Data RAM: 3840 Stack: 31
//////// I/O: 34 Analog Pins: 13
//////// C Scratch area: 00 ID Location: 0000
//////// Fuses: HS,H4_SW,EC,E4_SW,DEBUG,NODEBUG,XINST,NOXINST,STVREN
//////// Fuses: NOSTVREN,WDT,NOWDT,PROTECT,NOPROTECT,WDT1,WDT2,WDT4,WDT8
//////// Fuses: WDT16,WDT32,WDT64,WDT128,WDT256,WDT512,WDT1024,WDT2048
//////// Fuses: WDT4096,WDT8192,WDT16384,WDT32768,FCMEN,NOFCMEN,IESO,NOIESO
//////// Fuses: IOL1WAY,NOIOL1WAY,PRIMARY,INTRC,WPCFG,NOWPCFG,WPBEG,WPEND
//////// Fuses: WPDIS,NOWPDIS,LPT1OSC,NOLPT1OSC,T1DIG,NOT1DIG,MSSPMSK5
//////// Fuses: MSSPMSK7,INTRC_PLL,INTRC_PLL_IO,INTRC_IO,DSWDT2,DSWDT8
//////// Fuses: DSWDT32,DSWDT128,DSWDT512,DSWDT2048,DSWDT8192,DSWDT32768
//////// Fuses: DSWDT131072,DSWDT524288,DSWDT2097152,DSWDT8388608
//////// Fuses: DSWDT33554432,DSWDT134217728,DSWDT536870912,DSWDT2147483648
//////// Fuses: DSWDT,NODSWDT,DSBOR,NODSBOR,RTCOSC_INT,RTCOSC_T1
//////// Fuses: DSWDTOSC_INT,DSWDTOSC_T1,WPFP0,WPFP1,WPFP2,WPFP3,WPFP4,WPFP5
//////// Fuses: NOCPUDIV,CPUDIV2,CPUDIV3,CPUDIV6
#include <18F46J11.h>
//#device ICD=TRUE
//#use delay(clock=10M, crystal=10M)
//#fuses WDT32768,NOPROTECT,NODEBUG,NOIESO, NOSTVREN, NOWDT, NOFCMEN, NODSWDT
//#fuses LPT1OSC, NOT1DIG, RTCOSC_T1
//#opt 10
#locate EECON2 = GETENV("sfr:EECON2")
#locate PPSCON = GETENV("sfr:PPSCON")
#bit IOLOCK = 0xEFF.0
// -------------------------------------------------
#bit RTCEN = 0xF3F.7
#bit RTCOE = 0xF3F.2
#bit RTCWREN = 0xF3F.5
#bit RTCSECSEL0 = 0xF3C.1
#bit RTCSECSEL1 = 0xF3C.2
#locate RTCCAL = getenv("sfr:RTCCAL")
#EXPORT (RELOCATABLE)
void IO_UNLOCK (void) {
#asm ASIS
MOVLB 0x0E
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BCF 0xFF.0
#endasm
}
void IO_LOCK (void) {
#asm ASIS
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF 0xFF.0
#endasm
}
void IO_SET (void) {
#asm ASIS
MOVLW 0x05 // Set U2TX to D6
MOVWF 0xDD // Set U2TX to D6
MOVLW 0x18 // Set U2RX to D7
MOVWF 0xF6 // Set U2RX to D7
#endasm
}
void RTC_RESET (void) {
#asm ASIS
MOVLB 0x0F
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF RTCWREN
CLRF RTCCAL
BCF RTCSECSEL0
BSF RTCSECSEL1
BSF RTCEN
BSF RTCOE // this works
BCF RTCWREN
#endasm
}
|
_________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 5:27 pm |
|
|
| Thanks, but "try out" in what sense? |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 5:32 pm |
|
|
That's an exportable module that's more CCS compiler friendly.
So compile it -- and then try importing it.. (with success) and then see about just writing some C that makes calls to the functions in that .O file.
From there, take one of the functions and make it a pure routine... or writing something similar to see if the disconnect is the MPASM .O output.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 5:36 pm |
|
|
Ok, I got you. I already did that - confirm that its the importing of an MPASL generate .o file rather simply the importing of an .o file in general.
I'll play with it.
I probably should have taken people's advice yesterday and just rewrite the damned thing in c. That's retarded to the n'th degree.... but it looks like it will probably be the fastest and most reliable. |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 5:44 pm |
|
|
| s_mack wrote: | Ok, I got you. I already did that - confirm that its the importing of an MPASL generate .o file rather simply the importing of an .o file in general.
|
Right -- So let's take a step back to see where CCS is happy with the .o file.. and maybe that will lead us to somehow making importing the ASM code easier.
You can see from the same I sent you that making the ASM chunks into procedure calls isn't so bad since a lot of the syntax is maintained.
| s_mack wrote: |
I probably should have taken people's advice yesterday and just rewrite the damned thing in c. That's retarded to the n'th degree.... but it looks like it will probably be the fastest and most reliable. |
Yea. I know. The pain here is really a tweak/trick of the compiler we need to learn more than just the writing of C.
Whenever you ask a compiler to do something weird, this kind of learning curve hits. That's how ALL things with a lot of features to deal with the funk get.
Just be happy you're not using C18. It's like someone shoe-horned gcc into compiling for PIC's off of unix. It's really ugly sometimes. The last time I worked with C18 the programmer I inherited the project from didn't really understand the consequences of all the extra code that goes into manipulating 16bit words and 1bit shorts (the default typedefs) on an 8bit micro (that has an instruction for dealing with setting bits.)
I got back like 30% of the units ROM memory because of that changeover. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 5:49 pm |
|
|
what do you do with code that's outside of the function calls though? The ASM files are in 2 pieces, there's the main one and a math one. I gather the first references the 2nd. here's the math one:
| Code: | ;********************************************************
;This file contains the following math routines:
;24-bit addittion
;24-bit subtraction
;16*16 Unsigned Multiply
;24/16 Unsigned Divide
list p=18F4480
#include <p18F4480.inc>
#define _Z STATUS,2
#define _C STATUS,0
GLOBAL AARGB0,AARGB1,AARGB2,AARGB3
GLOBAL BARGB0,BARGB1,BARGB2,BARGB3
GLOBAL ZARGB0,ZARGB1,ZARGB2
GLOBAL REMB0,REMB1
GLOBAL TEMP,TEMPB0,TEMPB1,TEMPB2,TEMPB3
GLOBAL LOOPCOUNT,AEXP,CARGB2
LSB equ 0
MSB equ 7
math_data UDATA
AARGB0 RES 1
AARGB1 RES 1
AARGB2 RES 1
AARGB3 RES 1
BARGB0 RES 1
BARGB1 RES 1
BARGB2 RES 1
BARGB3 RES 1
REMB0 RES 1
REMB1 RES 1
REMB2 RES 1
REMB3 RES 1
TEMP RES 1
TEMPB0 RES 1
TEMPB1 RES 1
TEMPB2 RES 1
TEMPB3 RES 1
ZARGB0 RES 1
ZARGB1 RES 1
ZARGB2 RES 1
CARGB2 RES 1
AEXP RES 1
LOOPCOUNT RES 1
math_code CODE
;---------------------------------------------------------------------
; 24-BIT ADDITION
_24_BitAdd
GLOBAL _24_BitAdd
movf BARGB2,w
addwf AARGB2,f
movf BARGB1,w
btfsc _C
incfsz BARGB1,w
addwf AARGB1,f
movf BARGB0,w
btfsc _C
incfsz BARGB0,w
addwf AARGB0,f
return
;---------------------------------------------------------------------
; 24-BIT SUBTRACTION
_24_bit_sub
GLOBAL _24_bit_sub
movf BARGB2,w
subwf AARGB2,f
movf BARGB1,w
btfss STATUS,C
incfsz BARGB1,w
subwf AARGB1,f
movf BARGB0,w
btfss STATUS,C
incfsz BARGB0,w
subwf AARGB0,f
return
;-------------------------------------------------------------------------
; 16x16 Bit Unsigned Fixed Point Multiply 16 x 16 -> 32
FXM1616U
GLOBAL FXM1616U
MOVFF AARGB1,TEMPB1
MOVF AARGB1,W
MULWF BARGB1
MOVFF PRODH,AARGB2
MOVFF PRODL,AARGB3
MOVF AARGB0,W
MULWF BARGB0
MOVFF PRODH,AARGB0
MOVFF PRODL,AARGB1
MULWF BARGB1
MOVF PRODL,W
ADDWF AARGB2,F
MOVF PRODH,W
ADDWFC AARGB1,F
CLRF WREG
ADDWFC AARGB0,F
MOVF TEMPB1,W
MULWF BARGB0
MOVF PRODL,W
ADDWF AARGB2,F
MOVF PRODH,W
ADDWFC AARGB1,F
CLRF WREG
ADDWFC AARGB0,F
RETLW 0x00
;--------------------------------------------------------------------
FXD2416U
GLOBAL FXD2416U
CLRF REMB0
CLRF REMB1
CLRF WREG
TSTFSZ BARGB0
GOTO D2416BGT1
MOVFF BARGB1,BARGB0
CALL FXD2408U
MOVFF REMB0,REMB1
CLRF REMB0
RETLW 0x00
D2416BGT1
CPFSEQ AARGB0
GOTO D2416AGTB
MOVFF AARGB1,AARGB0
MOVFF AARGB2,AARGB1
CALL FXD1616U
MOVFF AARGB1,AARGB2
MOVFF AARGB0,AARGB1
CLRF AARGB0
RETLW 0x00
D2416AGTB
MOVFF AARGB2,AARGB3
MOVFF AARGB1,AARGB2
MOVFF AARGB0,AARGB1
CLRF AARGB0
MOVFF AARGB0,TEMPB0
MOVFF AARGB1,TEMPB1
MOVFF AARGB2,TEMPB2
MOVFF AARGB3,TEMPB3
MOVLW 0x02 ; set loop count
MOVWF AEXP
MOVLW 0x01
MOVWF ZARGB0
BTFSC BARGB0,MSB
GOTO D2416UNRMOK
CALL DGETNRMD ; get normalization factor
MOVWF ZARGB0
MULWF BARGB1
MOVF BARGB0,W
MOVFF PRODL,BARGB1
MOVFF PRODH,BARGB0
MULWF ZARGB0
MOVF PRODL,W
ADDWF BARGB0,F
MOVF ZARGB0,W
MULWF AARGB3
MOVFF PRODL,TEMPB3
MOVFF PRODH,TEMPB2
MULWF AARGB1
MOVFF PRODL,TEMPB1
MOVFF PRODH,TEMPB0
MULWF AARGB2
MOVF PRODL,W
ADDWF TEMPB2,F
MOVF PRODH,W
ADDWF TEMPB1,F
D2416UNRMOK
BCF _C
CLRF TBLPTRH
RLCF BARGB0,W
RLCF TBLPTRH,F
ADDLW LOW (IBXTBL256+1) ; access reciprocal table
MOVWF TBLPTRL
MOVLW HIGH (IBXTBL256)
ADDWFC TBLPTRH,F
TBLRD *-
D2416ULOOP
MOVFF TEMPB0,AARGB0
MOVFF TEMPB1,AARGB1
CALL FXD1608U2 ; estimate quotient digit
BTFSS AARGB0,LSB
GOTO D2416UQTEST
SETF AARGB1
MOVFF TEMPB1,REMB0
MOVF BARGB0,W
ADDWF REMB0,F
BTFSC _C
GOTO D2416UQOK
D2416UQTEST
MOVF AARGB1,W ; test
MULWF BARGB1
MOVF PRODL,W
SUBWF TEMPB2,W
MOVF PRODH,W
SUBWFB REMB0,W
BTFSC _C
GOTO D2416UQOK
DECF AARGB1,F
MOVF BARGB0,W
ADDWF REMB0,F
BTFSC _C
GOTO D2416UQOK
MOVF AARGB1,W
MULWF BARGB1
MOVF PRODL,W
SUBWF TEMPB2,W
MOVF PRODH,W
SUBWFB REMB0,W
BTFSS _C
DECF AARGB1,F
D2416UQOK
MOVFF AARGB1,ZARGB1
MOVF AARGB1,W
MULWF BARGB1
MOVF PRODL,W
SUBWF TEMPB2,F
MOVF PRODH,W
SUBWFB TEMPB1,F
MOVF AARGB1,W
MULWF BARGB0
MOVF PRODL,W
SUBWF TEMPB1,F
MOVF PRODH,W
SUBWFB TEMPB0,F
BTFSS TEMPB0,MSB ; test
GOTO D2416QOK
DECF ZARGB1,F
MOVF BARGB1,W
ADDWF TEMPB2,F
MOVF BARGB0,W
ADDWFC TEMPB1,F
D2416QOK
DCFSNZ AEXP,F ; is loop done?
GOTO D2416FIXREM
MOVFF ZARGB1,ZARGB2
MOVFF TEMPB1,TEMPB0
MOVFF TEMPB2,TEMPB1
MOVFF TEMPB3,TEMPB2
GOTO D2416ULOOP
D2416FIXREM
MOVFF TEMPB1,REMB0
MOVFF TEMPB2,REMB1
MOVLW 0x01
CPFSGT ZARGB0
GOTO D2416REMOK
RRNCF ZARGB0,W
MOVWF BARGB0
CALL DGETNRMD
MULWF TEMPB2
MOVFF PRODH,REMB1
MULWF TEMPB1
MOVF PRODL,W
ADDWF REMB1,F
MOVFF PRODH,REMB0
D2416REMOK
CLRF AARGB0
MOVFF ZARGB1,AARGB2
MOVFF ZARGB2,AARGB1
RETLW 0x00
;----------------------------------------------------
FXD2408U
MOVFF AARGB0,TEMPB0
MOVFF AARGB1,TEMPB1
MOVFF AARGB2,TEMPB2
CALL FXD1608U
MOVFF AARGB0,TEMPB0
MOVFF AARGB1,TEMPB1
MOVFF TEMPB2,AARGB1
MOVFF REMB0,AARGB0
CALL FXD1608U
MOVFF AARGB1,AARGB2
MOVFF TEMPB1,AARGB1
MOVFF TEMPB0,AARGB0
RETLW 0x00
;--------------------------------------------------------
FXD1608U
GLOBAL FXD1608U
MOVLW 0x01
CPFSGT BARGB0
GOTO DREMZERO8
FXD1608U1
GLOBAL FXD1608U1
BCF _C
CLRF TBLPTRH
RLCF BARGB0,W
RLCF TBLPTRH,F
ADDLW LOW (IBXTBL256+1) ; access reciprocal table
MOVWF TBLPTRL
MOVLW HIGH (IBXTBL256)
ADDWFC TBLPTRH,F
TBLRD *-
FXD1608U2
GLOBAL FXD1608U2
MOVFF AARGB0,REMB1
MOVFF AARGB1,REMB0
MOVF TABLAT,W ; estimate quotient
MULWF REMB1
MOVFF PRODH,AARGB0
MOVFF PRODL,AARGB1
TBLRD *+
MOVF TABLAT,W
MULWF REMB0
MOVFF PRODH,AARGB2
MULWF REMB1
MOVF PRODL,W
ADDWF AARGB2,F
MOVF PRODH,W
ADDWFC AARGB1,F
CLRF WREG
ADDWFC AARGB0,F
TBLRD *-
MOVF TABLAT,W
MULWF REMB0
MOVF PRODL,W
ADDWF AARGB2,F
MOVF PRODH,W
ADDWFC AARGB1,F
CLRF WREG
ADDWFC AARGB0,F
MOVF BARGB0,W
MULWF AARGB1
MOVFF PRODL,AARGB3
MOVFF PRODH,AARGB2
MULWF AARGB0
MOVF PRODL,W
ADDWF AARGB2,F
MOVF AARGB3,W ; estimate remainder
SUBWF REMB0,F
MOVF AARGB2,W
SUBWFB REMB1,F
BTFSS REMB1,MSB ; test remainder
RETLW 0x00
DECF AARGB1,F
CLRF WREG
SUBWFB AARGB0,F
MOVF BARGB0,W
ADDWF REMB0,F
RETLW 0x00
;----------------------------------------------------------
FXD1616U
TSTFSZ BARGB0
GOTO D1616B0GT0
MOVFF BARGB1,BARGB0
CALL FXD1608U
MOVFF REMB0,REMB1
CLRF REMB0
RETLW 0x00
D1616B0GT0
MOVF BARGB0,W
SUBWF AARGB0,W
BTFSS _C
GOTO D1616QZERO
BTFSS _Z
GOTO D1616AGEB
MOVF BARGB1,W
SUBWF AARGB1,W
BTFSS _C
GOTO D1616QZERO
D1616AGEB
MOVFF AARGB0,TEMPB0
MOVFF AARGB1,TEMPB1
MOVFF AARGB1,CARGB2
MOVFF AARGB0,AARGB1
CLRF AARGB0
MOVFF BARGB0,BARGB2
MOVFF BARGB1,BARGB3
BTFSC BARGB0,MSB
GOTO D1616UNRMOK
MOVF BARGB0,W
RLNCF WREG,F
ADDLW LOW (IBXTBL256+3) ; access reciprocal table
MOVWF TBLPTRL
MOVLW HIGH (IBXTBL256)
CLRF TBLPTRH
ADDWFC TBLPTRH,F
TBLRD *
MOVF TABLAT,W ; normalize
MULWF BARGB3
MOVFF PRODL,BARGB1
MOVFF PRODH,BARGB0
MULWF BARGB2
MOVF PRODL,W
ADDWF BARGB0,F
MOVF TABLAT,W
MULWF TEMPB1
MOVFF PRODL,CARGB2
MOVFF PRODH,AARGB1
MULWF TEMPB0
MOVF PRODL,W
ADDWF AARGB1,F
CLRF AARGB0
MOVF PRODH,W
ADDWFC AARGB0,F
D1616UNRMOK
CALL FXD1608U1 ; estimate quotient digit
MOVF AARGB1,W
MULWF BARGB1
MOVF PRODL,W
SUBWF CARGB2,W
MOVF PRODH,W
SUBWFB REMB0,W
BTFSS _C ; test
DECF AARGB1,F
D1616UQOK
MOVF AARGB1,W ; calculate remainder
MULWF BARGB3
MOVF PRODL,W
SUBWF TEMPB1,F
MOVF PRODH,W
SUBWFB TEMPB0,F
MOVF AARGB1,W
MULWF BARGB2
MOVF PRODL,W
SUBWF TEMPB0,F
; This test does not appear to be necessary in the 16 bit case, but
; is included here in the event that a case appears after testing.
; BTFSS TEMPB0,MSB ; test
; GOTO D1616QOK
; DECF AARGB1
; MOVF BARGB3,W
; ADDWF TEMPB1
; MOVF BARGB2,W
; ADDWFC TEMPB0
D1616QOK
MOVFF TEMPB0,REMB0
MOVFF TEMPB1,REMB1
RETLW 0x00
;---------------------------------------------------------
DGETNRMD
MOVLW 0x10
CPFSLT BARGB0
GOTO DGETNRMDH
DGETNRMDL
BTFSC BARGB0,3
RETLW 0x10
BTFSC BARGB0,2
RETLW 0x20
BTFSC BARGB0,1
RETLW 0x40
BTFSC BARGB0,0
RETLW 0x80
DGETNRMDH
BTFSC BARGB0,6
RETLW 0x02
BTFSC BARGB0,5
RETLW 0x04
BTFSC BARGB0,4
RETLW 0x08
;----------------------------------------------------------------------------------------------
; Routines for the trivial cases when the quotient is zero.
; Timing: 9,7,5 clks
; PM: 9,7,5 DM: 8,6,4
;D3232QZERO
; MOVFF AARGB3,REMB3
; CLRF AARGB3
;D2424QZERO
; MOVFF AARGB2,REMB2
; CLRF AARGB2
D1616QZERO
MOVFF AARGB1,REMB1
CLRF AARGB1
MOVFF AARGB0,REMB0
CLRF AARGB0
RETLW 0x00
DREMZERO8
CLRF REMB0
RETLW 0x00
;----------------------------------------------------------------------------------------------
; The table IBXTBL256 is used by all routines and consists of 16-bit
; upper bound approximations to the reciprocal of BARGB0.
IBXTBL256
GLOBAL IBXTBL256
DATA 0x0000
DATA 0x0001
DATA 0x8001
DATA 0x5556
DATA 0x4001
DATA 0x3334
DATA 0x2AAB
DATA 0x2493
DATA 0x2001
DATA 0x1C72
DATA 0x199A
DATA 0x1746
DATA 0x1556
DATA 0x13B2
DATA 0x124A
DATA 0x1112
DATA 0x1001
DATA 0x0F10
DATA 0x0E39
DATA 0x0D7A
DATA 0x0CCD
DATA 0x0C31
DATA 0x0BA3
DATA 0x0B22
DATA 0x0AAB
DATA 0x0A3E
DATA 0x09D9
DATA 0x097C
DATA 0x0925
DATA 0x08D4
DATA 0x0889
DATA 0x0843
DATA 0x0801
DATA 0x07C2
DATA 0x0788
DATA 0x0751
DATA 0x071D
DATA 0x06EC
DATA 0x06BD
DATA 0x0691
DATA 0x0667
DATA 0x063F
DATA 0x0619
DATA 0x05F5
DATA 0x05D2
DATA 0x05B1
DATA 0x0591
DATA 0x0573
DATA 0x0556
DATA 0x053A
DATA 0x051F
DATA 0x0506
DATA 0x04ED
DATA 0x04D5
DATA 0x04BE
DATA 0x04A8
DATA 0x0493
DATA 0x047E
DATA 0x046A
DATA 0x0457
DATA 0x0445
DATA 0x0433
DATA 0x0422
DATA 0x0411
DATA 0x0401
DATA 0x03F1
DATA 0x03E1
DATA 0x03D3
DATA 0x03C4
DATA 0x03B6
DATA 0x03A9
DATA 0x039C
DATA 0x038F
DATA 0x0382
DATA 0x0376
DATA 0x036A
DATA 0x035F
DATA 0x0354
DATA 0x0349
DATA 0x033E
DATA 0x0334
DATA 0x032A
DATA 0x0320
DATA 0x0316
DATA 0x030D
DATA 0x0304
DATA 0x02FB
DATA 0x02F2
DATA 0x02E9
DATA 0x02E1
DATA 0x02D9
DATA 0x02D1
DATA 0x02C9
DATA 0x02C1
DATA 0x02BA
DATA 0x02B2
DATA 0x02AB
DATA 0x02A4
DATA 0x029D
DATA 0x0296
DATA 0x0290
DATA 0x0289
DATA 0x0283
DATA 0x027D
DATA 0x0277
DATA 0x0271
DATA 0x026B
DATA 0x0265
DATA 0x025F
DATA 0x025A
DATA 0x0254
DATA 0x024F
DATA 0x024A
DATA 0x0244
DATA 0x023F
DATA 0x023A
DATA 0x0235
DATA 0x0231
DATA 0x022C
DATA 0x0227
DATA 0x0223
DATA 0x021E
DATA 0x021A
DATA 0x0215
DATA 0x0211
DATA 0x020D
DATA 0x0209
DATA 0x0205
DATA 0x0201
DATA 0x01FD
DATA 0x01F9
DATA 0x01F5
DATA 0x01F1
DATA 0x01ED
DATA 0x01EA
DATA 0x01E6
DATA 0x01E2
DATA 0x01DF
DATA 0x01DB
DATA 0x01D8
DATA 0x01D5
DATA 0x01D1
DATA 0x01CE
DATA 0x01CB
DATA 0x01C8
DATA 0x01C4
DATA 0x01C1
DATA 0x01BE
DATA 0x01BB
DATA 0x01B8
DATA 0x01B5
DATA 0x01B3
DATA 0x01B0
DATA 0x01AD
DATA 0x01AA
DATA 0x01A7
DATA 0x01A5
DATA 0x01A2
DATA 0x019F
DATA 0x019D
DATA 0x019A
DATA 0x0198
DATA 0x0195
DATA 0x0193
DATA 0x0190
DATA 0x018E
DATA 0x018B
DATA 0x0189
DATA 0x0187
DATA 0x0184
DATA 0x0182
DATA 0x0180
DATA 0x017E
DATA 0x017B
DATA 0x0179
DATA 0x0177
DATA 0x0175
DATA 0x0173
DATA 0x0171
DATA 0x016F
DATA 0x016D
DATA 0x016B
DATA 0x0169
DATA 0x0167
DATA 0x0165
DATA 0x0163
DATA 0x0161
DATA 0x015F
DATA 0x015D
DATA 0x015B
DATA 0x0159
DATA 0x0158
DATA 0x0156
DATA 0x0154
DATA 0x0152
DATA 0x0151
DATA 0x014F
DATA 0x014D
DATA 0x014B
DATA 0x014A
DATA 0x0148
DATA 0x0147
DATA 0x0145
DATA 0x0143
DATA 0x0142
DATA 0x0140
DATA 0x013F
DATA 0x013D
DATA 0x013C
DATA 0x013A
DATA 0x0139
DATA 0x0137
DATA 0x0136
DATA 0x0134
DATA 0x0133
DATA 0x0131
DATA 0x0130
DATA 0x012F
DATA 0x012D
DATA 0x012C
DATA 0x012A
DATA 0x0129
DATA 0x0128
DATA 0x0126
DATA 0x0125
DATA 0x0124
DATA 0x0122
DATA 0x0121
DATA 0x0120
DATA 0x011F
DATA 0x011D
DATA 0x011C
DATA 0x011B
DATA 0x011A
DATA 0x0119
DATA 0x0117
DATA 0x0116
DATA 0x0115
DATA 0x0114
DATA 0x0113
DATA 0x0112
DATA 0x0110
DATA 0x010F
DATA 0x010E
DATA 0x010D
DATA 0x010C
DATA 0x010B
DATA 0x010A
DATA 0x0109
DATA 0x0108
DATA 0x0107
DATA 0x0106
DATA 0x0105
DATA 0x0104
DATA 0x0103
DATA 0x0102
DATA 0x0101
END |
I'm not even sure what represents a function in there, but to start with at the top with lines like and
Man I'm so lost. |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 7:56 pm |
|
|
Ok, let's remember the MPASM reference is included with MPLAB.
So let's look at some code bits...
LSB equ 0
means a constant, LSB is defined as the value 0.
Same as #define LSB 0
Then,
AARGB0 RES 1
is the same as
| Code: | | static unsigned int8 AARGB0 |
So now let's take the first example and I'll comment the lines as we go with trailing //'s
| Code: |
;---------------------------------------------------------------------
; 24-BIT ADDITION
_24_BitAdd // Name/label of routine
GLOBAL _24_BitAdd // Declare this routine to make it available globally
movf BARGB2,w // move contents of BARGB2 into W
addwf AARGB2,f // add W and F (AARGB2)
movf BARGB1,w // Move BARGB1 into W
btfsc _C // Bit Test File (Status Reg Carry bit) - Skip next if clear
incfsz BARGB1,w // We have a carry from our previous add, so add that to BARGB1
addwf AARGB1,f // Add W and F (AARGB1)
movf BARGB0,w // Move BARGB0 into W
btfsc _C // Test that carry again
incfsz BARGB0,w // If carry set, increment BARGB0
addwf AARGB0,f // now add W to F (AARGB0)
return // Return from this routine.
|
Because of the low level of ASM vs C, those scratch variable have to be declared already (the RES statements at the top). Isn't a high-level language nice?
As a side note, AARGB0 is the most sig byte and AARGB2 is the least since as you can see, we need to add from the LSB up in order to properly utilize checking the carry.
So if you COULD unsigned int24 AARGB, you could just write AARGB += BARGB; and when you compile, you'd see something pretty similar in the .LST file of the compiler output.
Try this:
| Code: | unsigned int32 test;
test += 10;
|
in a program (separate function call) and see how it compiles.
So IF you could get those ASM files to assemble into .O's nicely, CCS could access them (possibly) as a function call (I don't think so) but MOST definitely
| Code: |
#asm
CALL _24_BitAdd
#endasm
| in some function you write.
And, because you can declare a global variable and then reference it inside the ASM code, then you can write stuff (syntax not quite exact) like this:
| Code: |
static unsigned int8 counter;
void addme (unsigned int8 var) {
#asm
movf var,w // move var into w
addwf counter, f // add var to counter
#endasm
}
|
I think I got that right.. Play with it.. and remember that both CCS and MPLAB have help that covers CCS's #ASM instruction syntax and MPASM's instruction syntax.
-Ben
p.s. In the land of micro's, knowing ASM is a good thing.. so this won't be wasted time. Over time, you'll look back at your compiled code and see when it's optimized and when it's not. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 8:45 pm |
|
|
For sure! It was so frustrating because I wasn't getting anywhere at all, but now with your help I'm starting to see some trees in this forrest.
But... where'd you find that? I looked at the MPASM help file and even found the reference but there's nowhere I could see that equated something like AARGB0 RES 1 to a static unsigned int8?? So perhaps if I saw that reference I'd be less dependent. The help I have says this about RES
| Quote: | res - Reserve Memory
Syntax
[label] res mem_units
Description
Causes the memory location pointer to be advanced from its current location by the value specified in mem_units. In relocatable code (using MPLINK linker), res can be used to reserve data storage. In non-relocatable code, label is assumed to be a program memory address.
Address locations are defined in words for PIC12/16 MCUs, and bytes for PIC18 MCUs.
Usage
This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Assembler Operation.
The most common usage for res is for data storage in relocatable code.
|
I gathered it must be an INT, but how do you know INT8 or that it is unsigned or static??
Cheers.[/quote] |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Fri Sep 04, 2009 11:23 pm |
|
|
| s_mack wrote: |
I gathered it must be an INT, but how do you know INT8 or that it is unsigned or static??
|
Well, ultimately, if you look at how memory (RAM) is organized, there's no concept of signed or unsigned.
It's up to the language to provide that feature in a sense.
As for "static" vs not... at least in my travels I've seen the use of volatile and static to describe declared variables... take either as you wish, but when they are especially declared OUTSIDE a function, they are typically global in nature. That concept of local vs. global is yet another "feature" that the compiler provides.
in ASM, you have to keep track of variables you might use for doing stuff. In 'C' -- that's done for you. global vars are assigned once and stay fixed in memory where locals can be re-used, thus saving on RAM.
You could do this in ASM, it's just YOU that has to track it vs. the compiler doing it for you.
Now, the PIC does have (in the 18F's anyway) a BNN instruction which tests an operand to see if it's negative, so that's nice -- but again in the system a byte is a byte.. the concept of negative or positive is something the user or compiler has to apply (possibly through the use of BNN and other methods.)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Fri Sep 04, 2009 11:45 pm |
|
|
very good, thank you ben. I thought you had a better help file then I did.
You've been most helpful in this, thank you. |
|
 |
s_mack
Joined: 04 Jun 2009 Posts: 107
|
|
Posted: Sat Sep 05, 2009 10:46 am |
|
|
Why is STATUS never declared anywhere? It must be special. So I tried looking it up in the help files but I can't figure out how to translate that to c.
Why can't ccs just bloody well import a MPASM o file like its own help file says it should!!! |
|
 |
|
|
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
|