View previous topic :: View next topic |
Author |
Message |
Andrew-miksys
Joined: 11 Sep 2007 Posts: 7
|
simple conversion c->asm |
Posted: Thu Jan 10, 2008 11:25 am |
|
|
I'm trying do convert:
Code: | counter = 256*TMR1H + TMR1L; |
to
Code: |
#asm
movf TMR1H,W
movwf high counter
movf TMR1L,W
movwf low counter
#endasm
|
but compiler don't know operator 'low' and 'high'.
What is other way to do that? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 10, 2008 11:52 am |
|
|
Simplest way to find out is to compile your C code and than have a look at the list file (*.lst) to see what assembly the compiler generated.
I wouldn't use assembly at all. It is hard to read, not portable and there is no need to use it.
Code: | counter = make16(TMR1H, TMR1L); | This will compile to just as short assembly code as your example. |
|
|
Andrew-miksys
Joined: 11 Sep 2007 Posts: 7
|
|
Posted: Thu Jan 10, 2008 5:17 pm |
|
|
make16() doing exactly what I need! Thanks!
BDW here is 'compiler' optimalization
Code: |
.................... counter = 256*TMR1H + TMR1L;
; address of TMR1H is 0x0F
; address of TMR1L is 0x0E
; address of counter is 0x58,0x59
; both in bank0
0321: MOVF 0F,W
0322: BSF 03.5
0323: BSF 03.6
0324: MOVWF 11
0325: CLRF 10
0326: BCF 03.5
0327: BCF 03.6
0328: MOVF 0E,W
0329: BSF 03.5
032A: BSF 03.6
032B: ADDWF 10,W
032C: BCF 03.5
032D: BCF 03.6
032E: MOVWF 59
032F: BSF 03.5
0330: BSF 03.6
0331: MOVF 11,W
0332: BCF 03.5
0333: BCF 03.6
0334: MOVWF 5A
0335: BTFSC 03.0
0336: INCF 5A,F
|
|
|
|
|