#INCLUDE "/home/amu5/users/georget/Phd/Simul/Defs/defs.inc"
#USE "/home/amu5/users/georget/Phd/Simul/library"


PROC AddC(CHAN OF BUNDLE frompcpipe,fromapipe,fromlsreg,W,Wc,MA,MAc,LSMP,
          MAa,Pca,Wa,WLx,APa,LSMPa,LSMa,CHAN OF DEB.MESSAGE screen,
          VAL INT report, evaluate, preemption) 

  BOOL pcparchanged, end,Ren,Wen,oldPCpar,PCpar,Nusr,Sp, Lsm, Opc, Ntrm, valid,
       dPc,lsmpc,dPCc,ToInc,LSin, finish, found, term, first,dest.reg.R15,lookahead.table.empty,invalid.lookahead.table.empty,
       new.address.possible,limit.exists,PC.received,PC.increment,WB.received, PCs.OK, instr.found,ldr.or.ldm.r15,limit.exit,
       first.valid,invalid.table.updated:

  [32]BOOL Ctrlb, Dec1ctrlb:  
  [10]BOOL Ctrl1b:

  [MESGLEN]INT Ctrl,Data,Wdata.occ,Pcdata.occ,ack, ackw,WB,PCr,PCtemp, null.ack:
  TIMER clock:
  VAL INT delays IS 2343:   --0.5 sec
  INT time, previous.report, preempt.frequency, preempt.magnitude, accum.preempt, clock0, msgnum, 
      lkahead.table.top, lkahead.table.base,contents,limit,lkahd.PCpar, result,num.of.PCs,cycles,which.limit,
      write.register, read.register1,read.register2,read.register3, invalid.lkahead.table.top, 
      invalid.lkahead.table.base,invalid.contents, is.valid:

  [5][OCCT.SIZE][OCCT.COL]INT occupancy.table:  --an array of occupancy tables!!!!
  [20]INT delay:
  VAL INT process.id IS ADDC.ID:

  VAL INT lkahead.table.size IS 10:
  VAL INT lat.lookahead IS 0:

  VAL INT        PCS.INIT                IS     1:     
  VAL INT        MAX.CYCLES              IS     4:   --limit       
  VAL INT        LDM.LIMIT               IS     3:   --limit       
  VAL INT        MIN.LIMIT               IS     2:   --limit      
  VAL INT        LIMIT                   IS     1:   --indicator     
  VAL INT        LDR.LIMIT               IS     3:   --limit     
  VAL INT        PCPAR.CHANGE            IS     1:   --tag     
  VAL INT        NORMAL                  IS     0:   --tag    
  VAL INT        LDRM.R15                IS     1:   --limit    
  VAL INT        PC.EXPECTED             IS     2:   --tag  
   
  VAL BOOL       VALID.TABLE             IS   TRUE:    
  VAL BOOL       INVALID.TABLE           IS  FALSE:    

  [lkahead.table.size+1][11]INT lookahead.table:    -- latency lookahead,limit, PCpar, 
                                                 -- #total cycles following, which.limit??, #cycles 

  [lkahead.table.size+1][11]INT invalid.lookahead.table:    -- invalid latency lookahead 

           

  -------------------------------------------------------------------------
  PROC calculate.delays()
    SEQ
      delay[0]:=(XOR+ARBITER)+SELECT
      delay[1]:=ARBITER+SELECT
      delay[2]:=SELECT
      delay[3]:=CALLR+CALLR
      delay[4]:=(MULLERC+CALLR)+CALLR
      delay[5]:=CALLA+CALLA
      delay[6]:=((CALLA+CALLA)+XOR)+XOR
      delay[7]:=SELECT+XOR
      delay[8]:=(MULLERC+CALLR)+CALLR
      delay[9]:=((((CALLA+CALLA)+SELECT)+SELECT)+XOR)+XOR
      delay[10]:=MULLERC + XOR
      delay[11]:=(MULLERC+CALLR)+CALLR
      delay[12]:=CALLR+CALLR
      delay[13]:=(CALLA+CALLA)+XOR
      delay[14]:=XOR
  :
  -----------------------------------------------------------------------------
  PROC  initialize.occup.tables()
    SEQ
      initialize.occup.table(occupancy.table[0], PCREGPIPE, PCREGPIPE.SIZE,REGISTER.DELAY)  
      initialize.occup.table(occupancy.table[1], LSMREG, LSMREG.SIZE,REGISTER.DELAY)  
      initialize.occup.table(occupancy.table[2], APIPE,APIPE.SIZE ,REGISTER.DELAY)  
      initialize.occup.table(occupancy.table[3], DEC1REGA,DEC1REGA.SIZE ,REGISTER.DELAY)  
      initialize.occup.table(occupancy.table[4], WCTRLREG,WCTRLREG.SIZE ,REGISTER.DELAY)  
  :
  -------------------------------------------------------------------------

  PROC mkpcc()
    SEQ
      init.hex(Ctrl[0], [PCpar,VSS,VDD, VDD, VSS, Nusr, VSS,VDD, VDD, Opc])

      int.to.bool(Ctrl[0], Ctrlb)      
      Wen:=Ctrlb[7]
      Ren:=Ctrlb[6]
      Opc:=Ctrlb[3]
  :

  -----------------------------------------------------------------------------
  ------------------------------------------------------------------------------

  PROC  decode.instruction( VAL []INT instruction, INT result, is.valid)
  
    SEQ
      SEQ
        write.register:=-1
        result:=-1
        IF  
          ((instruction[IS.INSTR]) /\ 1) <> (INT PCpar)     --This istruction has been discarded
            SEQ
              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  This istruction has been discarded ", instruction)

              is.valid:=0
          TRUE
            SEQ
              is.valid:=1
        SEQ
          SEQ
            SEQ
              lkahd.PCpar:=((instruction[IS.INSTR]) /\ 1)

              --------decode the instruction-------------
              IF
                (((instruction[INSTRUCTION]) /\  #0E000000) = #0A000000)   --branch
                  --------------------------------------------- 
                  SEQ
                    result:=BRANCH
                    read.register1:=-1
                    read.register2:=-1
                    read.register3:=-1
                   

                (((instruction[INSTRUCTION]) /\  #0C000000) = #00000000)   --data processing or (msr, mrs)
                  --------------------------------------------- 
                  SEQ
                    IF
                      ((instruction[INSTRUCTION]) /\  #01800000) = #01000000 --(msr, mrs)
                        SEQ
                          result:=-1
                          read.register1:=-1
                          read.register2:=-1
                          read.register3:=-1

                      TRUE  --data processing
                        ----------------------------------------------------------------- 
                        SEQ
                          IF
                            ((instruction[INSTRUCTION]) /\  #0FC00000) = #00000000 --multiply
                              SEQ
                                read.register1:= ((instruction[INSTRUCTION])/\ #0000000F)        --Rm
                                read.register2:= (((instruction[INSTRUCTION])/\ #00000F00) >> 8)  --Rs
                                IF
                                  ((instruction[INSTRUCTION])/\ 00200000) <>  0  -- accumulate
                                    SEQ
                                      read.register3:=(((instruction[INSTRUCTION])/\ #0000F000) >> 12) --Rn 
                                  ((instruction[INSTRUCTION])/\ 00200000) = 0  -- just multiply
                                    SEQ
                                      read.register3:=-1
                                IF                        --check if Rd=R15
                                  ((instruction[INSTRUCTION]) /\  #000F0000) = #000F0000  --Rd=r15
                                    SEQ
                                      result:= DATA.PROCESSING
                                      
                                  TRUE
                                    SEQ
                                      result:=(-1)
                            ----------------------------------------------------------------- 
                            ((instruction[INSTRUCTION]) /\  #0FC00000) <> #00000000 -- NOT multiply
                              SEQ
                                read.register3:=(-1)
                                read.register1:= (((instruction[INSTRUCTION])/\ #000F0000) >> 16)        --Rn
                                IF
                                  ((instruction[INSTRUCTION]) /\  #02000000) = 0   --bit 25 is 0
                                    SEQ
                                      read.register2:= ((instruction[INSTRUCTION])/\ #0000000F)   --Rm
                                  ((instruction[INSTRUCTION]) /\  #02000000) <> 0   --bit 25 is 1
                                    SEQ
                                      read.register2:=(-1) 

                                IF                        --check if Rd=R15
                                  ((instruction[INSTRUCTION]) /\  #0000F000) = #0000F000  --Rd=r15
                                    SEQ
                                      result:= DATA.PROCESSING 
                                  TRUE
                                    SEQ
                                      result:=(-1)
                      ----------------------------------------------------------------- 
                (((instruction[INSTRUCTION]) /\  #0C000000) = #04000000)   --ldr or str
                  --------------------------------------------- 
                  SEQ
                    IF           
                      (((instruction[INSTRUCTION]) /\  #00100000) = #00100000)   --ldr 
                        SEQ
                          result:=LDR
                          ------------------ read registers -----------------------
                          read.register1:=(((instruction[INSTRUCTION]) /\  #0000F000) >> 16) 
                          read.register3:=(-1)
                          IF
                            ((instruction[INSTRUCTION]) /\  #02000000) = 0   --bit 25 is 0
                              SEQ
                                read.register2:= ((instruction[INSTRUCTION])/\ #0000000F)   --Rm
                            ((instruction[INSTRUCTION]) /\  #02000000) <> 0   --bit 25 is 1
                              SEQ
                                read.register2:=(-1) 
                          ------------------ write register-----------------------                         
                          IF
                            (((instruction[INSTRUCTION]) /\  #0000F000) = #0000F000)   --Rd=R15
                              SEQ
                                dest.reg.R15:=TRUE
                                write.register:=-1
                            (((instruction[INSTRUCTION]) /\  #0000F000) <> #0000F000)   --Rd<>R15
                              SEQ
                                dest.reg.R15:=FALSE
                                write.register:= (((instruction[INSTRUCTION]) /\  #0000F000) >> 12)
                      (((instruction[INSTRUCTION]) /\   #00100000) <> #00100000) --str
                        SEQ
                          result:=STR

                (((instruction[INSTRUCTION]) /\  #0E000000) = #08000000)   --ldm or stm
                  ---------------------------------------------------------------- 
                  SEQ
                    IF           
                      (((instruction[INSTRUCTION]) /\  #00100000) = #00100000)   --ldm 
                        SEQ
                          result:=LDM
                          IF
                            (((instruction[INSTRUCTION]) /\  #00008000) = #00008000)   --Rd=R15
                              SEQ
                                dest.reg.R15:=TRUE

                            (((instruction[INSTRUCTION]) /\  #00008000) <> #00008000)   --Rd<>R15
                              SEQ
                                dest.reg.R15:=FALSE
                      (((instruction[INSTRUCTION]) /\  #00100000) <> #00100000)   --stm 

                        SEQ
                          result:=STM

                (((instruction[INSTRUCTION]) /\  #0F000000) = #0F000000)   --SWI
                  ---------------------------------------------------------------- 
                  SEQ
                    result:=SWI
                    read.register1:=-1
                    read.register2:=-1
                    read.register3:=-1

                ((instruction[INSTRUCTION]) /\  #0FB00FF0) = #01000090  --SWAP
                  ---------------------------------------------------------------- 
                  SEQ
                    read.register1:=  ((instruction[INSTRUCTION]) /\  #0000000F)  --Rm
                    read.register2:=  (((instruction[INSTRUCTION]) /\  #00F0000) >> 16)  --Rn
                    read.register3:=-1
                    result:=-1

                TRUE
                  ---------------------------------------------------------------- 
                  SEQ
                    read.register1:=-1
                    read.register2:=-1
                    read.register3:=-1
                    result:=(-1)
  :

  ------------------------------------------------------------------------------
  PROC  append.invalid.lookahead.table()
    SEQ
      --calculate.instr.cycles()

      invalid.lookahead.table[invalid.lkahead.table.top]:=lookahead.table[lkahead.table.base]
      invalid.lookahead.table[lkahead.table.top][1]:=NO.LIMIT
      invalid.lookahead.table[lkahead.table.top][5]:=0
      invalid.lookahead.table[invalid.lkahead.table.top][4]:= PCPAR.CHANGE 

      invalid.lkahead.table.top:=(invalid.lkahead.table.top+1) REM (lkahead.table.size+1)
      invalid.contents:=invalid.contents+1
      invalid.lookahead.table.empty:=FALSE
  :
  ------------------------------------------------------------------------------
  -------------------------------------------------------------------------------------------

  PROC  update.lookahead.table(VAL BOOL which.table, VAL INT action, VAL []INT instruction)


    --lookahead.table:  each entry in this FIFO buffer contains :
                        --0) the latency lookahead of the corresponding event
                        --1) if there is a limit on the number of PCr following this event
                        --2) the Pcpar of the instruction
                        --3) the number of cycles of instructions following this instruction
                        --4) A flag to show if this instruction has the potential to change the PCpar
                        --5) The number of instructions following this instruction
    INT i:
    BOOL exit:
    -----------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------
    PROC insert.invalid.lookahead.table(VAL INT pc.init, which.limit, latency.lookahead, PCpar, limit )
      SEQ

        IF
          latency.lookahead<>(-1)
            SEQ 
              invalid.contents:=invalid.contents+1
              invalid.lookahead.table[invalid.lkahead.table.top][0]:= latency.lookahead --invalid.lookahead timestamp
              invalid.lookahead.table[invalid.lkahead.table.top][1]:= NO.LIMIT --no of messages from other channel, limit
              invalid.lookahead.table[invalid.lkahead.table.top][2]:= PCpar  --the pcpar of the instruction
              invalid.lookahead.table[invalid.lkahead.table.top][3]:= cycles  --number of cycles following this instruction  initially cycles of this instruction
              invalid.lookahead.table[invalid.lkahead.table.top][4]:= PCPAR.CHANGE 
              invalid.lookahead.table[invalid.lkahead.table.top][5]:=0  --number of instructions following this instruction initially 1
              invalid.lookahead.table[invalid.lkahead.table.top][6]:=(instruction[INSTRUCTION])  --number of instructions following this instruction initially 1
              invalid.lookahead.table[invalid.lkahead.table.top][7]:=write.register  
              invalid.lookahead.table[invalid.lkahead.table.top][8]:=read.register1 
              invalid.lookahead.table[invalid.lkahead.table.top][9]:=read.register2  
              invalid.lookahead.table[invalid.lkahead.table.top][10]:=read.register3 

              invalid.lkahead.table.top:=(invalid.lkahead.table.top+1) REM (lkahead.table.size+1)
              invalid.lookahead.table.empty:=FALSE
          latency.lookahead=(-1)
            SEQ 
              IF
                invalid.lookahead.table.empty=FALSE
                  SEQ
                    ----------------------- insert this only if there is a write pending in the invalid.lookahead table
                    instr.found:=FALSE

                    i:=invalid.lkahead.table.base
                    WHILE ((i <> invalid.lkahead.table.top) AND (instr.found=FALSE))
                      SEQ
                        IF
                          ((((invalid.lookahead.table[i][7]) <> (-1) ) AND ((invalid.lookahead.table[i][4]) = LDR)) AND (((((invalid.lookahead.table[i][7]) =read.register1 ) OR ((invalid.lookahead.table[i][7]) =read.register2 )) OR ((invalid.lookahead.table[i][7]) =read.register3 ))))

                            SEQ
                              instr.found:=TRUE
                          TRUE
                            SEQ
                              instr.found:=FALSE

                        
                        i:= (i+1) 
                        IF
                          (i >lkahead.table.size)
                            SEQ
                              i:=0
                          TRUE
                            SEQ
                              SKIP

                    IF
                      instr.found=TRUE
                        SEQ
                          lookahead.table.empty:=FALSE
                          invalid.lookahead.table[invalid.lkahead.table.top][0]:= -1
                          invalid.lookahead.table[invalid.lkahead.table.top][1]:= NO.LIMIT --no of messages from other channel, limit
                          invalid.lookahead.table[invalid.lkahead.table.top][2]:= PCpar  --the pcpar of the instruction
                          invalid.lookahead.table[invalid.lkahead.table.top][3]:= cycles  --number of cycles following this instruction  initially cycles of this instruction
                          invalid.lookahead.table[invalid.lkahead.table.top][4]:= PCPAR.CHANGE   
                          invalid.lookahead.table[invalid.lkahead.table.top][5]:=PCS.INIT  --number of instructions following this instruction initially 1
                          invalid.lookahead.table[invalid.lkahead.table.top][6]:=(instruction[INSTRUCTION])  --number of instructions following this instruction initially 1
                          invalid.lookahead.table[invalid.lkahead.table.top][7]:=write.register  --number of instructions following this instruction initially 1

                          invalid.lookahead.table[invalid.lkahead.table.top][8]:=read.register1 
                          invalid.lookahead.table[invalid.lkahead.table.top][9]:=read.register2  
                          invalid.lookahead.table[invalid.lkahead.table.top][10]:=read.register3 
 
                          invalid.lkahead.table.top:=(invalid.lkahead.table.top+1) REM (lkahead.table.size+1)

                      instr.found=FALSE
                        SEQ
                          SKIP


                invalid.lookahead.table.empty=TRUE
                  SEQ
                    SKIP
    :
    -----------------------------------------------------------------------------------
    PROC insert.lookahead.table(VAL INT pc.init, which.limit, latency.lookahead, PCpar, limit )
  
      SEQ

        IF
          latency.lookahead<>(-1)
            SEQ 
              lookahead.table[lkahead.table.top][0]:= latency.lookahead --lookahead timestamp
              lookahead.table[lkahead.table.top][1]:= limit --no of messages from other channel, limit
              lookahead.table[lkahead.table.top][2]:= PCpar  --the pcpar of the instruction
              lookahead.table[lkahead.table.top][3]:= cycles  --number of cycles following this instruction  initially cycles of this instruction
              lookahead.table[lkahead.table.top][4]:= which.limit   
              lookahead.table[lkahead.table.top][5]:=pc.init  --number of instructions following this instruction initially 1
              lookahead.table[lkahead.table.top][6]:=(instruction[INSTRUCTION])  --number of instructions following this instruction initially 1
              lookahead.table[lkahead.table.top][7]:=write.register  
              lookahead.table[lkahead.table.top][8]:=read.register1 
              lookahead.table[lkahead.table.top][9]:=read.register2  
              lookahead.table[lkahead.table.top][10]:=read.register3 

              lkahead.table.top:=(lkahead.table.top+1) REM (lkahead.table.size+1)
              contents:=contents+1
              lookahead.table.empty:=FALSE
          latency.lookahead=(-1)
            SEQ 
              IF
                lookahead.table.empty=FALSE
                  SEQ
                    ----------------------- insert this only if there is a write pending in the lookahead table
                    instr.found:=FALSE

                    i:=lkahead.table.base
                    WHILE ((i <> lkahead.table.top) AND (instr.found=FALSE))
                      SEQ
                        IF
                          ((((lookahead.table[i][7]) <> (-1) ) AND ((lookahead.table[i][4]) = LDR)) AND (((((lookahead.table[i][7]) =read.register1 ) OR ((lookahead.table[i][7]) =read.register2 )) OR ((lookahead.table[i][7]) =read.register3 ))))

                            SEQ
                              instr.found:=TRUE
                          TRUE
                            SEQ
                              instr.found:=FALSE

                        
                        i:= (i+1) 
                        IF
                          (i >lkahead.table.size)
                            SEQ
                              i:=0
                          TRUE
                            SEQ
                              SKIP

                    IF
                      instr.found=TRUE
                        SEQ
                          lookahead.table.empty:=FALSE
                          lookahead.table[lkahead.table.top][0]:= -1
                          lookahead.table[lkahead.table.top][1]:= NO.LIMIT --no of messages from other channel, limit
                          lookahead.table[lkahead.table.top][2]:= PCpar  --the pcpar of the instruction
                          lookahead.table[lkahead.table.top][3]:= cycles  --number of cycles following this instruction  initially cycles of this instruction
                          lookahead.table[lkahead.table.top][4]:= which.limit   
                          lookahead.table[lkahead.table.top][5]:=PCS.INIT  --number of instructions following this instruction initially 1
                          lookahead.table[lkahead.table.top][6]:=(instruction[INSTRUCTION])  --number of instructions following this instruction initially 1
                          lookahead.table[lkahead.table.top][7]:=write.register  --number of instructions following this instruction initially 1

                          lookahead.table[lkahead.table.top][8]:=read.register1 
                          lookahead.table[lkahead.table.top][9]:=read.register2  
                          lookahead.table[lkahead.table.top][10]:=read.register3 
 
                          lkahead.table.top:=(lkahead.table.top+1) REM (lkahead.table.size+1)

                      instr.found=FALSE
                        SEQ
                          SKIP


                lookahead.table.empty=TRUE
                  SEQ
                    SKIP
    :
    -------------------------------------------------------------------------------------------------

    SEQ
      SEQ
        IF
          action=DELETE
            SEQ
              IF
                which.table=VALID.TABLE
                  SEQ
                    IF
                      (lookahead.table.empty=TRUE)
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF DELETE: TABLE IS EMPTY...DO NOT DELETE",NULL1 )
                      (lookahead.table.empty=FALSE)
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF DELETING FROM LkAHEAD QUEUE.... ", [(lookahead.table[lkahead.table.base][6]),0,0,0])
             
                          ---------------------------------------------------------------
                          lookahead.table[lkahead.table.base][3]:=0
                          lkahead.table.base:=(lkahead.table.base+1) REM (lkahead.table.size+1)  --delete
                          contents:=contents-1

                          WHILE (((lookahead.table[lkahead.table.base][0])= (-1)) AND (lkahead.table.base <> lkahead.table.top))
                            SEQ
                              lkahead.table.base:=(lkahead.table.base+1) REM (lkahead.table.size+1) --delete

                  
                          IF
                            contents=0
                              SEQ
                                lookahead.table.empty:=TRUE
                            contents>0
                              SEQ
                                SKIP
                          exit:=FALSE

                          IF
                            ((lookahead.table.empty=FALSE) AND (lookahead.table[lkahead.table.base][1] <> NO.LIMIT))
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lookahead table not empty, limit is  ",[(lookahead.table[lkahead.table.base][1]),0,0,0] )
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF instruction is , limit is  ",[(lookahead.table[lkahead.table.base][6]),0,0,0] )
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF which.limit.  is  ",[(lookahead.table[lkahead.table.base][4]),0,0,0] )
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF cycles is ",[(lookahead.table[lkahead.table.base][3]),0,0,0] )
                                limit.exists:=TRUE
                            TRUE
                              SEQ
                                limit.exists:=FALSE

                                IF
                                  (lookahead.table.empty=TRUE)
                                    SEQ
                                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lookahead table EMPTY!! ",NULL1)
                                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF base is  ",[lkahead.table.base, 0,0,0])
                                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF top is  ",[lkahead.table.top, 0,0,0])
                                      limit.exists:=FALSE
                                  (lookahead.table.empty=FALSE)
                                    SEQ
                                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF NOT EMPTY AND NOT LIMIT ",NULL1)
                                SKIP

                which.table=INVALID.TABLE
                  SEQ
                    lookahead.table[lkahead.table.base][3]:=0
                    invalid.lkahead.table.base:=(invalid.lkahead.table.base+1) REM (lkahead.table.size+1)  --delete
                    invalid.contents:=invalid.contents-1

                    WHILE (((invalid.lookahead.table[invalid.lkahead.table.base][0])= (-1)) AND (invalid.lkahead.table.base <> invalid.lkahead.table.top))
                      SEQ
                        invalid.lkahead.table.base:=(invalid.lkahead.table.base+1) REM (lkahead.table.size+1) --delete

                  
                    IF
                      invalid.contents=0
                        SEQ
                          invalid.lookahead.table.empty:=TRUE
                      invalid.contents>0
                        SEQ
                          SKIP
                    exit:=FALSE
                    IF
                      ((invalid.lookahead.table.empty=FALSE) AND (invalid.lookahead.table[invalid.lkahead.table.base][1] <> NO.LIMIT))
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  lookahead table not empty, limit is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][1]),0,0,0] )
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  instruction is , limit is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][6]),0,0,0] )
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  which.limit.  is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][4]),0,0,0] )
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  cycles is ",[(invalid.lookahead.table[invalid.lkahead.table.base][3]),0,0,0] )
                          limit.exists:=TRUE
                      TRUE
                        SEQ
                          limit.exists:=FALSE
                          IF
                            (invalid.lookahead.table.empty=TRUE)
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  lookahead table EMPTY!! ",NULL1)
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  base is  ",[invalid.lkahead.table.base, 0,0,0])
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  top is  ",[invalid.lkahead.table.top, 0,0,0])
                                limit.exists:=FALSE
                            (invalid.lookahead.table.empty=FALSE)
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF INVALID  NOT EMPTY AND NOT LIMIT ",NULL1)


                          

          action=APPEND
            SEQ

              decode.instruction(instruction, result, is.valid)
              ---------------------------------------------------------------
              IF
                ldr.or.ldm.r15=TRUE
                  SEQ
                    result:=-3
                    insert.lookahead.table(MIN.LIMIT,PC.EXPECTED, 0, lkahd.PCpar, LIMIT)
                TRUE
                  SKIP
              IF

                result=(-1)
                  SEQ
                    
                    IF
                      (((read.register1 <> (-1)) OR (read.register2 <> (-1))) OR (read.register3 <> (-1))) 
                        SEQ
                          IF
                            is.valid=1
                              SEQ
                                insert.lookahead.table(PCS.INIT,which.limit, (-1), lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                --insert.invalid.lookahead.table(PCS.INIT,which.limit, (-1), lkahd.PCpar, NO.LIMIT)

                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF result -1  ", instruction)
                      TRUE
                        SKIP
                result=(-3)
                  SEQ
                    SKIP

                
                (((result<>(-1)) AND (result<>(-2))) AND (result<>(-3)))
                  SEQ
                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF result (instruction) is  ", [result, 0,0,0])
                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF inserting into lookahead queue ", instruction)
                    IF
                      ----------------------------------------------------------
                      result=BRANCH
                        SEQ
                          which.limit:=PCPAR.CHANGE
                          IF
                            is.valid=1
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF result (instruction) is  ", [result, 0,0,0])

                                insert.lookahead.table(PCS.INIT,which.limit,BRANCH.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF NOT inserting into lookahead queue ", instruction)

                                SKIP

                      ----------------------------------------------------------
                      result=SWI
                        SEQ   
                          which.limit:=PCPAR.CHANGE
                          --exactly the same as branch?
                          IF
                            is.valid=1
                              SEQ
                                insert.lookahead.table(PCS.INIT,which.limit,SWI.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                SKIP


                      ----------------------------------------------------------
                      result=DATA.PROCESSING                --with R15 as the destination register
                        SEQ                                 --exactly the same as branch?
                          which.limit:=PCPAR.CHANGE
                          IF
                            is.valid=1
                              SEQ
                                insert.lookahead.table(PCS.INIT,which.limit,DP.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                SKIP

                      ----------------------------------------------------------
                      result=LDR
                        SEQ
                          --*first entry: data address it comes from
                          --the ALU so it is the same as in BRANCH*

                          IF
                            dest.reg.R15=TRUE  
                              SEQ
                                which.limit:=PCPAR.CHANGE
                            dest.reg.R15=FALSE  
                              SEQ
                                which.limit:=LDR
                          IF
                            is.valid=1
                              SEQ

                                insert.lookahead.table(PCS.INIT,which.limit,LDR1.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)

                                IF
                                  ----------------------------------------------------------------------
                                  dest.reg.R15=TRUE      --a)
                                    SEQ
                                      -----------------------------------------------------------
                                      --*second entry: the new PC comes
                                      -- from the memory. In this case
                                      --the prefetching stops so one PCr is received and discarded.
                                      --If an abort occurs then the
                                      --address from memory will never arrive but the address
                                      --of the istruction, which will be reexecuted) will 
                                      --arrive from ALU. So
                                      --in any case this second message will arrive to AddInt.
                                      --The delay is the min(delay:addc->memory-->adc,
                                      --delay:addc-->memory-->xption.address-->addc)
                                      --No NULL message is required in this case
                                      -----------------------------------------------------------

  
                                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF LDR dest.reg.R15=TRUE ",NULL1)
                                      insert.lookahead.table(PCS.INIT,which.limit,LDR2.LAT.LKAHD, lkahd.PCpar, 1)
                                      dest.reg.R15:=FALSE

                                      ------------------------------------------------------------
                                  dest.reg.R15=FALSE     --b)
                                    SEQ
                                      ------------------------------------------------------------
                                      --*second entry: either the Xption address in
                                      --case of abort or a NULL message
                                      --In this case there is no second event in the real system.
                                      --However if an abort occurs, the Xption address
                                      --will be sent by the ALU.
                                      --This is the delay from the moment the data address arrives
                                      --at the AddInt to the moment the abort
                                      --arrives at the ALU.
                                      ------------------------------------------------------------

                                insert.lookahead.table(PCS.INIT,which.limit,LDR2.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                                debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF LDR dest.reg.R15=FALSE ",NULL1)
                            is.valid=0
                              SEQ
                                insert.invalid.lookahead.table(PCS.INIT,which.limit,LDR1.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)

                      ----------------------------------------------------------
                      result=STR
                        SEQ
                          which.limit:=NORMAL

                          IF
                            is.valid=1
                              SEQ


                                ---------------------------------------------------
                                --*first entry: data address it comes
                                --from the ALU so it is the same as in BRANCH*
                                ---------------------------------------------------
                                insert.lookahead.table(PCS.INIT,which.limit,STR1.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                                ---------------------------------------------------
                                --*second entry: either the Xption address
                                --in case of abort or a NULL message
                                ---------------------------------------------------

                                insert.lookahead.table(PCS.INIT,which.limit,STR2.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                SKIP
                      ----------------------------------------------------------
                      result=LDM
                        SEQ
                          which.limit:=LDM
                          IF
                            is.valid=1
                              SEQ
                                ---------------------------------------------------
                                --*first entry: base data address it comes
                                --from the ALU so it is the same as in BRANCH*
                                ---------------------------------------------------
                                insert.lookahead.table(PCS.INIT,which.limit,LDM1.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)

                                IF
                                  ----------------------------------------------------------------------
                                  dest.reg.R15 = TRUE    --R15 in register list
                                    SEQ
                                      ---------------------------------------------------
                                      --*second entry: the new PC, it comes
                                      --from the memory. In this case
                                      -- the prefetching stops so one PCr is received and discarded.
                                      -- If an abort occurs then the
                                      -- address from memory will never arrive but the address
                                      -- of the instruction code will arrive from ALU. So
                                      -- in any case this second message will arrive to addint
                                      ---------------------------------------------------

                                      insert.lookahead.table(PCS.INIT,which.limit,LDM2.LAT.LKAHD, lkahd.PCpar, 1)

                                      dest.reg.R15:=FALSE

                                  dest.reg.R15=FALSE
                                    SEQ
                                      ---------------------------------------------------
                                      --*second entry: either the Xption address
                                      --in case of abort or a NULL message
                                      --in this case there is no second event in the real system.
                                      --However if an abort occurs, the address
                                      --of the instruction will be sent by the ALU.
                                      --This is the delay from the moment the base address LDM arrives
                                      --at the AddInt to the moment the abort
                                      --arrives at the ALU.
                                      ---------------------------------------------------
                                      insert.lookahead.table(PCS.INIT,which.limit,LDM2.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                SKIP
                      ----------------------------------------------------------
                      result=STM
                        SEQ
                          which.limit:=LDM
                          IF
                            is.valid=1
                              SEQ
                                ------------------------------------------------------
                                --*first entry: base data address it comes from
                                --the ALU so it is the same as in BRANCH*
                                -----------------------------------------------
                                insert.lookahead.table(PCS.INIT,which.limit,STM1.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)  --limit is the size of the PC pipe + 1!!!!!!!!

                                ------------------------------------------------------
                                --*second entry: either the instruction
                                --address in case of abort or a NULL message
                                ------------------------------------------------------

                                insert.lookahead.table(PCS.INIT,which.limit,STM2.LAT.LKAHD, lkahd.PCpar, NO.LIMIT)
                            is.valid=0
                              SEQ
                                SKIP

                      ----------------------------------------------------------
                      TRUE
                        SEQ
                          SKIP

  :
  -----------------------------------------------------------------------------
  PROC calculate.instr.cycles(VAL []INT  instruction)
    SEQ
      IF
        (((instruction[INSTRUCTION]) /\  #0F000000) = #0F000000)              --SWI  3 cycles
          ---------------------------------------------------------------- 
          SEQ
            cycles:=3  

        (((instruction[INSTRUCTION]) /\  #0C000000) = #04000000)            --ldr or str
          --------------------------------------------- 
          SEQ
            IF           
              (((instruction[INSTRUCTION]) /\  #00100000) = #00100000)        --ldr 
                SEQ
                  cycles:=1
              (((instruction[INSTRUCTION]) /\   #00100000) <> #00100000)      --str 
                SEQ
                  IF
                    (((instruction[INSTRUCTION]) /\  #02000000) = #02000000)  --STR  reg offset 2 cycles
                      SEQ
                        cycles:=2
                    TRUE
                      SEQ
                        cycles:=1

        (((instruction[INSTRUCTION]) /\  #0F000000) = #0B000000)   --branch link  2 cycles
          --------------------------------------------- 
          SEQ
            cycles:=2

        (((((instruction[INSTRUCTION]) /\  #0C000000) = #00000000)) AND (((instruction[INSTRUCTION]) /\  #01800000) <> #01000000)) --data processing
                       
          ----------------------------------------------------------------- 
          SEQ
            IF
              ((instruction[INSTRUCTION]) /\  #0FC00000) = #00000000 --multiply
                SEQ
                  cycles:=1

              ((instruction[INSTRUCTION]) /\  #0FC00000) <> #00000000 -- NOT multiply, ie ALU operation
                SEQ
                  IF                        --check if register shift
                    ((instruction[INSTRUCTION]) /\  #02000000) = #00000000    --bit 24 is 0    
                      SEQ
                        cycles:=2
                    TRUE
                      SEQ
                        cycles:=1

        ((instruction[INSTRUCTION]) /\  #01F0F000) = #01B0F000 --MOVS  PC,...
          --------------------------------------------- 
          SEQ
            cycles:=2
          
        TRUE
          --------------------------------------------- 
          SEQ
            cycles:=1

  :
  -----------------------------------------------------------------------------
  PROC  update.limits()
    INT i,j: 
    SEQ
      limit.exists:=FALSE  

      ----------------------CHECK VALID LOOKAHEAD TABLE  ------------------------------- 
  
      IF
        lookahead.table.empty=FALSE

          SEQ
            i:=lkahead.table.base
            WHILE (i <> lkahead.table.top)
              SEQ
                lookahead.table[i][5]:=lookahead.table[i][5] + 1    --increment num of PCs following this instruction
                --------------------update LDR or LDM  - R15  limits-------------------------------
                IF
                  ((lookahead.table[i][4]=PC.EXPECTED) AND (lookahead.table[i][5]>=LDRM.R15))  
                    SEQ
                      lookahead.table[i][1]:=LIMIT
                      debugmsg(report,screen, "ADDINT-AddC: UPDATE LIMITS VALID TABLE limit reached LDRM.R15", [lookahead.table[i][6],0,0,0])

                  TRUE
                    SEQ
                      SKIP
                --------------------update LDR limits-----------------------------------------------
                IF
                  lookahead.table[i][5]>=LDR.LIMIT  
                    SEQ
                      IF
                        ((((lookahead.table[i][8]) <> (-1)) OR ((lookahead.table[i][9]) <> (-1))) OR ((lookahead.table[i][10]) <> (-1)))   
                          SEQ                            --this is a read register instruction and possibly there is a 
                                                         --write on that register pending....
 
                            j:=lkahead.table.base
                            WHILE (j <> i)
                              SEQ
                                IF
                                  ((((lookahead.table[j][7]) <> (-1)) AND ((lookahead.table[j][4]) <> PCPAR.CHANGE)) AND ((((lookahead.table[j][7]) =lookahead.table[i][8] ) OR ((lookahead.table[j][7]) = lookahead.table[i][9])) OR ((lookahead.table[j][7]) = lookahead.table[i][10])))

                                    SEQ    --match found
                                      
                                      lookahead.table[j][1]:=LIMIT
                                      debugmsg(report,screen, "ADDINT-AddC: UPDATE LIMITS VALID TABLE limit LDR", [lookahead.table[i][6],0,0,0])

                                  TRUE
                                    SKIP
                                j:= (j+1) 
                                IF
                                  (j >lkahead.table.size)
                                    SEQ
                                      j:=0
                                  TRUE
                                    SEQ
                                      SKIP
                        TRUE
                          SKIP
                  TRUE 
                    SEQ
                      SKIP
                --------------------update LDM limit-----------------------------------------------
                IF
                  (((lookahead.table[i][4])=LDM) AND (((lookahead.table[i][5])=LDM.LIMIT) AND ((lookahead.table[i][1])=NO.LIMIT))) 
                    SEQ
                      lookahead.table[i][1]:=LIMIT
                      debugmsg(report,screen, "ADDINT-AddC: UPDATE LIMITS VALID TABLE limit reached LDM", [lookahead.table[i][6],0,0,0])

                      j:= (i+1) 
                      IF
                        (j >lkahead.table.size)
                          SEQ
                            j:=0
                        TRUE
                          SEQ
                            SKIP
                      lookahead.table[j][1]:=LIMIT    --second entry for LDM/STM intructions

                  TRUE 
                    SEQ
                      SKIP
                -----------------------update limit due to cycles following ----------------
                IF
                  lookahead.table[i][5]=MIN.LIMIT  --OK, this instruction will enter Dec1
                    SEQ
                      j:=lkahead.table.base
                      WHILE (j <> i)
                        SEQ
                          IF
                            ((lookahead.table[j][4]) <>PCPAR.CHANGE)   --this entry will not change the pcpar
                              SEQ
                                lookahead.table[j][3]:=lookahead.table[j][3] + lookahead.table[i][3]
                                IF 
                                  ((lookahead.table[j][3])>= MAX.CYCLES)
                                    SEQ
                                      lookahead.table[j][1]:=LIMIT
                                      debugmsg(report,screen, "ADDINT-AddC: UPDATE LIMITS VALID TABLE limit reached MAX. CYCLES", [lookahead.table[i][6],0,0,0])

                                  TRUE
                                    SEQ
                                      SKIP
                            TRUE
                              SEQ
                                SKIP
                          j:= (j+1) 
                          IF
                            (j >lkahead.table.size)
                              SEQ
                                j:=0
                            TRUE
                              SEQ
                                SKIP
                  TRUE
                    SEQ
                      SKIP

                --------------------------------------------------------------------------

                i:= (i+1) 
                IF
                  (i >lkahead.table.size)
                    SEQ
                      i:=0
                  TRUE
                    SEQ
                      SKIP
            IF
              lookahead.table[lkahead.table.base][1] <> NO.LIMIT
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF update.limits lookahead table not empty, limit is  ",[(lookahead.table[lkahead.table.base][1]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF instruction is , limit is  ",[(lookahead.table[lkahead.table.base][6]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF which.limit.  is  ",[(lookahead.table[lkahead.table.base][4]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF cycles is ",[(lookahead.table[lkahead.table.base][3]),0,0,0] )
                  limit.exists:=TRUE
              lookahead.table[lkahead.table.base][1] = NO.LIMIT
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lookahead table not empty, no limit  ",NULL1)
                  
                  SKIP

        lookahead.table.empty=TRUE
          SEQ
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lookahead table empty  ",NULL1)
            limit.exists:=FALSE

            SKIP

      ----------------------CHECK INVALID LOOKAHEAD TABLE  ------------------------------- 
      IF
        invalid.lookahead.table.empty=FALSE
          SEQ
            i:=invalid.lkahead.table.base
            WHILE (i <> invalid.lkahead.table.top)
              SEQ
                invalid.lookahead.table[i][5]:=invalid.lookahead.table[i][5] + 1    --increment num of PCs following this instruction

                --------------------update LDR or LDM  - R15  limits-------------------------------
                IF
                  ((invalid.lookahead.table[i][4]=PC.EXPECTED) AND (invalid.lookahead.table[i][5]>=LDRM.R15))  
                    SEQ
                      invalid.lookahead.table[i][1]:=LIMIT
                  TRUE
                    SEQ
                      SKIP
                --------------------update LDR limits-----------------------------------------------
                IF
                  invalid.lookahead.table[i][5]>=LDR.LIMIT  
                    SEQ
                      IF
                        ((((invalid.lookahead.table[i][8]) <> (-1)) OR ((invalid.lookahead.table[i][9]) <> (-1))) OR ((invalid.lookahead.table[i][10]) <> (-1)))   
                          SEQ                            --this is a read register instruction and possibly there is a 
                                                         --write on that register pending....
 
                            j:=invalid.lkahead.table.base
                            WHILE (j <> i)
                              SEQ
                                IF
                                  ((((invalid.lookahead.table[j][7]) <> (-1)) AND ((invalid.lookahead.table[j][4]) <> PCPAR.CHANGE)) AND ((((invalid.lookahead.table[j][7]) =invalid.lookahead.table[i][8] ) OR ((invalid.lookahead.table[j][7]) = invalid.lookahead.table[i][9])) OR ((invalid.lookahead.table[j][7]) = invalid.lookahead.table[i][10])))

                                    SEQ    --match found
                                      
                                      invalid.lookahead.table[j][1]:=LIMIT
                                  TRUE
                                    SKIP
                                j:= (j+1) 
                                IF
                                  (j >lkahead.table.size)
                                    SEQ
                                      j:=0
                                  TRUE
                                    SEQ
                                      SKIP
                        TRUE
                          SKIP
                  TRUE 
                    SEQ
                      SKIP
                --------------------update LDM limit-----------------------------------------------
                IF
                  (((invalid.lookahead.table[i][4])=LDM) AND (((invalid.lookahead.table[i][5])=LDM.LIMIT) AND ((invalid.lookahead.table[i][1])=NO.LIMIT))) 
                    SEQ
                      invalid.lookahead.table[i][1]:=LIMIT
                      j:= (i+1) 
                      IF
                        (j >lkahead.table.size)
                          SEQ
                            j:=0
                        TRUE
                          SEQ
                            SKIP
                      invalid.lookahead.table[j][1]:=LIMIT    --second entry for LDM/STM intructions

                  TRUE 
                    SEQ
                      SKIP
                -----------------------update limit due to cycles following ----------------
                IF
                  invalid.lookahead.table[i][5]=MIN.LIMIT  --OK, this instruction will enter Dec1
                    SEQ
                      j:=invalid.lkahead.table.base
                      WHILE (j <> i)
                        SEQ
                          IF
                            ((invalid.lookahead.table[j][4]) <>PCPAR.CHANGE)   --this entry will not change the pcpar
                              SEQ
                                invalid.lookahead.table[j][3]:=invalid.lookahead.table[j][3] + invalid.lookahead.table[i][3]
                                IF 
                                  ((invalid.lookahead.table[j][3])>= MAX.CYCLES)
                                    SEQ
                                      invalid.lookahead.table[j][1]:=LIMIT
                                  TRUE
                                    SEQ
                                      SKIP
                            TRUE
                              SEQ
                                SKIP
                          j:= (j+1) 
                          IF
                            (j >lkahead.table.size)
                              SEQ
                                j:=0
                            TRUE
                              SEQ
                                SKIP
                  TRUE
                    SEQ
                      SKIP

                --------------------------------------------------------------------------

                i:= (i+1) 
                IF
                  (i >lkahead.table.size)
                    SEQ
                      i:=0
                  TRUE
                    SEQ
                      SKIP
            IF
              invalid.lookahead.table[invalid.lkahead.table.base][1] <> NO.LIMIT
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  INVALID TABLE update.limits lookahead table not empty, limit is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][1]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  INVALID TABLE instruction is , limit is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][6]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  INVALID TABLE which.limit.  is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][4]),0,0,0] )
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  INVALID TABLE cycles is ",[(invalid.lookahead.table[invalid.lkahead.table.base][3]),0,0,0] )
                  limit.exists:=TRUE
              invalid.lookahead.table[invalid.lkahead.table.base][1] = NO.LIMIT
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  INVALID TABLE lookahead table not empty, no limit  ",NULL1)
                  
                  SKIP
        invalid.lookahead.table.empty=TRUE
          SEQ
            
            SKIP

  :
  -----------------------------------------------------------------------------
  PROC rpcpipe()

    [MESGLEN]INT ack:
    
    SEQ
      PCtemp:=Data

      IF 
        term =FALSE  --term is always FALSE
          -----------------------------------------------------------------------
          SEQ
            IF
              pcparchanged=FALSE          --ignore the first after the parity change
                SEQ
                  Data[TIME.STAMP]:=clock0 + delay[12]  --CALL+CALL
                  Ctrl[TIME.STAMP]:=clock0 + delay[12]  --CALL+CALL
                  Data[STALL]:=(-1)
                  mkpcc()                 -- make PCc
                  PAR                     -- to/from the register
                    MA!Data
                    MAc!Ctrl
                  MAa? ack
                  ------------------------------------*update lookahead table*
                  IF
                    preemption=PREEMPTION.OFF
                      SEQ

                        IF
                          ((ack[IS.INSTR]) /\ 2) <>0  --this is an instruction ack
                            SEQ

                              calculate.instr.cycles(ack)
                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rpcpipe appending ack: ",ack)
                              update.lookahead.table(VALID.TABLE, APPEND, ack)

                          ((ack[IS.INSTR]) /\ 2) = 0
                            SEQ
                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rpcpipe NOT appending ack: ",ack)

                              SKIP
                        -----------------------------------------
                        IF
                          (Opc=TRUE)  --this is an instruction fetch
                            SEQ
                              update.limits()
                              --num.of.PCs:=num.of.PCs + 1
                          TRUE
                            SEQ
                              SKIP  
                        -----------------------------------------                                 

                    preemption=PREEMPTION.ON
                      SEQ
                        SKIP
                  ------------------------------------
                  IF 
                    ack[0]=FINISH
                      SEQ
                        debugmsg(report,screen, "ADDINT-AddC: rpcpipe() Ack FINISH received",ack)
                        debugmsg(report,screen, "ADDINT-AddC: occupancy [1] is", [(occupancy.table[0][0][2]),0,0,0])

                        terminate(evaluate, ack[TIME.IN],NO.KILL, FLUSH, occupancy.table, screen, [MA])
                        debugmsg(report,screen, "ADDINT-AddC: occupancy [1] is", [(occupancy.table[0][0][2]),0,0,0])

                        ack[0]:=0
                        --term:=TRUE
                    TRUE
                      SKIP
                  -------------------------------------

                  debugmsg(report,screen, "ADDINT-AddC: For Address sent to memory", Data)
                  debugmsg(report,screen, "ADDINT-AddC: ack has been received from memory", ack)

                  clock0:=ack[TIME.STAMP]+delay[13]  --CALL+CALL+XOR                  
              TRUE
                SEQ
                  clock0:=clock0+delay[14]   --XOR
                  debugmsg(report,screen, "ADDINT-AddC: reject PC after pcpar changed ", Data)
                  pcparchanged:=FALSE
        term =TRUE
          -----------------------------------------------------------------------
          SEQ            --sink Xption addresses after finish.ack has been received
            SKIP   

      SEQ
        IF
          first=FALSE
            -------------------------------------------------------
            SEQ  
              ack[TIME.STAMP]:=clock0
              debugmsg(report,screen, "ADDINT-AddC: clock0 is", [clock0,0,0,0])
              debugmsg(report,screen, "ADDINT-AddC: Pcdata.occ is", Pcdata.occ)
              debugmsg(report,screen, "ADDINT-AddC: occupancy [1] is", [(occupancy.table[0][0][2]),0,0,0])
              debugmsg(report,screen, "ADDINT-AddC: waiting to send ack to pca for PC", Data)
              Pca!ack                   -- to the pcreg pipe
              debugmsg(report,screen, "ADDINT-AddC: send ack to pca for PC", Data)         
              calculate.occupancy(evaluate, occupancy.table[0], clock0, Pcdata.occ) 
          first=TRUE
            -------------------------------------------------------  do not acknowledge address 0!!!
            SEQ   
              first:=FALSE    
  :
  --------------------------------------------------------------------------

  PROC mkwac()

    SEQ
      int.to.bool(Ctrl[0],Ctrlb)
      lsmpc:=(Ctrlb[8] AND dPc)
      dPCc:=(lsmpc OR Ctrlb[1])
      Ctrl1b[0]:=Ctrlb[0]
      Ctrl1b[1]:=dPCc
      [Ctrl1b FROM 2 FOR 6]:=[Ctrlb FROM 2 FOR 6]
      LSin:=(Ctrlb[8] AND Ntrm)
      ToInc:=(LSin OR  Ctrlb[3])
      Ctrl1b[8]:=ToInc
      Ctrl1b[9]:=VSS
      init.hex(Ctrl[0], Ctrl1b)

      int.to.bool(Ctrl[0], Ctrlb)      
      Wen:=Ctrlb[7]
      Ren:=Ctrlb[6]
      Opc:=Ctrlb[3]

      ---initial implementation follows.....
      --get.bit(OPC, Ctrl[0],Opc)
      --get.bit(WEN, Ctrl[0],Wen)
      --get.bit(REN, Ctrl[0],Ren)      
      --set.bit(LSM, INT ((Opc OR (Lsm AND Ntrm))), Ctrl[0]) 
      --set.bit(SP, IVSS, Ctrl[0])  --Lsm  is 1 anyway
  : 


  ----------------------------------------------------------------------------
 
  PROC rwbus()
  
    [MESGLEN]INT ack,ackw: 
     
    SEQ
      mkwac()                         --make Wctrl 
      Data[TIME.STAMP]:=clock0
      Data[STALL]:=(-1)

      PAR                            --to/from register
        MA!Data
        MAc!Ctrl
      MAa? ack
      debugmsg(report,screen, "ADDINT-AddC: wbus() Ctrl is ",Ctrl)

      ------------------------------------*update lookahead table*
      IF
        preemption=PREEMPTION.OFF
          SEQ
            IF
              ((ack[IS.INSTR]) /\ 2) <>0
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rwbus appending ack: ",ack)
                  calculate.instr.cycles(ack)
                  

                  update.lookahead.table(VALID.TABLE, APPEND, ack)
              ((ack[IS.INSTR]) /\ 2) = 0
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rwbus NOT appending ack: ",ack)

                  SKIP
            -----------------------------------------
            IF
              (Opc=TRUE)   --this is an instruction fetch
                SEQ
                  update.limits()
                  --num.of.PCs:=num.of.PCs + 1
              TRUE
                SEQ
                  SKIP  
            -----------------------------------------                                 


        preemption=PREEMPTION.ON
          SEQ
            SKIP

      ------------------------------------
      IF 
        ack[0]=FINISH
          SEQ
            debugmsg(report,screen, "ADDINT-AddC: wbus() Ack FINISH received",NULL1)
            terminate(evaluate, ack[TIME.IN],NO.KILL, NO.FLUSH, occupancy.table, screen, [MA])
            --term:=TRUE
        TRUE
          SKIP
      -------------------------------------
 
      ackw[TIME.STAMP]:=  ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
      ack[TIME.STAMP]:=ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
      calculate.occupancy(evaluate, occupancy.table[4], ack[TIME.STAMP], Wdata.occ)  

      PAR            
        Wa!ack                      --to the wbus(wregister)
        WLx!ackw                    --to write-control             
  :
  -----------------------------------------------------------------------
  PROC rapipe() 

    [MESGLEN]INT  ack, ack1,ackw,Apipedata.occ:
    SEQ
      fromapipe? Data        --from apipe
      mkwac() 
      Apipedata.occ:=Data
                             --make Actrl 
      Data[TIME.STAMP]:= max(clock0, Data[TIME.STAMP]) +delay[4]  --MULLERC+CALL+CALL  
      Data[STALL]:=(-1)
                  
      PAR                            --to/from the register
        MA!Data
        MAc!Ctrl
      MAa? ack
                
      ------------------------------------*update lookahead table*
      IF
        preemption=PREEMPTION.OFF
          SEQ
            
            IF
              ((ack[IS.INSTR]) /\ 2) <> 0    --[pcpar, instruction]  0 1
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rapipe appending ack: ",ack)
                  calculate.instr.cycles(ack)
                  update.lookahead.table(VALID.TABLE, APPEND, ack)
              ((ack[IS.INSTR]) /\ 2) = 0
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF rapipe NOT appending ack: ",ack)

                  SKIP
            -----------------------------------------
            IF
              (Opc=TRUE)   --this is an instruction fetch
                SEQ
                  update.limits()
                  --num.of.PCs:=num.of.PCs + 1
              TRUE
                SEQ
                  SKIP  
            -----------------------------------------                                 

        preemption=PREEMPTION.ON
          SEQ
            SKIP

      ------------------------------------

      ack1[TIME.STAMP]:= ack[TIME.STAMP] +delay[5] --CALL+CALL
      ackw[TIME.STAMP]:=  ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
      ack[TIME.STAMP]:=ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
      clock0:=ackw[TIME.STAMP]
      calculate.occupancy(evaluate, occupancy.table[2], ack1[TIME.STAMP], Apipedata.occ)  
      calculate.occupancy(evaluate, occupancy.table[4], ack[TIME.STAMP], Wdata.occ)  

      PAR
        Wa!ack                    -- to the wbus for the Wc
        WLx!ackw
        APa!ack1                   -- to the apipe
  :        
  -----------------------------------------------------------------------
  PROC mklsc()

    SEQ
      
      init.hex(Ctrl[0], [PCpar,dPc, VDD, VSS, VSS,Nusr, Ren,Wen ,Ntrm, VDD])
      int.to.bool(Ctrl[0], Ctrlb)      
      Wen:=Ctrlb[7]
      Ren:=Ctrlb[6]
      Opc:=Ctrlb[3]
  :
  --------------------------------------------------------------------------

  PROC rlsmreg()

    [MESGLEN]INT  Dec1ctrl, ack, ack1,ack2,ackw,Lsmdata.occ :
 
    SEQ
      SEQ
        SEQ
      
          debugmsg(report,screen, "ADDINT-AddC: rlsmreg waiting  from Dec1",NULL1)
          LSMP? Dec1ctrl    --control from Dec1/includes Ntrm, dPc
          debugmsg(report,screen, "ADDINT-AddC rlsmreg received from Dec1",NULL1)
          int.to.bool(Dec1ctrl[0],Dec1ctrlb)
          Ntrm:=Dec1ctrlb[0]
          dPc:=Dec1ctrlb[1]

          mkwac()                 --use the above two values
          debugmsg(report,screen, "ADDINT-AddC rlsmreg waiting to send to MA",NULL1)
          Data[TIME.STAMP]:=max(clock0, Dec1ctrl[TIME.STAMP]) + delay[8]  --MULLERC+CALL+CALL
          Data[STALL]:=(-1)

          PAR
            MA!Data
            MAc!Ctrl
          debugmsg(report,screen, "ADDINT-AddC rlsmreg sent to MA",NULL1)
          debugmsg(report,screen, "ADDINT-AddC rlsmreg waiting for ack from MA",NULL1)
          MAa?  ack

          debugmsg(report,screen, "ADDINT-AddC rlsmreg received ack from MA",NULL1)
          debugmsg(report,screen, "ADDINT-AddC rlsmreg waiting to send LSMPa",NULL1)
          clock0:=ack[TIME.STAMP]
          ackw[TIME.STAMP]:=ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
          ack[TIME.STAMP]:=ack[TIME.STAMP] +delay[6] -- CALL+CALL+XOR+XOR
          calculate.occupancy(evaluate, occupancy.table[4], ack[TIME.STAMP], Wdata.occ) 
          ------------------------------------*update lookahead table*
          IF
            preemption=PREEMPTION.OFF
              SEQ
            
                IF
                  ((ack[IS.INSTR]) /\ 2) <> 0    --[pcpar, instruction]  0 1
                    SEQ
                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lsmreg appending ack: ",ack)
                      calculate.instr.cycles(ack)
                      update.lookahead.table(VALID.TABLE, APPEND, ack)
                  ((ack[IS.INSTR]) /\ 2) = 0
                    SEQ
                      debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lsmreg NOT appending ack: ",ack)

                      SKIP
                -----------------------------------------
                IF
                  (Opc=TRUE)   --this is an instruction fetch
                    SEQ
                      update.limits()
                      --num.of.PCs:=num.of.PCs + 1
                  TRUE
                    SEQ
                      SKIP  
 

          SEQ
            PAR
              Wa!ack     --send ack to WrtCtrl
              WLx!ackw
          clock0:=clock0 +delay[9] --CALL+CALL+SELECT+SELECT+XOR+XOR
          ack[TIME.STAMP]:=clock0
          calculate.occupancy(evaluate, occupancy.table[3], ack[TIME.STAMP],Dec1ctrl )  

          LSMPa!ack  --send ack to Dec1
          debugmsg(report,screen, "ADDINT-AddC rlsmreg sent LSMPa",NULL1)
          WHILE Ntrm=TRUE
            SEQ
              debugmsg(report,screen, "ADDINT-AddC: rlsmreg wait from Dec1-lsmreg",NULL1)
              PAR   
                fromlsreg? Data
                LSMP? Dec1ctrl
              Lsmdata.occ:=Data
              clock0:=max(clock0, Data[TIME.STAMP]) + delay[10]  --MULLERC + XOR
              clock0:=max(clock0, Dec1ctrl[TIME.STAMP]) + delay[11]  --MULLERC+CALL+CALL  
              debugmsg(report,screen, "ADDINT-AddC: rlsmreg received Dec1/lsmreg",NULL1)
              int.to.bool(Dec1ctrl[0],Dec1ctrlb)
              Ntrm:=Dec1ctrlb[0]
              dPc:=Dec1ctrlb[1]

              mklsc()               --use the above two values
              debugmsg(report,screen, "ADDINT-AddC rlsmreg waiting to send to MA",NULL1)
              Data[TIME.STAMP]:=clock0
              Data[STALL]:=(-1)
              PAR
                MA!Data
                MAc!Ctrl
              debugmsg(report,screen, "ADDINT-AddC rlsmreg sent to MA",NULL1)
              debugmsg(report,screen, "ADDINT-AddC rlsmreg waiting for ack from MA",NULL1)
              MAa? ack
              ------------------------------------*update lookahead table*
              IF
                preemption=PREEMPTION.OFF
                  SEQ
            
                    IF
                      ((ack[IS.INSTR]) /\ 2) <> 0    --[pcpar, instruction]  0 1
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lsmreg appending ack: ",ack)
                          calculate.instr.cycles(ack)
                          update.lookahead.table(VALID.TABLE, APPEND, ack)
                      ((ack[IS.INSTR]) /\ 2) = 0
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lsmreg NOT appending ack: ",ack)

                          SKIP
                    -----------------------------------------
                    IF
                      (Opc=TRUE)   --this is an instruction fetch
                        SEQ
                          update.limits()
                          --num.of.PCs:=num.of.PCs + 1
                      TRUE
                        SEQ
                          SKIP  


                preemption=PREEMPTION.ON
                  SEQ
                    SKIP

              ------------------------------------

              debugmsg(report,screen, "ADDINT-AddC rlsmreg rec ack from MA",NULL1)
              debugmsg(report,screen, "ADDINT-AddC rlsmreg wait to send LSMPa/LSMa",NULL1)
              clock0:=ack[TIME.STAMP]
              clock0:=clock0 +delay[9] --CALL+CALL+SELECT+SELECT+XOR+XOR
              ack[TIME.STAMP]:=clock0
              ack1[TIME.STAMP]:=clock0

              calculate.occupancy(evaluate, occupancy.table[1], ack[TIME.STAMP], Lsmdata.occ)  
              calculate.occupancy(evaluate, occupancy.table[3], ack1[TIME.STAMP],Dec1ctrl )  

              --LSMPa!ack  --send ack to Dec1  --*******************

              PAR
                LSMa!ack
                LSMPa!ack1
              debugmsg(report,screen, "ADDINT-AddC rlsmreg sent LSMPa and LSMa",NULL1)

          --debugmsg(report,screen, "ADDINT-AddC waiting to send to Wa and WLx",NULL1)
          --PAR
            --Wa!ack
           -- WLx!ackw
          --debugmsg(report,screen, "ADDINT-AddC  sent to Wa and WLx",NULL1)
  :
  -----------------------------------------------------------------------
    --***************************************************************
    --          ADDINT-ADDC: the following piece of code implements
    --          the program driven algorithm and should replace the
    --          ALT statement in the AddIn-AddC process of OCCARM
    --***************************************************************

  PROC AddC.preempt()


    --------------------------------------------------------------------------------

    PROC  W.bus()
      SEQ
        check.for.preemption(WB, PCtemp, clock0, process.id,report, clock0,
               previous.report, preempt.frequency,preempt.magnitude,msgnum, accum.preempt,screen, found)

        IF
          found=TRUE
            SEQ
              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION FOUND!!!!  Wbus", WB)

          found=FALSE
            SEQ
              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION NOT FOUND!!!!  Wbus", WB)

                         



        Wdata.occ:=WB
        Data:=WB
        clock0:=Data[TIME.STAMP]

        IF
          Data[0]<>FINISH
            SEQ
              Wc? Ctrl
               

              int.to.bool(Ctrl[0], Ctrlb)
              Sp:=Ctrlb[9]
              Lsm:=Ctrlb[8]
              Nusr:=Ctrlb[5]      -- they will be part of pcc
              oldPCpar:=PCpar
              PCpar:= Ctrlb[0]
              valid:=Ctrlb[2]
              -------------------------------------------DELETE CORRESPONDING ENTRIES
              IF
                valid=FALSE    --LDR discarded in ALU      --delete 2 entries!
                  ----------------------------------------------------------------
                  SEQ
                    IF
                      invalid.lookahead.table.empty=TRUE
                        SEQ
                          invalid.table.updated:=FALSE
                          update.lookahead.table(VALID.TABLE,DELETE, NULL1)
                      invalid.lookahead.table.empty=FALSE
                        SEQ
                          invalid.table.updated:=TRUE
                          update.lookahead.table(INVALID.TABLE,DELETE, NULL1)



                valid=TRUE    --LDR/M  discarded in ALU   
                  ----------------------------------------------------------------
                  SEQ
                    IF
                      (((((lookahead.table[lkahead.table.base][6]) /\  #0C000000) = #04000000)   AND ((((lookahead.table[lkahead.table.base][6]) /\  #00100000) = #00100000)  AND  (((lookahead.table[lkahead.table.base][6]) /\  #0000F000) = #0000F000)))  OR   ((((lookahead.table[lkahead.table.base][6]) /\  #0E000000) = #08000000)   AND  ((((lookahead.table[lkahead.table.base][6]) /\  #00100000) = #00100000)   AND   (((lookahead.table[lkahead.table.base][6]) /\  #00008000) = #00008000))))  
                        SEQ
                          ldr.or.ldm.r15:=TRUE
                      TRUE
                        SEQ
                          ldr.or.ldm.r15:=FALSE

                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)

              ------------------------------------------UPDATE CORRESPONDING TABLES AND LIMITS
              IF
                (valid=FALSE) AND (invalid.table.updated=TRUE) 
                  SEQ
                    SKIP
                TRUE                     
                  SEQ  
                    ----------------------- 
                    IF
                      ldr.or.ldm.r15=TRUE
                        SEQ
                          update.lookahead.table(VALID.TABLE,DELETE, NULL1)
                      ldr.or.ldm.r15=FALSE
                        SEQ
                          SKIP
                                 
                    limit.exists:=FALSE
                    IF                           --ckeck if the pc parity has changed
                      oldPCpar<>PCpar
                        SEQ
                          pcparchanged:=TRUE
                          -----------------------go on and delete relevant entries in the lookahead table

                          WHILE ((lookahead.table.empty=FALSE) AND ((lookahead.table[lkahead.table.base][2]) = (INT oldPCpar)))
                            SEQ
                              debugmsg(report,screen, "ADDINT-AddC: deleting lkahead table entries for discarded instructions....", Data)
                              ------------------------create invalid lookahead table???
                              IF
                                ((((((lookahead.table[lkahead.table.base][6]) /\  #0C000000) = #04000000)) OR  ((((lookahead.table[lkahead.table.base][6]) /\  #0E000000) = #08000000))) )  --LDR/M  STR/M
                                  SEQ
                                    debugmsg(report,screen, "ADDINT-AddC: inserting into INVALID TABLE ",[lookahead.table[lkahead.table.base][6], 0,0,0])
                                    IF
                                      ((((lookahead.table[lkahead.table.base][6]) /\  #0C000000) = #04000000)   AND  (((lookahead.table[lkahead.table.base][6]) /\  #00100000) = #00100000))  --ldr 
                                        SEQ
                                          append.invalid.lookahead.table()
                                          limit.exists:=FALSE
                                      TRUE
                                        SKIP
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)  --first entry
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)  --second entry
                                    


                                ((lookahead.table[lkahead.table.base][0]=(-1)))
                                  SEQ
                                    debugmsg(report,screen, "ADDINT-AddC: inserting into INVALID TABLE ",[lookahead.table[lkahead.table.base][6], 0,0,0])

                                    append.invalid.lookahead.table()
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)  --first entry 

                         
                                TRUE
                                  SEQ
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)  --just one entry
                      TRUE      
                        SKIP
                    -------------------------------------------
                    IF
                      ldr.or.ldm.r15=TRUE
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: ldr.or.ldm.r15=TRUE  appending to lookahead table", Data)
                          limit.exists:=TRUE
                          update.lookahead.table(VALID.TABLE,APPEND, [0,0,0,0])
                          ldr.or.ldm.r15:=FALSE
                      ldr.or.ldm.r15=FALSE
                        SEQ
                          debugmsg(report,screen, "ADDINT-AddC: ldr.or.ldm.r15=FALSE  NOT appending to lookahead table", Data)


              -------------------------------------------

              clock0:=clock0+delay[1] --ARBITER+SELECT
              IF
                ((Sp=TRUE) AND (Lsm=FALSE))
                  SEQ
                    debugmsg(report,screen, "ADDINT-AddC: call rapipe ", Data)
                    clock0:=clock0+delay[2]  --SELECT
                    rapipe()
                (Sp=FALSE)
                  SEQ
                    debugmsg(report,screen, "ADDINT-AddC: call rwbus ", Data)
                    clock0:=clock0+ delay[3]  --CALL+CALL

                    rwbus()
                ((Sp=TRUE) AND (Lsm=TRUE))
                  SEQ
                    clock0:=clock0+delay[7]  --SELECT+XOR
                    debugmsg(report,screen, "ADDINT-AddC: call rlsmreg ", Data)
                    rlsmreg()
          
          TRUE
            end:=TRUE
    :
    -----------------------------------------------------------------
    SEQ
      IF
        PC.received=FALSE
          SEQ
            IF
              (limit.exists=FALSE)
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=FALSE waiting for data from pcpipe ",NULL1)
                  frompcpipe? Data
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=FALSE received data from pcpipe ",Data)

                  Pcdata.occ:=Data
                  PCr:=Data
                  clock0:=Data[TIME.STAMP] + delay[0] --XOR+ARBITER+SELECT
                  debugmsg(report,screen, "ADDINT-AddC: Address received from PCpipe ", Data)
                  PC.received:=TRUE

              (limit.exists=TRUE)
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=FALSE ,limit.exists AND num.of.PCs=limit ",NULL1)

                  SKIP
        TRUE
          SEQ
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=TRUE ",NULL1)

            SKIP
      IF
        ((lookahead.table.empty=TRUE) AND (invalid.lookahead.table.empty=TRUE))
          SEQ
            IF
              PC.received=TRUE
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=TRUE calling rpcpipe ",NULL1)
                  Data:=Pcdata.occ
                  check.for.preemption(Data, Wdata.occ, clock0, process.id,report,clock0,
                  previous.report, preempt.frequency,preempt.magnitude, msgnum, accum.preempt, screen,found)
                  IF
                    found=TRUE
                      SEQ
                        debugmsg(report,screen, "ADDINT-AddC: PREEMPTION FOUND!!!!  PC pipe", Data)

                    found=FALSE
                      SEQ
                        debugmsg(report,screen, "ADDINT-AddC: PREEMPTION NOT FOUND!!!!  PC pipe", Data)

                  rpcpipe()
                  PC.received:=FALSE
              TRUE
                SKIP

        ((lookahead.table.empty=FALSE) OR (invalid.lookahead.table.empty=FALSE))
          SEQ
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  lookahead.table.empty= ", [(INT lookahead.table.empty), 0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  instruction is  ",[(lookahead.table[lkahead.table.base][6]),0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  lookahead time is   ",[(lookahead.table[lkahead.table.base][lat.lookahead]),0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  minimum limit is is   ",[(lookahead.table[lkahead.table.base][5]),0,0,0])


            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  invalid.lookahead.table.empty=FALSE ", [(INT invalid.lookahead.table.empty), 0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  instruction is  ",[(invalid.lookahead.table[invalid.lkahead.table.base][6]),0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  invalid.lookahead time is   ",[(invalid.lookahead.table[invalid.lkahead.table.base][lat.lookahead]),0,0,0])
            debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  invalid.minimum limit is is   ",[(invalid.lookahead.table[invalid.lkahead.table.base][5]),0,0,0])

            IF
              PC.received=TRUE
                SEQ
                  debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF PC.received=TRUE ",NULL1)

                  IF


                    (((lookahead.table.empty=TRUE) OR ((lookahead.table.empty=FALSE) AND ((lookahead.table[lkahead.table.base][lat.lookahead]  >= PCr[TIME.STAMP]) OR (lookahead.table[lkahead.table.base][5]< MIN.LIMIT))))  AND ((invalid.lookahead.table.empty=TRUE) OR ((invalid.lookahead.table.empty=FALSE) AND ((invalid.lookahead.table[invalid.lkahead.table.base][lat.lookahead]  >= PCr[TIME.STAMP]) OR (invalid.lookahead.table[invalid.lkahead.table.base][5]< MIN.LIMIT)))))



                      SEQ
                        Data:=Pcdata.occ

                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  queue timestamp > PC-timestamp",NULL1)
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF lookahead.table[lkahead.table.base][5] IS ",[lookahead.table[lkahead.table.base][5],0,0,0])
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  calling rpcpipe",NULL1)
                        check.for.preemption(Data, Wdata.occ, clock0, process.id,report,clock0,
                        previous.report, preempt.frequency,preempt.magnitude, msgnum, accum.preempt, screen,found)
                        IF
                          found=TRUE
                            SEQ
                              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION FOUND!!!!  PC pipe", Data)

                          found=FALSE
                            SEQ
                              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION NOT FOUND!!!!  PC pipe", Data)


                        rpcpipe()
                        PC.received:=FALSE

                    TRUE
                      --((lookahead.table[lkahead.table.base][lat.lookahead] < PCr[TIME.STAMP]) AND ((lookahead.table[lkahead.table.base][5] >= MIN.LIMIT)))   
                      SEQ
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  queue timestamp < PC-timestamp",NULL1)
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  waiting for data from Wbus",NULL1)
                        W?Data   --read from WriteCtrl
                        --num.of.PCs:=0
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  received data from Wbus",Data)

                        WB:=Data

                        IF
                          WB[0]=NULL.MESSAGE
                            SEQ
                              Wc? Ctrl

                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  Data was NULL.MESSAGE", Data)
                              IF
                                invalid.lookahead.table.empty=TRUE  --this NULL message has been sent by the ALU
                                  SEQ
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)
                                invalid.lookahead.table.empty=FALSE  --this NULL message has been sent by Dec1CtrlB
                                  SEQ
                                    update.lookahead.table(INVALID.TABLE,DELETE, NULL1)
                              PAR            
                                Wa!null.ack                      --to the wbus(wregister)
                                WLx!null.ack                    --to write-control             

                          WB[0]<>NULL.MESSAGE
                            SEQ
                              IF
                                WB[TIME.STAMP] <=PCr[TIME.STAMP]
                                  SEQ

                                    --num.of.PCs:=0
                                    --------------process WB
                                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  WB[TIME.STAMP] <=PCr[TIME.STAMP]", Data)
                                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  calling W.bus", Data)

                                    W.bus()
                                    WB.received:=FALSE

                                WB[TIME.STAMP] > PCr[TIME.STAMP]
                                  
                                  SEQ
                                    limit.exit:=FALSE
                                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  WB[TIME.STAMP] > PCr[TIME.STAMP", WB)

                                    WHILE (((WB[TIME.STAMP]) > (PCr[TIME.STAMP])) AND (limit.exit=FALSE))
                                      SEQ
                                    
                                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  WB is ", WB)
                                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  WB[TIME.STAMP] > PCr[TIME.STAMP]", PCr)
                                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  calling rpcpipe", Data)
                                        Data:=Pcdata.occ
                                        check.for.preemption(Data, Wdata.occ, clock0, process.id,report,clock0,
                                        previous.report, preempt.frequency,preempt.magnitude, msgnum, accum.preempt, screen,found)
                                        IF
                                          found=TRUE
                                            SEQ
                                              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION FOUND!!!!  PC pipe", Data)

                                          found=FALSE
                                            SEQ
                                              debugmsg(report,screen, "ADDINT-AddC: PREEMPTION NOT FOUND!!!!  PC pipe", Data)


                                        rpcpipe()
                                        PC.received:=FALSE
                                        IF
                                          (limit.exists=TRUE)

                                            SEQ
                                              debugmsg(report,screen, "ADDINT-AddC: LIMIT REACHED  EXITING WHILE LOOP....", WB)

                                              limit.exit:=TRUE
                                              SKIP
                                          TRUE
                                            SEQ
                                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF waiting for data from PCpipe ", NULL1)

                                              frompcpipe? Data
                                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF received for data from PCpipe ", Data)

                                              Pcdata.occ:=Data
                                              PCr:=Data
                                              clock0:=Data[TIME.STAMP] + delay[0] --XOR+ARBITER+SELECT
                                              debugmsg(report,screen, "ADDINT-AddC: Address received from PCpipe ", Data)
                                              PC.received:=TRUE

                                    --------------process WB
                                    debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  exiting WHILE LOOP  ", WB)

                                    W.bus()


    
              PC.received=FALSE
                SEQ
                  IF
                    ((limit.exists=TRUE))
                      SEQ
                        debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  waiting for data from Wbus",NULL1)


                        W?Data   --read from WriteCtrl
                                                --num.of.PCs:=0
                        WB:=Data

                        IF
                          WB[0]=NULL.MESSAGE
                            SEQ
                              Wc? Ctrl
                              debugmsg(report,screen, "ADDINT-AddC: PRMPT OFF  Data was NULL.MESSAGE", Data)
                              IF
                                invalid.lookahead.table.empty=TRUE  --this NULL message has been sent by the ALU
                                  SEQ
                                    update.lookahead.table(VALID.TABLE,DELETE, NULL1)
                                invalid.lookahead.table.empty=FALSE  --this NULL message has been sent by Dec1CtrlB
                                  SEQ
                                    update.lookahead.table(INVALID.TABLE,DELETE, NULL1)

                              PAR  
                                          
                                Wa!null.ack                      --to the wbus(wregister)
                                WLx!null.ack                   --to write-control             

                          WB[0]<>NULL.MESSAGE
                            SEQ
                              WB:=Data

                              --------------process WB
                              W.bus()
                              WB.received:=FALSE

                    TRUE
                      SKIP

  :
  ------------------------------------------------------------------   
  SEQ
    end:=FALSE
    oldPCpar:=FALSE
    PCpar:=FALSE
    Nusr:=FALSE
    Sp:=FALSE
    Lsm:=FALSE
    Opc:=FALSE
    Ntrm:=FALSE
    dPc:=FALSE
    Wen:=FALSE
    Ren:=FALSE
    lsmpc:=FALSE
    dPCc:=FALSE
    ToInc:=FALSE
    LSin:=FALSE
    term:=FALSE
    pcparchanged:=FALSE
    --------------------------
    limit.exists:=FALSE
    PC.received:=FALSE
    PCs.OK:=FALSE
    num.of.PCs:=0
    lkahead.table.top, lkahead.table.base,contents:=0,0,0
    lookahead.table.empty:=TRUE
    invalid.lkahead.table.top, invalid.lkahead.table.base,invalid.contents:=0,0,0
    invalid.lookahead.table.empty:=TRUE
    ----------------------------
    previous.report, preempt.frequency, preempt.magnitude,accum.preempt:=0,0,0,0
    msgnum:=0
    calculate.delays()

    initialize.occup.tables()
    Wdata.occ:=[0,0,0,0]
    Pcdata.occ:=[0,0,0,0]   --initialy
    clock0:=0
    ack[0]:=0
    null.ack:=[0,0,0,0]
    first:=TRUE

    WHILE NOT end
      SEQ
        IF
          preemption=PREEMPTION.ON
            --------------------------------------------------------------------------------------      
            SEQ
              
              ALT
                W?Data   --read from WriteCtrl
                  SEQ
                    clock?time
                    check.for.preemption(Data, Pcdata.occ, clock0, process.id,report, clock0,
                    previous.report, preempt.frequency,preempt.magnitude,msgnum, accum.preempt,screen, found)


                    Wdata.occ:=Data
                    IF
                      found=FALSE
                        SEQ
                          clock0:=Data[TIME.STAMP]
                      found=TRUE
                        SEQ
                          SKIP

                    debugmsg(report,screen, "ADDINT-AddC: Address received from WriteCtrl ", Data)
                    IF
                      Data[0]<>FINISH
                        SEQ
                          Wc? Ctrl
                          int.to.bool(Ctrl[0], Ctrlb)
                          Sp:=Ctrlb[9]
                          Lsm:=Ctrlb[8]
                          Nusr:=Ctrlb[5]      -- they will be part of pcc
                          oldPCpar:=PCpar
                          PCpar:= Ctrlb[0]                             
     
                          IF                           --ckeck if the pc parity has changed
                            oldPCpar<>PCpar
                              SEQ
                                pcparchanged:=TRUE   
                            TRUE
                              SKIP
                          IF
                            found=FALSE
                              SEQ
                                clock0:=clock0+delay[1] --ARBITER+SELECT
                            found=TRUE
                              SEQ
                                SKIP
                          IF
                            ((Sp=TRUE) AND (Lsm=FALSE))
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: call rapipe ", Data)
                                clock0:=clock0+delay[2]  --SELECT
                                rapipe()
                            (Sp=FALSE)
                              SEQ
                                debugmsg(report,screen, "ADDINT-AddC: call rwbus ", Data)
                                IF
                                  found=FALSE
                                    SEQ
                                      clock0:=clock0+ delay[3]  --CALL+CALL
                                  found=TRUE
                                    SEQ
                                      SKIP

                                rwbus()
                            ((Sp=TRUE) AND (Lsm=TRUE))
                              SEQ
                                IF
                                  found=FALSE
                                    SEQ
                                      clock0:=clock0+delay[7]  --SELECT+XOR
                                  found=TRUE
                                    SEQ
                                      SKIP

                                debugmsg(report,screen, "ADDINT-AddC: call rlsmreg ", Data)
                                rlsmreg()
                      TRUE
                        end:=TRUE 
                frompcpipe? Data       --read from pc pipe
                  SEQ
                    clock?time
                    check.for.preemption(Data, Wdata.occ, clock0, process.id,report,clock0,
                    previous.report, preempt.frequency,preempt.magnitude, msgnum, accum.preempt, screen,found)

                    Pcdata.occ:=Data
                    IF
                      found=FALSE
                        SEQ
                          clock0:=Data[TIME.STAMP] + delay[0] --XOR+ARBITER+SELECT
                      found=TRUE
                        SEQ
                          SKIP


                    debugmsg(report,screen, "ADDINT-AddC: Address received from PCpipe ", Data)
                    rpcpipe()
 
            
          preemption=PREEMPTION.OFF
            --------------------------------------------------------------------------------------      
            SEQ
              SKIP  
              AddC.preempt() 

    --end sent back with ack from memory
    debugmsg(report,screen, "ADDINT-AddC: end has been received ", Data)

    terminate(evaluate, Data[TIME.STAMP],KILL, NO.FLUSH, occupancy.table, screen, [MA])
:




