-
help with the code
hi all,
i am attaching my code here. it is reading some ascii instructions from the file , (which are in the linked list) are once it sees the pattern of
LOADC #c1 Rx
LOADC #c2 Ry
op Rz Rx Ry
where (the op can be subtract, add or multiply)
once i get that pattern, i reset the values of first loadc to
LOADC #C3 rZ (C3 is the result)
and frees the other LOADC and op.
Note each instruction is contained within the node. and instruction is the type of pointer, that is pointing to the linked list.
ok, so my problem is that i cannot seem to free the two nodes and result the values to c3.
can somone help me with this.
i am havig hard time with it
anyother questions. i will clarify it .
thanks a lot
fatima
Code:
#include <stdio.h>
#include "CodeGen.h"
#include "InstrUtils.h"
int
main() {
Instruction *instr;
Instruction *temp, *head,*temp2, *temp3;
int x, z, p , s, y, a;
instr = ReadInstructionList(stdin);
temp = instr;
while(temp!=NULL){
if(temp->opcode == LOADC) {
{
x = temp->field1;
z = temp->field2;
}
temp2= temp->next;
if(temp2->opcode == LOADC)
p = temp2->field1;
s = temp2->field2;
temp3 = temp2->next;
if(temp3->opcode == (ADD||SUB||MUL))
{
y = temp3->field1 ;
temp3->field2 = temp->field2;
temp3->field3 = temp2->field2;
// if(z == b && s == c)
// t = temp3->field2;
// n = temp3->field3;
if( temp3->opcode == ADD)
{ a = x + p;
free(temp3);
}
else if (temp3->opcode == SUB)
{ if ( x >p ) a = x - p;
else a = p - x;
free(temp3);
}
else a = x * p;
free(temp3);
}
temp->field1 = a;
temp->field2 = y;
free(temp2);
free(temp3);
}
temp = temp->next;
}
PrintInstructionList(stdout, instr);
return 0;
}
-
thanks for that,
but now i cannot seem to reset the pointer so that it would skip the two nodes. and point to the nodes after the two nodes.
thanks for any kind of hint on that.