In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: John, as Paul mentioned, follwing a skip instruction by a compound statement is a real killer! The latest version of the SX-Key IDE should give you a warning though. Besides this, your original code contains another "killer". By no means do I want to offend you - I made the same mistakes more than once but I think this is a "nice" example, helping the SX fellow programmers avoiding such bugs. Here is your original code again: [code]:DO MOV M,#tmsg >> 8 ;move top 4 bits of tmsg into the m register mov W,#tmsg & 255 ;move bottom 8 bits into the W register add W, idx ;add the index to the address to get the position snc ;skip adding 1 to the top 4 bits if W didnt roll over to 0 mov M,#(tmsg >> 8) +1 ;problem child IREAD ;reads the char and pos w+m into W mov char, W ;moves the char at w into char CJE char,#0,@scroll ;done with the top line, do the bottom line now call @LCD_OUT ADD idx,#1 JMP @:DO[/code] In the second and third lines, you prepare W to hold the lower eight bits for the IREAD. In the fifth line, there is the compound mov M, #(tmsg >> 8) + 1 instruction that will be replaced by SASM as follows: mov W, #(tmsg >> 8) + 1 mov M, W Assuming that the SNC instruction would not be executed as this would lead to chaos anyway, it means that the original contents of W (the lower 8 bits for the IREAD) are overwriten here, as the W register is used as temporary storage for the compound instruction. IOW: As almost all compound instructions make use of the W register for temporary storage, any initialization of W done before executing a compound statement is most likely lost afterwards. Sometimes, you may make use of the fact that W is used as temporary storage. For example: mov Foo1, #5 mov Foo2, #5 is expanded into mov W, #5 mov Foo1, W mov W, #5 mov Foo2, W As you can see, W is initialized to #5 twice, so you could write mov Foo1, #5 mov Foo2, W instead which expands into mov W, #5 mov Foo1, W mov Foo2, W Nevertheless, I can't recommend such "tricky" constructs at all. Imagine the following context: mov W, #1 mov Foo1, #5 mov Foo2, W Thius might make someone believe that Foo2 receives #1 which is definitely not the case - Foo2 will be 5 (see above). Therefore, I highly recommend not to use compound statements at all in such context. Replacing the code by mov W, #1 mov W, #5 mov Foo1, W mov Foo2, W makes it very obvious that the first mov W,#1 has no meaning at all. Happy programming! ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=84844#m84994 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)