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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/20/08 19:20
Read: times


 
#149778 - try this
Responding to: ???'s previous message
"And my main question was is this asm is legal ?"

Yes.


You might want to try one of these:

----8<----------------------------------------
#include <compiler.h>

SFR16(TMR2, 0xCC);

unsigned int mainoff = 5000;

void main ()
{
    TMR2 = ~(mainoff - 1);
}

void foo()
{
    __asm
        mov     a,_mainoff
        add     a,#0xff
        cpl     a
        mov     _TMR2,a
        mov     a,(_mainoff + 1)
        addc    a,#0xff
        cpl     a
        mov     (_TMR2 >> 8),a
   __endasm;
}
---->8----------------------------------------


Which results in:

   0022                     127 _main:
                            136 ;       mainoff.c:9: TMR2 = ~(mainoff - 1);
   0022 E5 08               137         mov     a,_mainoff
   0024 24 FF               138         add     a,#0xff
   0026 FA                  139         mov     r2,a
   0027 E5 09               140         mov     a,(_mainoff + 1)
   0029 34 FF               141         addc    a,#0xff
   002B FB                  142         mov     r3,a
   002C EA                  143         mov     a,r2
   002D F4                  144         cpl     a
   002E F5 CC               145         mov     _TMR2,a
   0030 EB                  146         mov     a,r3
   0031 F4                  147         cpl     a
   0032 F5 CD               148         mov     (_TMR2 >> 8),a
   0034 22                  149         ret
                            150 ;------------------------------------------------------------
                            151 ;Allocation info for local variables in function 'foo'
                            152 ;------------------------------------------------------------
                            153 ;------------------------------------------------------------
                            154 ;       mainoff.c:12: void foo()
                            155 ;       -----------------------------------------
                            156 ;        function foo
                            157 ;       -----------------------------------------
   0035                     158 _foo:
                            159 ;       mainoff.c:23: __endasm;
                            160
   0035 E5 08               161                 mov a,_mainoff
   0037 24 FF               162                 add a,#0xff
   0039 F4                  163                 cpl a
   003A F5 CC               164                 mov _TMR2,a
   003C E5 09               165                 mov a,(_mainoff + 1)
   003E 34 FF               166                 addc a,#0xff
   0040 F4                  167                 cpl a
   0041 F5 CD               168                 mov (_TMR2 >> 8),a
                            169
   0043 22                  170         ret



List of 19 messages in thread
TopicAuthorDate
SDCC, copying integer in ASM            01/01/70 00:00      
   Shift-and-mask, or union            01/01/70 00:00      
      I used asm tag and the rr command but....            01/01/70 00:00      
         Your question            01/01/70 00:00      
            Portable unions            01/01/70 00:00      
               Less non-portable?            01/01/70 00:00      
                  Less non-portable            01/01/70 00:00      
                     portable, schmortable            01/01/70 00:00      
                        Disagree!            01/01/70 00:00      
                           how portable?            01/01/70 00:00      
                              emphasis            01/01/70 00:00      
                        Real world portable            01/01/70 00:00      
      using - does not give the same result            01/01/70 00:00      
         try this            01/01/70 00:00      
         You are exceeeding 2 byte signed integer limits            01/01/70 00:00      
            Fighting the tools            01/01/70 00:00      
   Thanks all.            01/01/70 00:00      
      Dangerous            01/01/70 00:00      
         Very important warning!            01/01/70 00:00      

Back to Subject List