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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/26/08 18:31
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#152578 - How about this? (union, C-compiler, assembler)
Responding to: ???'s previous message
You seem to need the code in assembler (otherwise you
probably wouldn't ask for 24bit).

Let a C-compiler (using sdcc here) do some work for you:

#include <8052.h>

/* using a union so the data can be accessed as bytes or as long word */
union
{
    unsigned long a;
    struct
    {
        // is this your endianness?
        unsigned char b0;
        unsigned char b1;
        unsigned char b2;
        unsigned char b3;
    } b;
} myvar;

volatile char e;


void main()
{
   myvar.b.b0 = P1;  /* just to have something */
   myvar.b.b1 = P2;  /* just to have something */
   myvar.b.b2 = P3;  /* just to have something */

   if (myvar.a > 0x0649C6) /* look at the assembler source and eventually remove the last compare */
      e++;
}

generates this code with "sdcc 24bit_comp.c":

   0000                     366 _main:
                            375 ;       24bit_comp.c:22: myvar.b.b0 = P1;  /* just to have something */
   0000 85 90*00            376         mov     _myvar,_P1
                            377 ;       24bit_comp.c:23: myvar.b.b1 = P2;  /* just to have something */
   0003 85 A0*01            378         mov     (_myvar + 0x0001),_P2
                            379 ;       24bit_comp.c:24: myvar.b.b2 = P3;  /* just to have something */
   0006 85 B0*02            380         mov     (_myvar + 0x0002),_P3
                            381 ;       24bit_comp.c:26: if (myvar.a > 0x0649C6) /* look at the assembler source and eventually remove the last compare */
   0009 C3                  382         clr     c
   000A 74 C6               383         mov     a,#0xC6
   000C 95*00               384         subb    a,_myvar
   000E 74 49               385         mov     a,#0x49
   0010 95*01               386         subb    a,(_myvar + 1)
   0012 74 06               387         mov     a,#0x06
   0014 95*02               388         subb    a,(_myvar + 2)
   0016 E4                  389         clr     a
   0017 95*03               390         subb    a,(_myvar + 3)
   0019 50 02               391         jnc     00103$
                            392 ;       24bit_comp.c:27: e++;
   001B 05*04               393         inc     _e
   001D                     394 00103$:
   001D 22                  395         ret


Greetings,
Frieder

List of 7 messages in thread
TopicAuthorDate
24 bit number comparison in a 8 bit mc            01/01/70 00:00      
   assembler or C            01/01/70 00:00      
   How about this? (union, C-compiler, assembler)            01/01/70 00:00      
      helpful!            01/01/70 00:00      
         OT: shifting 32 bit            01/01/70 00:00      
            re: OT: shifting 32 bit            01/01/70 00:00      
   Thanks            01/01/70 00:00      

Back to Subject List