flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > x51 Divide efficiency

Thread Post new topic Reply to topic

Joined: 15 Jan 2015
Posts: 674
l4m2 13 Sep 2017, 15:56
I found the keil x51 long/long code:
C:0x002A    75F008   MOV      B(0xF0),#0x08
C:0x002D    758200   MOV      DP0L(0x82),#0x00
C:0x0030    EF       MOV      A,R7
C:0x0031    2F       ADD      A,R7
C:0x0032    FF       MOV      R7,A
C:0x0033    EE       MOV      A,R6
C:0x0034    33       RLC      A
C:0x0035    FE       MOV      R6,A
C:0x0036    CD       XCH      A,R5
C:0x0037    33       RLC      A
C:0x0038    CD       XCH      A,R5
C:0x0039    CC       XCH      A,R4
C:0x003A    33       RLC      A
C:0x003B    CC       XCH      A,R4
C:0x003C    C582     XCH      A,DP0L(0x82)
C:0x003E    33       RLC      A
C:0x003F    C582     XCH      A,DP0L(0x82)
C:0x0041    9B       SUBB     A,R3
C:0x0042    ED       MOV      A,R5
C:0x0043    9A       SUBB     A,R2
C:0x0044    EC       MOV      A,R4
C:0x0045    99       SUBB     A,R1
C:0x0046    E582     MOV      A,DP0L(0x82)
C:0x0048    98       SUBB     A,R0
C:0x0049    400C     JC       C:0057
C:0x004B    F582     MOV      DP0L(0x82),A
C:0x004D    EE       MOV      A,R6
C:0x004E    9B       SUBB     A,R3
C:0x004F    FE       MOV      R6,A
C:0x0050    ED       MOV      A,R5
C:0x0051    9A       SUBB     A,R2
C:0x0052    FD       MOV      R5,A
C:0x0053    EC       MOV      A,R4
C:0x0054    99       SUBB     A,R1
C:0x0055    FC       MOV      R4,A
C:0x0056    0F       INC      R7
C:0x0057    D5F0D6   DJNZ     B(0xF0),C:0030
C:0x005A    E4       CLR      A
C:0x005B    CE       XCH      A,R6
C:0x005C    FB       MOV      R3,A
C:0x005D    E4       CLR      A
C:0x005E    CD       XCH      A,R5
C:0x005F    FA       MOV      R2,A
C:0x0060    E4       CLR      A
C:0x0061    CC       XCH      A,R4
C:0x0062    F9       MOV      R1,A
C:0x0063    A882     MOV      R0,DP0L(0x82)
C:0x0065    22       RET      
C:0x0066    B800C1   CJNE     R0,#0x00,C:002A
C:0x0069    B90059   CJNE     R1,#0x00,C:00C5
C:0x006C    BA002D   CJNE     R2,#0x00,C:009C
C:0x006F    EC       MOV      A,R4
C:0x0070    8BF0     MOV      B(0xF0),R3
C:0x0072    84       DIV      AB
C:0x0073    CF       XCH      A,R7
C:0x0074    CE       XCH      A,R6
C:0x0075    CD       XCH      A,R5
C:0x0076    FC       MOV      R4,A
C:0x0077    E5F0     MOV      A,B(0xF0)
C:0x0079    CB       XCH      A,R3
C:0x007A    F9       MOV      R1,A
C:0x007B    7818     MOV      R0,#0x18
C:0x007D    EF       MOV      A,R7
C:0x007E    2F       ADD      A,R7
C:0x007F    FF       MOV      R7,A
C:0x0080    EE       MOV      A,R6
C:0x0081    33       RLC      A
C:0x0082    FE       MOV      R6,A
C:0x0083    ED       MOV      A,R5
C:0x0084    33       RLC      A
C:0x0085    FD       MOV      R5,A
C:0x0086    EC       MOV      A,R4
C:0x0087    33       RLC      A
C:0x0088    FC       MOV      R4,A
C:0x0089    EB       MOV      A,R3
C:0x008A    33       RLC      A
C:0x008B    FB       MOV      R3,A
C:0x008C    10D703   JBC      CY(0xD0.7),C:0092
C:0x008F    99       SUBB     A,R1
C:0x0090    4004     JC       C:0096
C:0x0092    EB       MOV      A,R3
C:0x0093    99       SUBB     A,R1
C:0x0094    FB       MOV      R3,A
C:0x0095    0F       INC      R7
C:0x0096    D8E5     DJNZ     R0,C:007D
C:0x0098    E4       CLR      A
C:0x0099    F9       MOV      R1,A
C:0x009A    FA       MOV      R2,A
C:0x009B    22       RET      
C:0x009C    7818     MOV      R0,#0x18
C:0x009E    EF       MOV      A,R7
C:0x009F    2F       ADD      A,R7
C:0x00A0    FF       MOV      R7,A
C:0x00A1    EE       MOV      A,R6
C:0x00A2    33       RLC      A
C:0x00A3    FE       MOV      R6,A
C:0x00A4    ED       MOV      A,R5
C:0x00A5    33       RLC      A
C:0x00A6    FD       MOV      R5,A
C:0x00A7    EC       MOV      A,R4
C:0x00A8    33       RLC      A
C:0x00A9    FC       MOV      R4,A
C:0x00AA    C9       XCH      A,R1
C:0x00AB    33       RLC      A
C:0x00AC    C9       XCH      A,R1
C:0x00AD    10D705   JBC      CY(0xD0.7),C:00B5
C:0x00B0    9B       SUBB     A,R3
C:0x00B1    E9       MOV      A,R1
C:0x00B2    9A       SUBB     A,R2
C:0x00B3    4007     JC       C:00BC
C:0x00B5    EC       MOV      A,R4
C:0x00B6    9B       SUBB     A,R3
C:0x00B7    FC       MOV      R4,A
C:0x00B8    E9       MOV      A,R1
C:0x00B9    9A       SUBB     A,R2
C:0x00BA    F9       MOV      R1,A
C:0x00BB    0F       INC      R7
C:0x00BC    D8E0     DJNZ     R0,C:009E
C:0x00BE    E4       CLR      A
C:0x00BF    C9       XCH      A,R1
C:0x00C0    FA       MOV      R2,A
C:0x00C1    E4       CLR      A
C:0x00C2    CC       XCH      A,R4
C:0x00C3    FB       MOV      R3,A
C:0x00C4    22       RET      
C:0x00C5    75F010   MOV      B(0xF0),#0x10
C:0x00C8    EF       MOV      A,R7
C:0x00C9    2F       ADD      A,R7
C:0x00CA    FF       MOV      R7,A
C:0x00CB    EE       MOV      A,R6
C:0x00CC    33       RLC      A
C:0x00CD    FE       MOV      R6,A
C:0x00CE    ED       MOV      A,R5
C:0x00CF    33       RLC      A
C:0x00D0    FD       MOV      R5,A
C:0x00D1    CC       XCH      A,R4
C:0x00D2    33       RLC      A
C:0x00D3    CC       XCH      A,R4
C:0x00D4    C8       XCH      A,R0
C:0x00D5    33       RLC      A
C:0x00D6    C8       XCH      A,R0
C:0x00D7    10D707   JBC      CY(0xD0.7),C:00E1
C:0x00DA    9B       SUBB     A,R3
C:0x00DB    EC       MOV      A,R4
C:0x00DC    9A       SUBB     A,R2
C:0x00DD    E8       MOV      A,R0
C:0x00DE    99       SUBB     A,R1
C:0x00DF    400A     JC       C:00EB
C:0x00E1    ED       MOV      A,R5
C:0x00E2    9B       SUBB     A,R3
C:0x00E3    FD       MOV      R5,A
C:0x00E4    EC       MOV      A,R4
C:0x00E5    9A       SUBB     A,R2
C:0x00E6    FC       MOV      R4,A
C:0x00E7    E8       MOV      A,R0
C:0x00E8    99       SUBB     A,R1
C:0x00E9    F8       MOV      R0,A
C:0x00EA    0F       INC      R7
C:0x00EB    D5F0DA   DJNZ     B(0xF0),C:00C8
C:0x00EE    E4       CLR      A
C:0x00EF    CD       XCH      A,R5
C:0x00F0    FB       MOV      R3,A
C:0x00F1    E4       CLR      A
C:0x00F2    CC       XCH      A,R4
C:0x00F3    FA       MOV      R2,A
C:0x00F4    E4       CLR      A
C:0x00F5    C8       XCH      A,R0
C:0x00F6    F9       MOV      R1,A
C:0x00F7    22       RET          

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

