In SX Microcontrollers, SX/B Compiler and SX-Key Tool, PJMonty wrote: SailorMan, One thing to keep in mind is that the assembly in the first post was machine generated by the SX/B compiler. Machine generated assembly code is harder for humans to read since it doesn't make human comprehension a priority. I have gone through with a plain old text editor and done a search and replace to convert the unfriendly variable names with human friendly versions. There are two things to notice here: 1 - Just changing variables names to something with meaning makes assembly code easier to read. 2 - ALWAYS use good variables names (such as "PwmCount") and not weak variable names (such as "Count" or "Cnt" or "C" to make the code easier to comprehend at a glance. Here's the easier to read version: [code]INTERRUPT ASM ' ** Setup variables MOV NumBitsPerPort,#4 ' (2) Number of bits per port MOV BitOn_OrMask,#1 ' (2) OR Mask for turning a bit ON MOV BitOff_AndMask,#254 ' (2) AND Mask for turning a bit OFF INC PWM_Count ' (1) Adjust the PWM count ' If the PWM value for each channel is ' less than PWM_Count then it should ' be high, othewise it should be low MOV PwmCount_Global,PWM_Count ' (2) Make copy of PWM_Count in global memory MOV FSR,#PWM_Values ' (2) Set FSR to address of 1st element of PWM values :NEXT_BIT CJA IND,PwmCount_Global,@:MAKE_HIGH_B ' (5/7) If this element is above PWM_Count ' Then jump to MAKE_HIGH_B AND RB,BitOff_AndMask ' (2) Value is below or equal to PWM_Count so ' make it low. JMP @:DONE_BIT_B ' (4) Jump over MAKE_HIGH code :MAKE_HIGH_B OR RB,BitOn_OrMask ' (2) Value is above PWM_Count so make it HIGH NOP ' (1) Waste time NOP ' (1) Waste time :DONE_BIT_B STC ' (1) Need to shift a 1 into AND mask value RL BitOff_AndMask ' (1) Shift AND mask value CLC ' (1) Need to shift a 0 into OR mask value RL BitOn_OrMask ' (1) Shift OR mask value INC FSR ' (1) Point to next array element DJNZ NumBitsPerPort,@:NEXT_BIT ' (3/5) Repeat until done ENDASM ReturnInt[/code] BTW, you can make this even easier to read by copying it into the SX-Key IDE or any text editor that uses a non-proportional font. That will makes the comments line up correctly. [list]Thanks, PeterM[/list] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=153024#m153113 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)