In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: Most times simpler is better. Consider these three (dirt simple) functions that do what you want. They are easy to use and don't require any program variables -- the functionality is so simple it can be handled in assembly using SX/B's internal parameter variables. [code]NIB_LO FUNC 1, 2, 2, Byte, Byte, Byte NIB_HI FUNC 1, 2, 2, Byte, Byte, Byte MERGE FUNC 1, 2, 2, Byte, Byte, Byte[/code] [code]' Use: bResult = NIB_LO target, value ' -- moves value into low nibble of target ' -- value truncated to four bits FUNC NIB_LO ASM AND __param1, #$F0 ' clear low nib AND __param2, #$0F ' truncate to 4 bits OR __param1, __param2 ' merge ENDASM ENDFUNC ' Use: bResult = NIB_HI target, value ' -- moves value into high nibble of target ' -- value truncated to four bits FUNC NIB_HI ASM AND __param1, #$0F ' clear high nib AND __param2, #$0F ' truncate to 4 bits SWAP __param2 ' move value to high nib OR __param1, __param2 ' merge ENDASM ENDFUNC ' Use: bResult = MERGE value1, value2 ' -- merge two 4-bit values into a byte ' -- value1 to high nibble, value2 to low nibble ' -- values truncated to four bits FUNC MERGE ASM AND __param1, #$0F ' truncate to 4 bits SWAP __param1 ' move to high nibble AND __param2, #$0F ' truncate to 4 bits OR __param1, __param2 ' merge ENDASM ENDFUNC[/code] I know, I know... Assembly is supposed to be "hard." Well, it really isn't and I am frequently adding very efficient Assembly sections to my SX/B programs. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=408151#m408371 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)