+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Newbie level 4
    Points: 57, Level: 1

    Join Date
    Mar 2016
    Posts
    5
    Helped
    0 / 0
    Points
    57
    Level
    1

    help with numbers to letters conversion in assembly 8051

    hi,
    I'm trying to complete my project in assembly 8051 , and thanks to all of you I completed the 1st phase
    now I'm stuck in the 2nd phase

    I should convert a number to its letters --->> for example if I put R3 = #31 it should print thirty one

    I know I had to make an arrays:
    1. single digit (one to nine)
    2. double digit (eleven to nineteen)
    3. tens digit (ten , twenty, thirty, ..........., ninety)

    since the range from 1 - 99

    and I know this function involve with division , but I don't know how to begin with it and check for each state

    I need an explanation for the procedures

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 52,890, Level: 56

    Join Date
    Apr 2011
    Location
    Minneapolis, Minnesota, USA
    Posts
    12,941
    Helped
    2578 / 2578
    Points
    52,890
    Level
    56

    Re: help with numbers to letters conversion in assembly 8051

    Many languages have a routine which converts a numeric value to a string. Example, A$ = STR$ ( X )

    Thus if X=31, then A$= "31" or " 31".



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 4
    Points: 2,136, Level: 10
    xenos's Avatar
    Join Date
    May 2015
    Location
    127.0.0.1
    Posts
    212
    Helped
    82 / 82
    Points
    2,136
    Level
    10

    Re: help with numbers to letters conversion in assembly 8051

    use your stack in stead of array

    the pseudo code bellow will print nothing if n is equal to 0
    Code:
    int digits = 0
    while(n<>0){
       push (n div 10)
       n = n / 10
       digits=digits+1
    }
    while(digits>0){
          print (pop + '0')
          digit--
    }
    the pseudo code bellow will print '0' if n is equal to 0
    Code:
    int digits = 0
    do{
       push (n div 10)
       n = n / 10
       digits=digits+1
    }while(n<>0)
    while(digits>0){
          print (pop + '0')
          digit--
    }


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 2
    Points: 6,866, Level: 19
    ctownsend's Avatar
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    574
    Helped
    94 / 94
    Points
    6,866
    Level
    19

    Re: help with numbers to letters conversion in assembly 8051

    Code:
    ;***********************************
    ;convert data in acc to ascii and print to screen
    HOUT:
          PUSH    ACC
          SWAP    A
          call   PHEX1
          POP     ACC
          call   PHEX1
          RET
    ;***********************************
    ;hex2ascii routine
    PHEX1:
          ANL     A,#0FH
          ADD     A,#4
          MOVC    A,@A+PC
          call   outchar
          RET
          DB     '0123456789ABCDEF'
    ;***********************************


    1 members found this post helpful.

--[[ ]]--