flat assembler
Message board for the users of flat assembler.

flat assembler > Non-x86 architectures > x51 Divide efficiency

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 648
I found the keil x51 long/long code:
Code:
C0x002A    75F008   MOV      B0xF0,#0x08
C0x002D    758200   MOV      DP0L0x82,#0x00
C0x0030    EF       MOV      A,R7
C0x0031    2F       ADD      A,R7
C0x0032    FF       MOV      R7,A
C0x0033    EE       MOV      A,R6
C0x0034    33       RLC      A
C0x0035    FE       MOV      R6,A
C0x0036    CD       XCH      A,R5
C0x0037    33       RLC      A
C0x0038    CD       XCH      A,R5
C0x0039    CC       XCH      A,R4
C0x003A    33       RLC      A
C0x003B    CC       XCH      A,R4
C0x003C    C582     XCH      A,DP0L0x82
C0x003E    33       RLC      A
C0x003F    C582     XCH      A,DP0L0x82
C0x0041    9B       SUBB     A,R3
C0x0042    ED       MOV      A,R5
C0x0043    9A       SUBB     A,R2
C0x0044    EC       MOV      A,R4
C0x0045    99       SUBB     A,R1
C0x0046    E582     MOV      A,DP0L0x82
C0x0048    98       SUBB     A,R0
C0x0049    400C     JC       C0057
C0x004B    F582     MOV      DP0L0x82,A
C0x004D    EE       MOV      A,R6
C0x004E    9B       SUBB     A,R3
C0x004F    FE       MOV      R6,A
C0x0050    ED       MOV      A,R5
C0x0051    9A       SUBB     A,R2
C0x0052    FD       MOV      R5,A
C0x0053    EC       MOV      A,R4
C0x0054    99       SUBB     A,R1
C0x0055    FC       MOV      R4,A
C0x0056    0F       INC      R7
C0x0057    D5F0D6   DJNZ     B0xF0,C0030
C0x005A    E4       CLR      A
C0x005B    CE       XCH      A,R6
C0x005C    FB       MOV      R3,A
C0x005D    E4       CLR      A
C0x005E    CD       XCH      A,R5
C0x005F    FA       MOV      R2,A
C0x0060    E4       CLR      A
C0x0061    CC       XCH      A,R4
C0x0062    F9       MOV      R1,A
C0x0063    A882     MOV      R0,DP0L0x82
C0x0065    22       RET      
                 C?ULDIV
