Lasse Madsen wrote: > >If forinstance i have a counter which counts from 0 towards 8 and at the >present moment it has reached 5 how would i drag that 5 out from memory and >compare it with numbers from 0 to 8 and if a match is found proceed with >another function ? > >If the counter counted maybe i could say: > >N equ 0x1a > > movlw 8 >go sublw N > btfss status,5 > goto go > goto do_something > >Right ? > Since I haven't seen any other responses to this message, I'll take a shot at it: I'm not quite sure exactly what you're trying to accomplish here. It appears that you have confused the SUBLW (Subtract W from Literal) instruction with SUBWF (Subtract W from f). Your code will repeatedly subtract the address of your N variable (not its value) from W until it reaches zero. Since W is initially set to 8 and the address of N is specified as 0x1a, the number of loops is constant and not dependent on the value of the N variable. Subtract 26 from W (putting the result in W) repeatedly using 8-bit math if you really want to find out how many. It should eventually wrap to zero. If it doesn't, it will loop forever. Well, DUH, the paragraph I just wrote turns out to be total rubbish. I just looked up the bits in the STATUS register. The Z flag is bit 2 rather than bit 5. I ASSumed that you were testing for the zero condition. This code will actually loop until bit RP0 in STATUS gets set. Since there is nothing here to set RP0, it should loop forever. Some suggestions: 1) Use the CBLOCK...ENDC directive pair to assign addresses for your variables rather than hard-coding absolute addresses for them. 2) Use *descriptive* variable names. (Single-letter names are fine for algebra but they really suck for programming.) Avoid 'magic numbers' by equating constants to meaningful names. 3) Use the standard Microchip include files (e.g. p16f84.inc) to provide definitions for processor registers and bit positions. A line that says "btfss STATUS, Z" tells you what's actually happening - skip if the Z bit in STATUS is set. (Some people prefer to use skpz and skpnz macros, YMMV.) 4) Use the MPLAB simulator to learn what's really happening as your code executes. In assembly language, there are far more details to concern yourself with than in higher level languages. 5) Study other people's code for further ideas. Many PIClisters consistently use excellent programming practices. To check for a variable matching a specific value, something along these lines should do the trick: (Please ignore the dots, my mailer doesn't do multiple spaces well.) check_value..equ..5 . . ...movlw...check_value......(the constant you are comparing to) ...subwf...your_variable,w..(result to W, don't trash your variable) ...btfsc...STATUS,Z.........(if Z is clear, skip for no match) ...goto....matched..........(if Z is set, result = 0, value matched) . ..........(continue with non-match code here) . match:....(here if the variable matched check_value) . . Sorry for such a lengthy reply. I hope this helps. Regards, Bob _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body