Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/12/09 16:46
Read: times


 
#165272 - I would not do this in 'C'
Responding to: ???'s previous message
I should preface this comment with the statement that I'm not one who uses 'C' or other HLL's for tasks small enough to fit in an 8-bit MCU. That's because I've always used ASM, with many different CPU architectures, and have never become totally "happy" with HLL's for small machines.

There are features in the 805x instruction set that make this sort of thing VERY straightforward in ASM.

You receive one of 8 commands, presumably via serial port. That command is then in 'A' when you retrieve it from SBUF. If your "main dispatch loop" has the address of a "default" jump table loaded into DPTR, then the JMP @A+DPTR instruction quite useful, as it then transfers control to a program segment presumably dedicated to that specific command. Before you can use that instruction, you must left-shift the byte so that there's room for two bytes of address in the table entry.

This approach is both very fast and very reliable, as it avoids using stack or other memory resources, aside from nonvolatile code memory. Since there are only eight basic commands, it would probably be useful to use a lookup table to reduce the size of the integer in A. To accomplish that, you'd use the MOVC A, @A+DPTR to perform the reduction. MOVC A, @A+PC might be useful in order to produce a smaller table. If you think about how these simple instructions work, you'll quickly see that they're intended for exactly what you need to do.

If you process multi-byte commands, each one will best be reduced in some way, either by code or by table lookup, and the code segment that processes the first byte will vector to the code segment that processes the second byte, and so on.

Programming this sort of thing in 'C' is as difficult as doing it in ASM. If you're really uncomfortable in ASM, then 'C' can do it too, albeit much more slowly and with considerably more code space consumed. That may not be a particularly big penalty for you, however.

RE


List of 29 messages in thread
TopicAuthorDate
Command Processor            01/01/70 00:00      
   More detail required            01/01/70 00:00      
      Command Processor            01/01/70 00:00      
         Standard Async Serial (updated)            01/01/70 00:00      
         What is it that you need?            01/01/70 00:00      
            Command Processor            01/01/70 00:00      
               What compiler?            01/01/70 00:00      
                  Code to Get command            01/01/70 00:00      
                     Buffer overflow...            01/01/70 00:00      
                        Sorry            01/01/70 00:00      
                     did you retype the code?? ....            01/01/70 00:00      
                        This code is translated            01/01/70 00:00      
                           Alternative parsing            01/01/70 00:00      
                              Code to Get command            01/01/70 00:00      
                           wasteful            01/01/70 00:00      
               I would not do this in 'C'            01/01/70 00:00      
                  Thank you            01/01/70 00:00      
                     Assembler floating point?            01/01/70 00:00      
                        I didn't say he shouldn't use 'C' at all ...            01/01/70 00:00      
                  'C' may not be that bad            01/01/70 00:00      
                     Just this particular function would be very fast in ASM            01/01/70 00:00      
                        Maybe; maybe not...            01/01/70 00:00      
                           The opinion that assembler is faster than C            01/01/70 00:00      
                              In this case, speed isn't a big factor.            01/01/70 00:00      
                                 dead easy and it will not work if you do not            01/01/70 00:00      
                                    no (keil?) C will work if the main is in asm            01/01/70 00:00      
                                       What I was considering            01/01/70 00:00      
                  I WOULD write thsi in C            01/01/70 00:00      
                     Thta doesn't surprise me.            01/01/70 00:00      

Back to Subject List