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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/17/08 08:37
Read: times


 
#157527 - Assembly to C and then back again
Responding to: ???'s previous message
Hi Cuong, hi Jan,

taking Jan's code I did some modifications so the
generated assembly looks even more close to that
you started with.

--------8<----------------------------------
#pragma callee_saves DspSelect      /* be careful with this pragma */

extern void DspSelect();

xdata unsigned char at 0x5000 ADspTab ;
#define EndDspTab 16

void foo() {
  unsigned char DspTabCount = 0;
  unsigned char xdata * DspTabPoint;

  DspTabPoint = &ADspTab;
  do {
    if (*DspTabPoint == 0)
      break;
    DspTabPoint++;
    DspSelect();
  } while ( ++DspTabCount != EndDspTab);
  // return DspTabCount;
}
-------->8----------------------------------

(converted for loop to while loop,
added a dangerous pragma,
changed * xdata to xdata *,
packed into a function)

using SDCC (sorry not Keil) this compiles to:
--------8<----------------------------------
   0000                     101 _foo:
   0000 7A 00               112         mov     r2,#_ADspTab
   0002 7B 50               113         mov     r3,#(_ADspTab >> 8)
   0004 7C 00               114         mov     r4,#0x00
   0006                     115 00103$:
   0006 8A 82               117         mov     dpl,r2
   0008 8B 83               118         mov     dph,r3
   000A E0                  119         movx    a,@dptr
   000B 60 0C               120         jz      00106$
   000D 0A                  122         inc     r2
   000E BA 00 01            123         cjne    r2,#0x00,00112$
   0011 0B                  124         inc     r3
   0012                     125 00112$:
   0012 12s00r00            127         lcall   _DspSelect
   0015 0C                  129         inc     r4
   0016 BC 10 ED            130         cjne    r4,#0x10,00103$
   0019                     131 00106$:
   0019 22                  132         ret
-------->8----------------------------------

and just for reference, this is the code you started with:

--------8<----------------------------------

   ADspTab     Equ    05000h
   EndDspTab   Equ    16

   DspTabPointH       Data     12h
   DspTabPointL       Data     11h
   DspTabCount        Data     10h

LoopMain:

         Mov     DspTabPointH,#High(ADspTab)
         Mov     DspTabPointL,#Low(ADspTab)
         Mov     DspTabCount,#0
LoopDspTab:
         Mov     Dph,DspTabPointH
         Mov     DpL,DspTabPointL
         Movx    A,@Dptr
         Jz      LoopMain
         Inc     Dptr
         Mov     DspTabPointH,Dph
         Mov     DspTabPointL,Dpl
         Lcall   DspSelect
         Inc     DspTabCount
         Mov     A,DspTabCount
         Cjne    A,#EndDspTab,LoopDspTab
         Ajmp    LoopMain

-------->8----------------------------------

Greetings,
Frieder

List of 10 messages in thread
TopicAuthorDate
Convert Assembly routine to C using Keil.            01/01/70 00:00      
   no guarantee this will fit your purpose...            01/01/70 00:00      
      Assembly to C and then back again            01/01/70 00:00      
      Double loop            01/01/70 00:00      
         yes, you are right            01/01/70 00:00      
      Target processor name.            01/01/70 00:00      
         Microprocessor name.            01/01/70 00:00      
            initializing global variable to zero            01/01/70 00:00      
               Are you sure you want it outside of the loop?            01/01/70 00:00      
   What is the target processor name.??            01/01/70 00:00      

Back to Subject List