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

Slipperz's Avatar
Newbie Member
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!
0
sgermain's Avatar, Join Date: Mar 2014
Newbie Member
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'.
0
uchiwa's Avatar, Join Date: Dec 2014
Newbie Member
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;
    
    }