| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Assembly Questions and Answers for Assembly here! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
given the following instruction set,
A number of instructions are defined below: Opcode = Symbolic Representation = Meaning 000 = LM A = Load AC from Memory Location A 001 = SM A = Store AC to Memory Location A 010 = SAC I = Set AC to an immediate number I 011= BEZ I = If the Content of AC is Equal to Zero, Skip I instructions 100 = J I = Unconditionally jump through I Instructions 101 = AM A = Add to AC from Memory Location A I need to change this to convert C code into assembly code but I am unsure of how to add to this instruction set to handle array indexing, if possible, can anyone give me an idea of how to specify the index as a variable so that I would have access to the arrays? Thanks. Below is an example of what I mean: Code:
C program:
int A=0;
for(int i=0;i!=10;i++)
A=A+i;
converts into this assembly program with the given instruction set:
SAC 0
SM 0 #M[0]=0,A=0
SM 1 #M[1]=0, i=0
SAC 1
SM 2 #M[2]=1
SAC -10
SM 3 #M[3]= -10
LM 1 #AC=i
AM 3 #AC=AC-10, i=i-10
BEZ 7 #if(AC==0) exit
LM 1 # AC=i
AM 0 # AC=AC+M[1], AC=i+A
SM 0 #M[0]=AC
LM 1 #AC=i
AM 2 #AC=AC+1
SM 1 # i=AC
J -9
Exit
I need to convert:
int B[10];
B[0]=0;
B[1]=1;
Do{
if(B[i]= = 0) B[i]=B[i+1]+3;
else B[i]= -B[i];
i=i++;
}while(i!=10);
into assembly code.
|
|
#2
|
||||
|
||||
|
Re: Assembly language on hypothetical machine
If I got all your rules right, when all operands at all instuctions MUST be immediate values, then it is not possible to implement indexing in this language. There should be at least one istruction which would allow to read or write memory using address stored either in acc or in other memory cell. So there should be instructions like:
Load Acc with value stored at memory cell pointed by acc (or other memory cell) Store Acc at memory cell pointed by acc (or other memory cell) It would be enough if you could use LM ACC SM ACC but those are not said to be possible to use. With immeds only, it could be required to introduce instructions like LMP I: Load ACC with value stored at cell pointed by cell I SMP I: Store ACC at cell pointed by cell I You still have 2 opcodes free, you could use them for those. I hope that my ideas are right and that there is no mistake in this... PS as long as length of array is fixed and known at 'compile time', its possible to do without indexing, just separately for each cell, but I think that its not how you wand it to be done. Hob
__________________
B+! 'There is no cat' - A. Einstein Use [code] [/code] tags! Did YOU share your photo with us at CG Members photo gallery ? |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|