Thread: help with the code

  1. #1
    Registered User
    Join Date
    Oct 2002

    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

    #include <stdio.h>
    #include "CodeGen.h"
    #include "InstrUtils.h"
    main() {
      Instruction *instr;
    Instruction *temp, *head,*temp2, *temp3;
    int x, z, p , s, y, a;
      instr = ReadInstructionList(stdin);
       temp = instr;
        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; 
    			  else if (temp3->opcode == SUB)
    				{   if ( x >p ) a  = x - p;
                                            else a = p - x;
                               else a = x * p; 		    
    temp->field1 = a;
    temp->field2 = y;
     temp = temp->next;
    PrintInstructionList(stdout, instr);
    return 0;
    Last edited by kfatima; 10-11-2002 at 12:22 PM.

  2. #2
    Registered User
    Join Date
    Oct 2002
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM