Displaying a character's ascii in assembly? (pep8)

Discussion in 'Assembly Language Programming (ALP) Forum' started by Slipperz, Aug 29, 2012.

  1. Slipperz

    Slipperz New Member

    Joined:
    Aug 29, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hai,

    I'm using Pep8 which is a simulator for my assembly class. For the 1st step of the project I need to find a way to display a character's ascii number.
    'h' is 104
    so
    deco 'h',i (decimal output 'h' immediately) will output 104.. but note that I need to manually enter 'h'.. How to I input it through like chari or on the console... if you see what i mean ...help

    When I enter:
    chari ascii,d ; Character input and store it in the "variable" ascii
    deco ascii,d ; Decimal output of the "variable" ascii
    stop
    ascii : .block 2 ;
    .end

    I get 26624 instead of 104!! My teacher said it's 104 times 256 = 26624.. but why times 256.. I need to do something but I don't know what!!

    HELP!
     
  2. sgermain

    sgermain New Member

    Joined:
    Mar 14, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The problem is that you're trying to output the decimal value of a byte. CHARI stores a byte value, not a decimal value. You'll have to transition it over to a decimal value by loading a byte value from memory into the accumulator and then store that decimal value back into your variable.

    Here's how you do that:

    CHARI ascii, d
    LDBYTEA ascii, d
    STA ascii, d
    DECO ascii, d
    STOP
    ascii: .BLOCK 2
    .END

    That should return 104 when you enter 'h'.
     
  3. uchiwa

    uchiwa New Member

    Joined:
    Dec 1, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi,

    I'm using Pep8 which is a simulator for my assembly class.

    and i wana convert this java code to assembly

    HELP!
    Code:
    
    /**
     * Write a description of class Calc here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Calc {   
        static int valeurX = 0;
        
        
        
        public static Noeud conArbre() {
            Noeud newNoeud = new Noeud();
            
            while (newNoeud.operande == 0) {
                newNoeud.operande = Pep8.chari();
                
                if (newNoeud.operande == '*' || newNoeud.operande == '+' ||
                        newNoeud.operande == '-' || newNoeud.operande == '/'){
                    newNoeud.noeudG = conArbre();
                    newNoeud.noeudD = conArbre();                    
                } else if (newNoeud.operande >= '0' && newNoeud.operande <= '9') {
                    newNoeud.valeurN = conNb(newNoeud.operande);
                    newNoeud.operande = 'n';           
                } else if (newNoeud.operande == 'x') {
                    
                } else if (newNoeud.operande == '.') {
                    Pep8.charo('.');
                    Pep8.charo('\n');
                    Pep8.stop();            
                } else { 
                    newNoeud.operande = 0;                            
                }           
            }
            
            return newNoeud;
        
        }
        
        public static int conNb(char chiffre){
            int nombre = chiffre - 48;
            
            chiffre = Pep8.chari();
            
            while (chiffre >= '0' && chiffre <= '9'){
                nombre = ((nombre * 10) + (chiffre - 48));
                chiffre = Pep8.chari();                    
            }
            
            return nombre;
            
        }
        
        public static int calcul(Noeud noeud){
            int calculRep = 0;
            
            if (noeud.operande == '+'){
                calculRep = calcul(noeud.noeudG) + calcul(noeud.noeudD);        
            } else if (noeud.operande == '-'){
                calculRep = calcul(noeud.noeudG) - calcul(noeud.noeudD);         
            } else if (noeud.operande == '/'){
                calculRep = calcul(noeud.noeudG) / calcul(noeud.noeudD);         
            } else if (noeud.operande == '*'){
                calculRep = calcul(noeud.noeudG) * calcul(noeud.noeudD);         
            } else if (noeud.operande == 'n'){
                calculRep = noeud.valeurN;         
            } else if (noeud.operande == 'x'){
                calculRep = valeurX;        
            }
            
            return calculRep;    
        
        }
        
        public static void affForm(Noeud formule){
            if (formule.operande == 'n'){
                Pep8.deco(formule.valeurN);        
            } else if (formule.operande == 'x'){
                Pep8.charo('x');        
            } else {
                Pep8.charo('(');
                affForm(formule.noeudG);
                Pep8.charo(formule.operande);
                affForm(formule.noeudD);
                Pep8.charo(')');
            }   
        }
        
        public static void main(String[] params){
            char mChoix = 0;
            Noeud arbre = conArbre();
            
            
            while (mChoix != '.'){
                if (mChoix == '='){
                    Pep8.deco(calcul(arbre));
                    Pep8.charo('\n');            
                } else if (mChoix == '>') {
                    affForm(arbre);
                    Pep8.charo('\n');            
                } else if (mChoix == 'x'){
                    valeurX = Pep8.deci();            
                }
                
                mChoix = Pep8.chari();
                
            }
            
            Pep8.charo('.');
            Pep8.charo('\n');
            Pep8.stop();
        
        }
        
        
    }
    
    class Noeud {
            public char operande = 0;
            
            public int valeurN = 0;
            public Noeud noeudG = null;
            public Noeud noeudD = null;
        
        }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice