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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/16/09 20:42
Read: times


 
#162493 - maybe use a compiler
Responding to: ???'s previous message
you could also use a compiler and throw a C-snippet at it:

#include <8052.h>

void main (void)
{
    unsigned char uc, uc2;
             char  c,  c2;

    c  = uc  = P0;
    c2 = uc2 = P2;

    /* unsigned comparison */
    if( uc >  uc2 )
        goto noonecares;
    if( uc >= uc2 )
        goto noonecares;
    if( uc == uc2 )
        goto noonecares;
    if( uc <  uc2 )
        goto noonecares;
    if( uc <= uc2 )
        goto noonecares;

    /* signed comparison */
    if( c >  c2 )
        goto noonecares;
    if( c >= c2 )
        goto noonecares;
    if( c == c2 )
        goto noonecares;
    if( c <  c2 )
        goto noonecares;
    if( c <= c2 )
        goto noonecares;


    while(1)
        ;

noonecares:
    while(2)
        ;
}

 

with f.e. SDCC (and command line option --nogcse so the compiler may not keep global common subexpressions) you arrive at:

                            355 ;uc                        Allocated to registers r2 
                            356 ;uc2                       Allocated to registers r4 
                            357 ;c                         Allocated to registers r3 
                            358 ;c2                        Allocated to registers r5 

   0000                     364 _main:
                            373 ;	compare2.c:8: c  = uc  = P0;
   0000 AA 80               374 	mov	r2,_P0
   0002 AB 80               375 	mov	r3,_P0
                            376 ;	compare2.c:9: c2 = uc2 = P2;
   0004 AC A0               377 	mov	r4,_P2
   0006 AD A0               378 	mov	r5,_P2
                            379 ;	compare2.c:12: if( uc >  uc2 )
   0008 C3                  380 	clr	c
   0009 EC                  381 	mov	a,r4
   000A 9A                  382 	subb	a,r2
                            383 ;	compare2.c:14: if( uc >= uc2 )
   000B 40 4D               384 	jc	00126$
   000D EA                  385 	mov	a,r2
   000E 9C                  386 	subb	a,r4
   000F 50 49               387 	jnc	00126$
                            388 ;	compare2.c:16: if( uc == uc2 )
   0011 EA                  389 	mov	a,r2
   0012 B5 04 02            390 	cjne	a,ar4,00143$
   0015 80 43               391 	sjmp	00126$
   0017                     392 00143$:
                            393 ;	compare2.c:18: if( uc <  uc2 )
   0017 C3                  394 	clr	c
   0018 EA                  395 	mov	a,r2
   0019 9C                  396 	subb	a,r4
                            397 ;	compare2.c:20: if( uc <= uc2 )
   001A 40 3E               398 	jc	00126$
   001C EC                  399 	mov	a,r4
   001D 9A                  400 	subb	a,r2
   001E 50 3A               401 	jnc	00126$
                            402 ;	compare2.c:24: if( c >  c2 )
   0020 C3                  403 	clr	c
   0021 ED                  404 	mov	a,r5
   0022 64 80               405 	xrl	a,#0x80
   0024 8B F0               406 	mov	b,r3
   0026 63 F0 80            407 	xrl	b,#0x80
   0029 95 F0               408 	subb	a,b
                            409 ;	compare2.c:26: if( c >= c2 )
   002B 40 2D               410 	jc	00126$
   002D EB                  411 	mov	a,r3
   002E 64 80               412 	xrl	a,#0x80
   0030 8D F0               413 	mov	b,r5
   0032 63 F0 80            414 	xrl	b,#0x80
   0035 95 F0               415 	subb	a,b
   0037 50 21               416 	jnc	00126$
                            417 ;	compare2.c:28: if( c == c2 )
   0039 EB                  418 	mov	a,r3
   003A B5 05 02            419 	cjne	a,ar5,00148$
   003D 80 1B               420 	sjmp	00126$
   003F                     421 00148$:
                            422 ;	compare2.c:30: if( c <  c2 )
   003F C3                  423 	clr	c
   0040 EB                  424 	mov	a,r3
   0041 64 80               425 	xrl	a,#0x80
   0043 8D F0               426 	mov	b,r5
   0045 63 F0 80            427 	xrl	b,#0x80
   0048 95 F0               428 	subb	a,b
                            429 ;	compare2.c:32: if( c <= c2 )
   004A 40 0E               430 	jc	00126$
   004C ED                  431 	mov	a,r5
   004D 64 80               432 	xrl	a,#0x80
   004F 8B F0               433 	mov	b,r3
   0051 63 F0 80            434 	xrl	b,#0x80
   0054 95 F0               435 	subb	a,b
   0056 50 02               436 	jnc	00126$
                            437 ;	compare2.c:36: while(1)
   0058                     438 00122$:
                            439 ;	compare2.c:40: while(2)
   0058 80 FE               440 	sjmp	00122$
   005A                     441 00126$:
   005A 80 FE               442 	sjmp	00126$

 

which is a start.

And you could easily modify the C-snippet to compare against a literal (or something within xdata/pdata/idata/code), or 16bit/32bit signed/unsigned integers or make the compiler use ljmp instead of sjmp.

List of 10 messages in thread
TopicAuthorDate
mathimatical question using 8052            01/01/70 00:00      
   CJNE?            01/01/70 00:00      
      problem in "" < "" and "" > ""            01/01/70 00:00      
         Reading is fundamental            01/01/70 00:00      
            *Careful* and *Thorough* reading is key            01/01/70 00:00      
      "bible" link(s)            01/01/70 00:00      
   Combine CJNE with JC/JNC instruction...            01/01/70 00:00      
      Thanks Kai the PDF was so helpfull            01/01/70 00:00      
         You can use..            01/01/70 00:00      
   maybe use a compiler            01/01/70 00:00      

Back to Subject List