caramoan tour package

caramoan tour package

Author Topic: Code Compression (tips and tricks)  (Read 15289 times)

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #120 on: March 29, 2008, 11:05:14 PM »
hindi naman hijo, union is a standard C data type. Try it in CCS C or SDCC and they will not complain. They are designed to handle such complicated data structure. You can also put a structure inside a union.
tito,
di ko pa rin ma-gets yang union na yan..  :'(
ang alam ko lang na union is yung group ng mga employees,
yung group na magbo-boycott sa trabaho pag di maganda ang palakad ng company.. hehe  ;D


dito na lang nga ako mag-aagre:
Quote
Kung malaki naman ang RAM/ROM , why bother to save space? Once naman na nagkasya yung code mo sa chip - that's it! The important thing is that your project goal is achieved.  ;)
ahihihi  :D
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #120 on: March 29, 2008, 11:05:14 PM »

Offline Mentor Lee

  • Size C Battery
  • *****
  • Posts: 193
  • Pogi/Ganda Points: 16
  • Gender: Male
  • "Call to Me and I will answer you.....
Re: Code Compression (tips and tricks)
« Reply #121 on: March 30, 2008, 12:10:06 AM »
Quote
di ko pa rin ma-gets yang union na yan..  Cry
ang alam ko lang na union is yung group ng mga employees,
yung group na magbo-boycott sa trabaho pag di maganda ang palakad ng company.. hehe  Grin
;D ;D
Tama ka hijo . at ang dapat na inilalagay sa loob ng union ay mga tulad mong agresibo para sigurado, bankarote agad ang kompanya  :D :D
...and show you great and inscrutable things that you do not know "
--Hotline 333--

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #121 on: March 30, 2008, 12:10:06 AM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #122 on: March 30, 2008, 01:18:11 AM »
 ;D ;D ;D
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #122 on: March 30, 2008, 01:18:11 AM »

Offline RRcom

  • CR2032 Battery
  • **
  • Posts: 45
  • Pogi/Ganda Points: 3
Re: Code Compression (tips and tricks)
« Reply #123 on: March 30, 2008, 02:57:16 AM »
im agree talaga na di mo kaylangan ng maraming programming language para maging expert kundi mag focus ka lang sa isa o dalawa at kaalaman naman sa iba upang maging bihasa katulad ng enumeration structure and union sa c kung mabibihasa lahat ng tamang paggamit ng sintax at pag combination ng code kaya mong pabilisin at paliitin ang code at di mo kaylangan isisi sa language na napili mo kung bakit mabagal o malaki ang code na nagawa mo, katulad ng una kong program gumawa ako ng maraming character string halos mapuno ang isang notebook sa character pero kinapos ako sa ram memory pero alam kong marami pa akong program memory may bagay akong naiisip bat di ko kaya gawin ko silang constant variable, pero diba para wala paring mangyayari dahil diko naman binawasan variable kundi ginawa ko lang constant, pero naisip ko na kung ako ang compiler eh alam ko namang constant bakit ko ilalagay sa ram hindi naman sya kaylangan baguhin diba pwede naman sila gawing literal nalang at yun nga ginawa ng compiler ko. dun ko rin naisip na kaylangan na di lang sa sintax kundi pati Behaviour ng compiler ay kaylangan din intindihin.
Made in Calamba City

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #123 on: March 30, 2008, 02:57:16 AM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #124 on: March 30, 2008, 09:53:22 AM »
..at ang dapat na inilalagay sa loob ng union ay mga tulad mong agresibo para sigurado, bankarote agad ang kompanya..
tito, pwede bang mag-apply sa company nyo ?   ??? :D

.. im agree talaga na di mo kaylangan ng maraming programming language para maging expert kundi mag focus ka lang sa isa o dalawa at kaalaman naman sa iba upang maging bihasa..
may advantage naman siguro (sa resume  ;D) kung marami kang alam na programming language..  :D
saka gusto ko lang ma-try ang mga different languages para malaman ko kung alin ang pinaka-efficient..  ;)
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #124 on: March 30, 2008, 09:53:22 AM »

Offline Mentor Lee

  • Size C Battery
  • *****
  • Posts: 193
  • Pogi/Ganda Points: 16
  • Gender: Male
  • "Call to Me and I will answer you.....