C0x0066    B800C1   CJNE     R0,#0x00,C002A
C0x0069    B90059   CJNE     R1,#0x00,C00C5
C0x006C    BA002D   CJNE     R2,#0x00,C009C
C0x006F    EC       MOV      A,R4
C0x0070    8BF0     MOV      B0xF0,R3
C0x0072    84       DIV      AB
C0x0073    CF       XCH      A,R7
C0x0074    CE       XCH      A,R6
C0x0075    CD       XCH      A,R5
C0x0076    FC       MOV      R4,A
C0x0077    E5F0     MOV      A,B0xF0
C0x0079    CB       XCH      A,R3
C0x007A    F9       MOV      R1,A
C0x007B    7818     MOV      R0,#0x18
C0x007D    EF       MOV      A,R7
C0x007E    2F       ADD      A,R7
C0x007F    FF       MOV      R7,A
C0x0080    EE       MOV      A,R6
C0x0081    33       RLC      A
C0x0082    FE       MOV      R6,A
C0x0083    ED       MOV      A,R5
C0x0084    33       RLC      A
C0x0085    FD       MOV      R5,A
C0x0086    EC       MOV      A,R4
C0x0087    33       RLC      A
C0x0088    FC       MOV      R4,A
C0x0089    EB       MOV      A,R3
C0x008A    33       RLC      A
C0x008B    FB       MOV      R3,A
C0x008C    10D703   JBC      CY0xD0.7,C0092
C0x008F    99       SUBB     A,R1
C0x0090    4004     JC       C0096
C0x0092    EB       MOV      A,R3
C0x0093    99       SUBB     A,R1
C0x0094    FB       MOV      R3,A
C0x0095    0F       INC      R7
C0x0096    D8E5     DJNZ     R0,C007D
C0x0098    E4       CLR      A
C0x0099    F9       MOV      R1,A
C0x009A    FA       MOV      R2,A
C0x009B    22       RET      
C0x009C    7818     MOV      R0,#0x18
C0x009E    EF       MOV      A,R7
C0x009F    2F       ADD      A,R7
C0x00A0    FF       MOV      R7,A
C0x00A1    EE       MOV      A,R6
C0x00A2    33       RLC      A
C0x00A3    FE       MOV      R6,A
C0x00A4    ED       MOV      A,R5
C0x00A5    33       RLC      A
C0x00A6    FD       MOV      R5,A
C0x00A7    EC       MOV      A,R4
C0x00A8    33       RLC      A
C0x00A9    FC       MOV      R4,A
C0x00AA    C9       XCH      A,R1
C0x00AB    33       RLC      A
C0x00AC    C9       XCH      A,R1
C0x00AD    10D705   JBC      CY0xD0.7,C00B5
C0x00B0    9B       SUBB     A,R3
C0x00B1    E9       MOV      A,R1
C0x00B2    9A       SUBB     A,R2
C0x00B3    4007     JC       C00BC
C0x00B5    EC       MOV      A,R4
C0x00B6    9B       SUBB     A,R3
C0x00B7    FC       MOV      R4,A
C0x00B8    E9       MOV      A,R1
C0x00B9    9A       SUBB     A,R2
C0x00BA    F9       MOV      R1,A
C0x00BB    0F       INC      R7
C0x00BC    D8E0     DJNZ     R0,C009E
C0x00BE    E4       CLR      A
C0x00BF    C9       XCH      A,R1
C0x00C0    FA       MOV      R2,A
C0x00C1    E4       CLR      A
C0x00C2    CC       XCH      A,R4
C0x00C3    FB       MOV      R3,A
C0x00C4    22       RET      
C0x00C5    75F010   MOV      B0xF0,#0x10
C0x00C8    EF       MOV      A,R7
C0x00C9    2F       ADD      A,R7
C0x00CA    FF       MOV      R7,A
C0x00CB    EE       MOV      A,R6
C0x00CC    33       RLC      A
C0x00CD    FE       MOV      R6,A
C0x00CE    ED       MOV      A,R5
C0x00CF    33       RLC      A
C0x00D0    FD       MOV      R5,A
C0x00D1    CC       XCH      A,R4
C0x00D2    33       RLC      A
C0x00D3    CC       XCH      A,R4
C0x00D4    C8       XCH      A,R0
C0x00D5    33       RLC      A
C0x00D6    C8       XCH      A,R0
C0x00D7    10D707   JBC      CY0xD0.7,C00E1
C0x00DA    9B       SUBB     A,R3
C0x00DB    EC       MOV      A,R4
C0x00DC    9A       SUBB     A,R2
C0x00DD    E8       MOV      A,R0
C0x00DE    99       SUBB     A,R1
C0x00DF    400A     JC       C00EB
C0x00E1    ED       MOV      A,R5
C0x00E2    9B       SUBB     A,R3
C0x00E3    FD       MOV      R5,A
C0x00E4    EC       MOV      A,R4
C0x00E5    9A       SUBB     A,R2
C0x00E6    FC       MOV      R4,A
C0x00E7    E8       MOV      A,R0
C0x00E8    99       SUBB     A,R1
C0x00E9    F8       MOV      R0,A
C0x00EA    0F       INC      R7
C0x00EB    D5F0DA   DJNZ     B0xF0,C00C8
C0x00EE    E4       CLR      A
C0x00EF    CD       XCH      A,R5
C0x00F0    FB       MOV      R3,A
C0x00F1    E4       CLR      A
C0x00F2    CC       XCH      A,R4
C0x00F3    FA       MOV      R2,A
C0x00F4    E4       CLR      A
C0x00F5    C8       XCH      A,R0
C0x00F6    F9       MOV      R1,A
C0x00F7    22       RET          

or in psuedo code:
Code:
// a/b R4~R7 / R0~R3

if b3 
  L = 0
  for 8 
    La *= 2
    if La3..1 >= b 
      La3..1 -= b
      a0 ++
    
  
  b = La3..1
  a3..1 = 0
  return

if b2  // L=b3
  for 16 
    La *= 2
    if La3..2 >= b 
      La3..2 -= b
      a0 ++
    
  
  b = La3..2
  La3..2 = 0
  return 0;

if b1  // for_counter=b3, L=b2
  for 24 
    La *= 2
    if La3 >= b 
      La3 -= b
      a0 ++
    
  
  b = La3
  La3 = 0
  return 0;

A,B = a3/b
a = a2..0A
... also 24 times for each bit    

Wht not a faster way? Because there is not, or it cost more memory, or anything?
Post 13 Sep 2017, 15:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
Moved to Non-x86 architectures
Post 13 Sep 2017, 15:59
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
Another prob: SHL
Code:
                 C?LSHL
C0x0017    E8       MOV      A,R0
C0x0018    600F     JZ       C0029
C0x001A    EF       MOV      A,R7
C0x001B    C3       CLR      C
C0x001C    33       RLC      A
C0x001D    FF       MOV      R7,A
C0x001E    EE       MOV      A,R6
C0x001F    33       RLC      A
C0x0020    FE       MOV      R6,A
C0x0021    ED       MOV      A,R5
C0x0022    33       RLC      A
C0x0023    FD       MOV      R5,A
C0x0024    EC       MOV      A,R4
C0x0025    33       RLC      A
C0x0026    FC       MOV      R4,A
C0x0027    D8F1     DJNZ     R0,C001A
C0x0029    22       RET          

Should be possible to optimize
Post 13 Sep 2017, 16:04
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
the only optimisation in shl which I see is to replace
Code:
clr c
rlc a    

to
Code:
add a,acc    
Wink
Post 25 Sep 2017, 07:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.