Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Is this cose right please (http://www.go4expert.com/forums/cose-t2450/)

omaransi 6Jan2007 00:52

Is this cose right please
Hi, everyone
I have some problems with 8085 assembly in this code
That is ,I need the user to write MOV then enters the Rs,and Rd and copies the contents of rs to rd and then display it please any one can help me
and how I can write a line ofcode that allows the user to write e.g MOV A,B at once



 Void error();
  Char opcode;
Char rs;
Char rd;
Char vrs;
Void error()
{ cout<<"Incorrect Reg.name,try again "<<endl;  }
Xxx: cout<<"\n Enter the Opcode "<<endl;

 Cerr<<"\t Incorrect opcode,try again"<<endl;
Goto xxx;
Error(); goto xxx;
Cout<<"\n Enter its value in Hexadecimal "<<endl;
Yyy :Cout<<"Enter the Destination Reg.Name "<<endl;
Cout<<" "<<endl;

{Error(); goto yyy; }

        MVI  rd,0; Clear the det.reg.
        MVI  rs,vrs;  load the value to source reg
        Mov  rd,rs;
        MOV  ? ,[rd];  save for output later
    }  ; what I will use for ? to transfer the contents to Rd

Cout<<"("<<rs<<")=" <<vrs<<endl; // show (Rs) contents
Cout<<"("<<rd<<")="<< ?<<endl;  //show (rd) contents

Return 0; }

DaWei 7Jan2007 02:25

Re: Is this cose right please
Do you want to use C or C++? I'm preparing an example, but I won't mix my code, such as you have done.

The use of "goto", while not evil, is indicative of a poorly thought out design. The use of "gets" is an invitation to having your program entirely clobbered by the inattentive or malicious user.

You also need to understand that case counts in C/C++. Obviously, if you've made an attempt to compile that, you have 2 tons of errors.

Move beyond laziness. Indulge in design and thought. If you can't expend that energy, I won't expend mine for you. Learn to format your code, put it in code tags, and clean unnecessary syntax errors such as the case issue. In other words, compile it and clean up all the errors you understand. After you clean up your code, repost it. Then I can perhaps presume you're serious about getting help.

omaransi 7Jan2007 22:17

Re: Is this cose right please
Ok thanks
I am using c++ and i will try to compile it and clean up the errors and repost it

much thanks

DaWei 8Jan2007 22:03

Re: Is this cose right please
Here's the deal about doing this. You want to emulate the registers in a uP. To do this, you need to tie the register identification to a variable that represents the register contents. You also need to tie an instruction mnemonic to a function that performs the instruction.

Since register mnemonics vary from chip to chip, the best way is to define a list of register names in such a way that finding the name in the list returns an index into a set of register variables (or possibly a pointer).

Similarly, with the opcode mnemonics. Consider a simple implementation. Operations (opcodes) may have zero, one, or two operands. Operands may be register IDs, immediate values, direct memory addresses (other variable names), or indirect memory addresses (pointers to other variable names).

Finding a mnemonic in a list would return (or imply) information regarding the number of operands, and how to use them. One then simply calls the appropriate function, much as one would do in a calculator implementation. Determining the appropriate function could be done in a number of ways. A switch or if construct related to the index of the mnemonic could be used, or the mnemonic-search could return a function pointer.

These operations could be performed using an array or a vector or a map. The information contained could be as simple as an index value, or as complex as a class or struct which contains all the information necessary for a particular mnemonic instruction. The class or struct could even possess information that would specify the machine code to be emitted.

The purpose of this post is to encourage you to thoroughly think about and design your application. When that is firmly fixed, in your mind and on paper, then you can sit down and translate it into the kind of code you feel is most appropriate.

All times are GMT +5.5. The time now is 05:58.