Re: Code Compression (tips and tricks)
« Reply #125 on: March 30, 2008, 08:37:22 PM »
tito, pwede bang mag-apply sa company nyo ?   ??? :D
Hindi naman semiconductor or programming related yung company namin. Power plant ito hijo  ;D. and I am an electrical engineer. Passion ko lang talaga ang programming & electronics. ;) :D

Quote
may advantage naman siguro (sa resume  ;D) kung marami kang alam na programming language..  :D
saka gusto ko lang ma-try ang mga different languages para malaman ko kung alin ang pinaka-efficient..  ;)
Tumpak! Take it from my experience, habang bata basa ng basa at gawa ng gawa para maraming natututunan sa buhay. Kailangan ang gawa ( hndi ngawa ) kasi kung walang practical, walang silbi yung nabasa mo. It's a free world. Take advantage of it.


...and show you great and inscrutable things that you do not know "
--Hotline 333--

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10720
  • Pogi/Ganda Points: 630
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #126 on: March 30, 2008, 10:11:07 PM »
pag gumamit ka ng union at structure, check mo rin yung assembly kung mas maliit ba yung implementation or kung mas mabilis...

----------

minsan ok rin maraming alam na programming language lalo na kung madalas ka sa mga ganitong site...

http://www.getafreelancer.com

 ;D ;D ;D

Software Development is a discipline of studying and implementing algorithms, not really specific to any language...although, you must master at least one language in a certain Paradigm...
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #127 on: March 30, 2008, 10:26:39 PM »
minsan ok rin maraming alam na programming language lalo na kung madalas ka sa mga ganitong site...

http://www.getafreelancer.com

meron pala talaga nito.. magandang sideline 'to.. ahihihi  :D
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10720
  • Pogi/Ganda Points: 630
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #128 on: March 30, 2008, 10:30:09 PM »
yung mga Software Developers talaga ang madaling maka-sideline...kaya nag-aaral na din ako... ;D
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #129 on: July 08, 2008, 10:00:10 AM »
question:
sa C language PIC programming,
alin ang mas efficient na gamitin (in term of code size and speed of execution):
yung maraming if-else o switch-case ? ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Code Compression (tips and tricks)
« Reply #130 on: July 08, 2008, 10:10:47 AM »
On Hitech, switch-case is more code efficient.
Case comparisons are done via XORed values of the previous comparisons.

In assembly it is much leaner.
Example testing values with 'A', 'B', 'C' and 'D':
Code: [Select]

    movf  char, W
 
    xorlw  'A'
    skpnz
     goto  process_A
 
    xorlw  'A' ^ 'B'
    skpnz
     goto  process_B

    xorlw  'A' ^ 'B' ^ 'C'
    skpnz
     goto  process_C

    xorlw  'A' ^ 'B' ^ 'C' ^ 'D'
    skpnz
     goto  process_D

    goto  not_valid

The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #131 on: July 08, 2008, 10:16:59 AM »
On Hitech, switch-case is more code efficient.
Case comparisons are done via XORed values of the previous comparisons.

thanks!
maybe the same lang din sa CCS C..
kagabi ko lang kasi na-try yung switch-case,
kahit nung nag-aaral pa lang kami ng turbo C++ nung college, laging if-else ang ginagamit ko..  :D
mas convenient pala yung switch-case..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10720
  • Pogi/Ganda Points: 630
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #132 on: July 08, 2008, 01:33:48 PM »
kung puro numbers lang ang case, parang offset table lang para kung saan tatalon yung Program Counter. mas mahaba equivalent code ng series of if-else.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #133 on: July 09, 2008, 06:05:16 PM »
para sa akin mas readable ang switch-case lalo na kung napakahaba.. pero kalimitan ginagawa ko (lalo na pag alam kong hahaba ang switch case ko) is yung array function pointers.
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #134 on: July 09, 2008, 07:29:30 PM »
.. pero kalimitan ginagawa ko (lalo na pag alam kong hahaba ang switch case ko) is yung array function pointers.
pa'no naman 'to? ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10720
  • Pogi/Ganda Points: 630
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #135 on: July 09, 2008, 07:42:52 PM »
madalas ko ring makita yan sa state machine ng ibang source code.

typically ilalagay mo sa isang array ang pointers to functions.