if (b[3]) {
  L = 0
  for 8 {
    La *= 2
    if (La[3..1] >= b) {
      La[3..1] -= b
      a[0] ++
  b = La[3..1]
  a[3..1] = 0
if (b[2]) { // L:=b[3]
  for 16 {
    La *= 2
    if (La[3..2] >= b) {
      La[3..2] -= b
      a[0] ++
  b = La[3..2]
  La[3..2] = 0
  return 0;
if (b[1]) { // for_counter:=b[3], L:=b[2]
  for 24 {
    La *= 2
    if (La[3] >= b) {
      La[3] -= b
      a[0] ++
  b = La[3]
  La[3] = 0
  return 0;
(A,B) = a[3]/b
a = a[2..0]A
... (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
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19871
Location: In your JS exploiting you and your system
revolution 13 Sep 2017, 15:59
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

Joined: 15 Jan 2015
Posts: 674
l4m2 13 Sep 2017, 16:04
Another prob: SHL
C:0x0017    E8       MOV      A,R0
C:0x0018    600F     JZ       C:0029
C:0x001A    EF       MOV      A,R7
C:0x001B    C3       CLR      C
C:0x001C    33       RLC      A
C:0x001D    FF       MOV      R7,A
C:0x001E    EE       MOV      A,R6
C:0x001F    33       RLC      A
C:0x0020    FE       MOV      R6,A
C:0x0021    ED       MOV      A,R5
C:0x0022    33       RLC      A
C:0x0023    FD       MOV      R5,A
C:0x0024    EC       MOV      A,R4
C:0x0025    33       RLC      A
C:0x0026    FC       MOV      R4,A
C:0x0027    D8F1     DJNZ     R0,C:001A
C:0x0029    22       RET          

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

Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 25 Sep 2017, 07:16
the only optimisation in shl which I see is to replace
clr c
rlc a    

add a,acc    
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.