In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Sparks-R-Fun wrote: Bill, It is not clear to me (and perhaps to others) what you are using as your measure of efficiency. Possibilities include clock cycles, the number of instructions, the amount of memory used or even the number of SX/B statements required. You will need to think of SX/B efficiency differently than how you may tend to think of it in relation to the Basic Stamps. SX/B instructions might translate into anywhere from one to many assembly statements. With the Basic Stamps, each instruction basically translates into one 'token' with its associated variables. Until you become familiar with SX assembly I would urge you not to worry too much about efficiency. (It sounds strange, I know. Perhaps others will disagree with me.) When you write an SX/B program, take at look at its assembly source listing (CTRL-L). This will help you the most. You will soon learn where the greatest improvements in efficiency can be made. Some functions, such as SERIN and SEROUT, generate large blocks of assembly code each time they are encountered in your program. So it is a more efficient use of code space to include such functions only once in your program. Just call them as a subroutine each time you need them. Other functions perform initialization steps which might only be needed once. If you split those instructions into two separate assembly sections you might gain some efficiency in terms of clock cycles for your program. You will have to decide if it is worth the effort. Honestly, the SX operates so fast that unless you are critically short on your timing in a certain section of code or you find yourself running out of memory, you really will not need to focus on efficiency as much as you might think. [b]Comments on Your Code:[/b] Basme's code outputs the high nibble first. Your code sections do not. Try changing your second code segment to look like this: [code]Send_Inst: LOW RS RB = Inst ' Sends High nibble first PULSOUT E, 3 ' TEMP1 = Inst << 4 ' Creates an 8 bit "LOWNIBBLE" variable by ' sending 0000 zeros on pins 0 to 3 RB = Temp1 ' Outputs the LSB low nibble and LSB values 'RB = Inst ' are sent to ground PULSOUT E,3 GOSUB Wait_Busyflag HIGH RS RETURN [/code] With everything else being equal, it does appear that your second code section uses four fewer assembly code primitives and thus runs four clock cycles faster than the section of Basme's code you reference. Does that help? - Sparks ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=161442#m161521 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)