eto may nakita akong short tutorial. baka mas madali intindihin dito. ;D

http://www.newty.de/fpt/fpt.html
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #136 on: July 09, 2008, 08:06:09 PM »
yup, nung nag aaral ako ng state machine ko natutunan ang technique ng array of functions pointers ;D ;D kaya gamit na gamit hanggang ngayon hehehe ;D ;D ;D

kaya ang code na:

Code: [Select]
switch x
{
case 0:
   mymeth();
   break;
case 1:
   myanothermeth();
   break;
default:
   breakl
}


napapaiksi ng ganito

Code: [Select]
myfunctionarraypointer[x](); //myfunctionarraypointer is an array of function pointer to mymeth() and myanothermeth()
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #137 on: July 09, 2008, 08:43:12 PM »
ibig sabihin mas compressed pa yung resulting hexcodes?  ??? :o
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Code Compression (tips and tricks)
« Reply #138 on: July 10, 2008, 08:23:21 AM »
In PIC assembly you could do similar and is leaner:

Code: [Select]
fn_array:
    andlw 0x03    ;ensure that we don't go to limbo
    addwf PCL,f
    goto func_0
    goto func_1
    goto func_2
    return            ;put a 'return' on unused slot

func_0:
    ...
    return

func_1:
    ...
    return

The Cebuano Geek

Offline motion55

  • Technical People
  • Diesel Generator
  • *****
  • Posts: 1878
  • Pogi/Ganda Points: 243
  • Gender: Male
  • Been at this longer than you've been alive.
Re: Code Compression (tips and tricks)
« Reply #139 on: July 10, 2008, 09:48:23 AM »
In PIC assembly you could do similar and is leaner:

Code: [Select]
fn_array:
    andlw 0x03    ;ensure that we don't go to limbo
    addwf PCL,f
    goto func_0
    goto func_1
    goto func_2
    return            ;put a 'return' on unused slot

func_0:
    ...
    return

func_1:
    ...
    return


For the PIC18 family, instead of the "computed goto" which limits the range of where you can place the functions and which also breaks should the "goto" table cross a 256 byte page boundary, I use a different technique utilizing the "Top Of Stack" as follows:

Code: [Select]
;-----------------------------------------------------------
         MOVLW   LOW  FUNCTION_TABLE
         MOVWF   TBLPTRL
         MOVLW   HIGH FUNCTION_TABLE
         MOVWF   TBLPTRH
         CLRF      TBLPTRU
;
         MOVF     FUNCTION_NO,W
         ANDLW   B'00000111'
         RCALL    TOS_GOTO
FUNCTION_TABLE:
         DW        FUNCTION1
         DW        FUNCTION2
         DW        FUNCTION3
         DW        FUNCTION4
         DW        FUNCTION5
         DW        FUNCTION6
         DW        FUNCTION7
         DW        FUNCTION8
FUNCTION_TABLE_END:
;-----------------------------------------------------------
TOS_GOTO:
         ADDWF    WREG,W        ; X2
         ADDWF    TBLPTRL,F
         SKPNC
         INCF     TBLPTRH,F
;
         TBLRD*+
         MOVF     TABLAT,W
         MOVWF    TOSL
;
         TBLRD*+
         MOVF     TABLAT,W
         MOVWF    TOSH
;
         RETURN
;-----------------------------------------------------------

The address taken from the function table is written to the top of the stack and then a "RETURN" instruction is executed.

///////////////////////////////////////////////////////////////////////

And I agree, I extensively use the state machine technique for writing programs for embedded controllers specially for complex machines.

1. You have to realize that when writing software for automated equipment, you are essentially debugging two animals. The software itself and then there is the machine. Often it is harder to debug the machine than the software program. The controller CPU operates in the microsecond/nanosecond steps while the mechanical machine's time scale is the milliseconds, thousands of times slower. A complex machine can have several mechanisms operating almost independently of each other. You can assign a separate state machine for each one.

2. Because of tight delivery commitments, you would be writing the software while the machine is still being fabricated. The mechanical engineer can make changes to the machine design and you should have a way to quickly modify the sequence of operation in the software program.

3. It is easier to debug. The machine can jam and you have to find way to recover from that jam. You can single step the machine while debugging.

"Set your mind free!"

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #139 on: July 10, 2008, 09:48:23 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com