This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

5 Byte number to be converted into decimal string

Hallo

it would be fine if somebody could help me on the following problem: I have to send the decimal digits of a 5 Byte Hex value, that is currently stored in an array, via the serial interface. It is no problem to get the digits of a 4 Byte number but Keil or the controller do not allow double integer!

any solution????

Parents
  • Minor update:

    #pragma ASM
    
        $REGUSE _fast_40_bit_divide( A, B, PSW, R0, R3, R4, R5, R6, R7 )
    
        PUBLIC fast_40_bit_divide
    
    #pragma ENDASM
    
    unsigned char fast_40_bit_divide( unsigned char data * dividend, unsigned char divisor ) small
    {
        dividend = dividend;                  // Suppress unused variable warning.
        divisor = divisor;                  // Suppress unused variable warning.
    
        #pragma ASM
    
        // pointer to dividend:   R7
        // divisor in:            R5
        // uses:                  R3, R4, R6
        // quotient returned in:  data memory
        // remainder returned in: R7
    
    pointer         SET     R0              ;
    remainder       SET     R3              ;
    partial         SET     R4              ;
    divisor         SET     R5              ;
    loop            SET     R6              ;
                                            ;
            MOV     A,R7                    ;
            MOV     pointer,A               ;
                                            ;
    fast_40_bit_divide:                     ;
                                            ;
            MOV     A,@R0                   ;Get the MS byte of dividend and divide
            MOV     B,divisor               ; it by the divisor.
            DIV     AB                      ;
                                            ;
            MOV     @R0,A                   ;Store result of division as quotient.
                                            ;
            MOV     A,B                     ;Save the remainder (which must be in
            SWAP    A                       ; the range 0...15) shifted four bits
            MOV     B,A                     ; to the left.
                                            ;
            INC     R0                      ;
                                            ;
            MOV     loop,#04                ;load loop counter.
                                            ;
    ?fast_40_bit_divide_loop:               ;
                                            ;
            MOV     A,@pointer              ;Get the MS nibble of the
            SWAP    A                       ; dividend into the accumulator.
            ANL     A,#0x0F                 ;
            ORL     A,B                     ; Or in remainder from last iteration.
                                            ;
            MOV     B,divisor               ;Divide MS nibble by the divisor.
            DIV     AB                      ;
                                            ;
            SWAP    A                       ;Save partial result (which must be
            MOV     partial,A               ; in the range 0...15) shifted 4 bits.
                                            ;
            MOV     A,B                     ;Read remainder (which must be in
            SWAP    A                       ; the range 0...15) and shift 4 bits left.
                                            ;
            XCHD    A,@pointer              ;Get next nibble of the dividend into
                                            ; the accumulator.
            MOV     B,divisor               ;Divide by the divisor.
            DIV     AB                      ;
                                            ;
            ORL     A,partial               ;Or in the previously saved partial result.
            MOV     @pointer,A              ;Save the MSB of the quotient ready
                                            ; to be returned.
                                            ;
            MOV     A,B                     ;Save remainder
            SWAP    A                       ; shifted 4 bits left
            MOV     B,A                     ; in B.
                                            ;
            INC     pointer                 ;
    
            DJNZ    loop,?fast_40_bit_divide_loop
    
            SWAP    A                       ;The final remainder is in upper nibble
            MOV     R7,A                    ; of accumulator.
                                            ;
            RET                             ;
    
        #pragma ENDASM
    
        return( dividend );
    
    }
    

Reply
  • Minor update:

    #pragma ASM
    
        $REGUSE _fast_40_bit_divide( A, B, PSW, R0, R3, R4, R5, R6, R7 )
    
        PUBLIC fast_40_bit_divide
    
    #pragma ENDASM
    
    unsigned char fast_40_bit_divide( unsigned char data * dividend, unsigned char divisor ) small
    {
        dividend = dividend;                  // Suppress unused variable warning.
        divisor = divisor;                  // Suppress unused variable warning.
    
        #pragma ASM
    
        // pointer to dividend:   R7
        // divisor in:            R5
        // uses:                  R3, R4, R6
        // quotient returned in:  data memory
        // remainder returned in: R7
    
    pointer         SET     R0              ;
    remainder       SET     R3              ;
    partial         SET     R4              ;
    divisor         SET     R5              ;
    loop            SET     R6              ;
                                            ;
            MOV     A,R7                    ;
            MOV     pointer,A               ;
                                            ;
    fast_40_bit_divide:                     ;
                                            ;
            MOV     A,@R0                   ;Get the MS byte of dividend and divide
            MOV     B,divisor               ; it by the divisor.
            DIV     AB                      ;
                                            ;
            MOV     @R0,A                   ;Store result of division as quotient.
                                            ;
            MOV     A,B                     ;Save the remainder (which must be in
            SWAP    A                       ; the range 0...15) shifted four bits
            MOV     B,A                     ; to the left.
                                            ;
            INC     R0                      ;
                                            ;
            MOV     loop,#04                ;load loop counter.
                                            ;
    ?fast_40_bit_divide_loop:               ;
                                            ;
            MOV     A,@pointer              ;Get the MS nibble of the
            SWAP    A                       ; dividend into the accumulator.
            ANL     A,#0x0F                 ;
            ORL     A,B                     ; Or in remainder from last iteration.
                                            ;
            MOV     B,divisor               ;Divide MS nibble by the divisor.
            DIV     AB                      ;
                                            ;
            SWAP    A                       ;Save partial result (which must be
            MOV     partial,A               ; in the range 0...15) shifted 4 bits.
                                            ;
            MOV     A,B                     ;Read remainder (which must be in
            SWAP    A                       ; the range 0...15) and shift 4 bits left.
                                            ;
            XCHD    A,@pointer              ;Get next nibble of the dividend into
                                            ; the accumulator.
            MOV     B,divisor               ;Divide by the divisor.
            DIV     AB                      ;
                                            ;
            ORL     A,partial               ;Or in the previously saved partial result.
            MOV     @pointer,A              ;Save the MSB of the quotient ready
                                            ; to be returned.
                                            ;
            MOV     A,B                     ;Save remainder
            SWAP    A                       ; shifted 4 bits left
            MOV     B,A                     ; in B.
                                            ;
            INC     pointer                 ;
    
            DJNZ    loop,?fast_40_bit_divide_loop
    
            SWAP    A                       ;The final remainder is in upper nibble
            MOV     R7,A                    ; of accumulator.
                                            ;
            RET                             ;
    
        #pragma ENDASM
    
        return( dividend );
    
    }
    

Children