Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.89 KB | None | 0 0
  1. #Alex Alvizo
  2. #netid: aalviz2
  3. #uin: 671629368
  4.  
  5. #--------#-----------------------------#---------------------------#
  6. #  Stage #           iaddl             #           leave           #
  7. #--------#-----------------------------#---------------------------#
  8. #        #                             #                           #
  9. #  Fetch #     icode:ifun <- M1[PC]    #     icode:ifun <- M1[PC]  #
  10. #        #  rA:rB <- M1[PC+1]          #        valP <- PC+1       #
  11. #        #  valC <- M4[PC+2]           #                           #
  12. #        #       valP <- PC+6          #                           #
  13. #        #                             #                           #
  14. #--------#-----------------------------#---------------------------#
  15. #        #                             #                           #
  16. # Decode #       valB <- R[rB]         #     valB <- R[%ebp]       #
  17. #        #                             #                           #
  18. #--------#-----------------------------#---------------------------#
  19. #        #                             #                           #
  20. # Excode #      valE <- valB+valC      #     valE <- valB + 4      #
  21. #        #           Set CC            #                           #
  22. #------- #---------------------------- #-------------------------- #
  23. #        #                             #                           #
  24. # Memory #                             #     valM <- M4[valB]      #
  25. #        #                             #                           #
  26. #--------#-----------------------------#---------------------------#
  27. #        #                             #                           #
  28. #  Write #       R[rB] <- valE         #     R[%esp] <- valE       #
  29. #  Back  #                             #     R[%ebp] <- valM       #
  30. #        #                             #                           #
  31. #--------#-----------------------------#---------------------------#
  32. #        #                             #                           #
  33. #   PC   #         PC <- valP          #       PC <- valP          #      
  34. # Update #                             #                           #
  35. #--------#-----------------------------#---------------------------#
  36.  
  37.  
  38. #/* $begin seq-all-hcl */
  39. ####################################################################
  40. #  HCL Description of Control for Single Cycle Y86 Processor SEQ   #
  41. #  Copyright (C) Randal E. Bryant, David R. O'Hallaron, 2010       #
  42. ####################################################################
  43.  
  44. ## Your task is to implement the iaddl and leave instructions
  45. ## The file contains a declaration of the icodes
  46. ## for iaddl (IIADDL) and leave (ILEAVE).
  47. ## Your job is to add the rest of the logic to make it work
  48.  
  49. ####################################################################
  50. #    C Include's.  Don't alter these                               #
  51. ####################################################################
  52.  
  53. quote '#include <stdio.h>'
  54. quote '#include "isa.h"'
  55. quote '#include "sim.h"'
  56. quote 'int sim_main(int argc, char *argv[]);'
  57. quote 'int gen_pc(){return 0;}'
  58. quote 'int main(int argc, char *argv[])'
  59. quote '  {plusmode=0;return sim_main(argc,argv);}'
  60.  
  61. ####################################################################
  62. #    Declarations.  Do not change/remove/delete any of these       #
  63. ####################################################################
  64.  
  65. ##### Symbolic representation of Y86 Instruction Codes #############
  66. intsig INOP     'I_NOP'
  67. intsig IHALT    'I_HALT'
  68. intsig IRRMOVL  'I_RRMOVL'
  69. intsig IIRMOVL  'I_IRMOVL'
  70. intsig IRMMOVL  'I_RMMOVL'
  71. intsig IMRMOVL  'I_MRMOVL'
  72. intsig IOPL 'I_ALU'
  73. intsig IJXX 'I_JMP'
  74. intsig ICALL    'I_CALL'
  75. intsig IRET 'I_RET'
  76. intsig IPUSHL   'I_PUSHL'
  77. intsig IPOPL    'I_POPL'
  78. # Instruction code for iaddl instruction
  79. intsig IIADDL   'I_IADDL'
  80. # Instruction code for leave instruction
  81. intsig ILEAVE   'I_LEAVE'
  82.  
  83. ##### Symbolic represenations of Y86 function codes                  #####
  84. intsig FNONE    'F_NONE'        # Default function code
  85.  
  86. ##### Symbolic representation of Y86 Registers referenced explicitly #####
  87. intsig RESP     'REG_ESP'       # Stack Pointer
  88. intsig REBP     'REG_EBP'       # Frame Pointer
  89. intsig RNONE    'REG_NONE'      # Special value indicating "no register"
  90.  
  91. ##### ALU Functions referenced explicitly                            #####
  92. intsig ALUADD   'A_ADD'     # ALU should add its arguments
  93.  
  94. ##### Possible instruction status values                             #####
  95. intsig SAOK 'STAT_AOK'      # Normal execution
  96. intsig SADR 'STAT_ADR'  # Invalid memory address
  97. intsig SINS 'STAT_INS'  # Invalid instruction
  98. intsig SHLT 'STAT_HLT'  # Halt instruction encountered
  99.  
  100. ##### Signals that can be referenced by control logic ####################
  101.  
  102. ##### Fetch stage inputs        #####
  103. intsig pc 'pc'              # Program counter
  104. ##### Fetch stage computations      #####
  105. intsig imem_icode 'imem_icode'      # icode field from instruction memory
  106. intsig imem_ifun  'imem_ifun'       # ifun field from instruction memory
  107. intsig icode      'icode'       # Instruction control code
  108. intsig ifun   'ifun'        # Instruction function
  109. intsig rA     'ra'          # rA field from instruction
  110. intsig rB     'rb'          # rB field from instruction
  111. intsig valC   'valc'        # Constant from instruction
  112. intsig valP   'valp'        # Address of following instruction
  113. boolsig imem_error 'imem_error'     # Error signal from instruction memory
  114. boolsig instr_valid 'instr_valid'   # Is fetched instruction valid?
  115.  
  116. ##### Decode stage computations     #####
  117. intsig valA 'vala'          # Value from register A port
  118. intsig valB 'valb'          # Value from register B port
  119.  
  120. ##### Execute stage computations    #####
  121. intsig valE 'vale'          # Value computed by ALU
  122. boolsig Cnd 'cond'          # Branch test
  123.  
  124. ##### Memory stage computations     #####
  125. intsig valM 'valm'          # Value read from memory
  126. boolsig dmem_error 'dmem_error'     # Error signal from data memory
  127.  
  128.  
  129. ####################################################################
  130. #    Control Signal Definitions.                                   #
  131. ####################################################################
  132.  
  133. ################ Fetch Stage     ###################################
  134.  
  135. # Determine instruction code
  136. int icode = [
  137.     imem_error: INOP;
  138.     1: imem_icode;      # Default: get from instruction memory
  139. ];
  140.  
  141. # Determine instruction function
  142. int ifun = [
  143.     imem_error: FNONE;
  144.     1: imem_ifun;       # Default: get from instruction memory
  145. ];
  146.  
  147. bool instr_valid = icode in
  148.     { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL,
  149.            IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL, IIADDL, ILEAVE };
  150.  
  151. # Does fetched instruction require a regid byte?
  152. bool need_regids =
  153.     icode in { IRRMOVL, IOPL, IPUSHL, IPOPL,
  154.              IIRMOVL, IRMMOVL, IMRMOVL, IIADDL };
  155.  
  156. # Does fetched instruction require a constant word?
  157. bool need_valC =
  158.     icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL, IIADDL };
  159.  
  160. ################ Decode Stage    ###################################
  161.  
  162. ## What register should be used as the A source?
  163. int srcA = [
  164.     icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA;
  165.     icode in { IPOPL, IRET } : RESP;
  166.     1 : RNONE; # Don't need register
  167. ];
  168.  
  169. ## What register should be used as the B source?
  170. int srcB = [
  171.     icode in { IOPL, IRMMOVL, IMRMOVL, IIADDL  } : rB;
  172.     icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP;
  173.     icode in { ILEAVE } : REBP;
  174.     1 : RNONE;  # Don't need register
  175. ];
  176.  
  177. ## What register should be used as the E destination?
  178. int dstE = [
  179.     icode in { IRRMOVL } && Cnd : rB;
  180.     icode in { IIRMOVL, IOPL, IIADDL} : rB;
  181.     icode in { IPUSHL, IPOPL, ICALL, IRET, ILEAVE} : RESP;
  182.     1 : RNONE;  # Don't write any register
  183. ];
  184.  
  185. ## What register should be used as the M destination?
  186. int dstM = [
  187.     icode in { IMRMOVL, IPOPL } : rA;
  188.     icode in { ILEAVE } : REBP;
  189.     1 : RNONE;  # Don't write any register
  190. ];
  191.  
  192. ################ Execute Stage   ###################################
  193.  
  194. ## Select input A to ALU
  195. int aluA = [
  196.     icode in { IRRMOVL, IOPL } : valA;
  197.     icode in { IIRMOVL, IRMMOVL, IMRMOVL, IIADDL } : valC;
  198.     icode in { ICALL, IPUSHL } : -4;
  199.     icode in { IRET, IPOPL, ILEAVE } : 4;
  200.     # Other instructions don't need ALU
  201. ];
  202.  
  203. ## Select input B to ALU
  204. int aluB = [
  205.     icode in { IRMMOVL, IMRMOVL, IOPL, ICALL,
  206.               IPUSHL, IRET, IPOPL, IIADDL, ILEAVE } : valB;
  207.     icode in { IRRMOVL, IIRMOVL } : 0;
  208.     # Other instructions don't need ALU
  209. ];
  210.  
  211. ## Set the ALU function
  212. int alufun = [
  213.     icode == IOPL : ifun;
  214.     1 : ALUADD;
  215. ];
  216.  
  217. ## Should the condition codes be updated?
  218. bool set_cc = icode in { IOPL, IIADDL };
  219.  
  220. ################ Memory Stage    ###################################
  221.  
  222. ## Set read control signal
  223. bool mem_read = icode in { IMRMOVL, IPOPL, IRET, ILEAVE};
  224.  
  225. ## Set write control signal
  226. bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };
  227.  
  228. ## Select memory address
  229. int mem_addr = [
  230.     icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL } : valE;
  231.     icode in { IPOPL, IRET } : valA;
  232.     icode in { ILEAVE } : valB;
  233.     # Other instructions don't need address
  234. ];
  235.  
  236. ## Select memory input data
  237. int mem_data = [
  238.     # Value from register
  239.     icode in { IRMMOVL, IPUSHL } : valA;
  240.     # Return PC
  241.     icode == ICALL : valP;
  242.     # Default: Don't write anything
  243. ];
  244.  
  245. ## Determine instruction status
  246. int Stat = [
  247.     imem_error || dmem_error : SADR;
  248.     !instr_valid: SINS;
  249.     icode == IHALT : SHLT;
  250.     1 : SAOK;
  251. ];
  252.  
  253. ################ Program Counter Update ############################
  254.  
  255. ## What address should instruction be fetched at
  256.  
  257. int new_pc = [
  258.     # Call.  Use instruction constant
  259.     icode == ICALL : valC;
  260.     # Taken branch.  Use instruction constant
  261.     icode == IJXX && Cnd : valC;
  262.     # Completion of RET instruction.  Use value from stack
  263.     icode == IRET : valM;
  264.     # Default: Use incremented PC
  265.     1 : valP;
  266. ];
  267. #/* $end seq-all-hcl */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement