utcguy
April 25th, 2005, 09:18 PM
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:
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.
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:
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.