Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Alex Alvizo
- #netid: aalviz2
- #uin: 671629368
- #--------#-----------------------------#---------------------------#
- # Stage # iaddl # leave #
- #--------#-----------------------------#---------------------------#
- # # # #
- # Fetch # icode:ifun <- M1[PC] # icode:ifun <- M1[PC] #
- # # rA:rB <- M1[PC+1] # valP <- PC+1 #
- # # valC <- M4[PC+2] # #
- # # valP <- PC+6 # #
- # # # #
- #--------#-----------------------------#---------------------------#
- # # # #
- # Decode # valB <- R[rB] # valB <- R[%ebp] #
- # # # #
- #--------#-----------------------------#---------------------------#
- # # # #
- # Excode # valE <- valB+valC # valE <- valB + 4 #
- # # Set CC # #
- #------- #---------------------------- #-------------------------- #
- # # # #
- # Memory # # valM <- M4[valB] #
- # # # #
- #--------#-----------------------------#---------------------------#
- # # # #
- # Write # R[rB] <- valE # R[%esp] <- valE #
- # Back # # R[%ebp] <- valM #
- # # # #
- #--------#-----------------------------#---------------------------#
- # # # #
- # PC # PC <- valP # PC <- valP #
- # Update # # #
- #--------#-----------------------------#---------------------------#
- #/* $begin seq-all-hcl */
- ####################################################################
- # HCL Description of Control for Single Cycle Y86 Processor SEQ #
- # Copyright (C) Randal E. Bryant, David R. O'Hallaron, 2010 #
- ####################################################################
- ## Your task is to implement the iaddl and leave instructions
- ## The file contains a declaration of the icodes
- ## for iaddl (IIADDL) and leave (ILEAVE).
- ## Your job is to add the rest of the logic to make it work
- ####################################################################
- # C Include's. Don't alter these #
- ####################################################################
- quote '#include <stdio.h>'
- quote '#include "isa.h"'
- quote '#include "sim.h"'
- quote 'int sim_main(int argc, char *argv[]);'
- quote 'int gen_pc(){return 0;}'
- quote 'int main(int argc, char *argv[])'
- quote ' {plusmode=0;return sim_main(argc,argv);}'
- ####################################################################
- # Declarations. Do not change/remove/delete any of these #
- ####################################################################
- ##### Symbolic representation of Y86 Instruction Codes #############
- intsig INOP 'I_NOP'
- intsig IHALT 'I_HALT'
- intsig IRRMOVL 'I_RRMOVL'
- intsig IIRMOVL 'I_IRMOVL'
- intsig IRMMOVL 'I_RMMOVL'
- intsig IMRMOVL 'I_MRMOVL'
- intsig IOPL 'I_ALU'
- intsig IJXX 'I_JMP'
- intsig ICALL 'I_CALL'
- intsig IRET 'I_RET'
- intsig IPUSHL 'I_PUSHL'
- intsig IPOPL 'I_POPL'
- # Instruction code for iaddl instruction
- intsig IIADDL 'I_IADDL'
- # Instruction code for leave instruction
- intsig ILEAVE 'I_LEAVE'
- ##### Symbolic represenations of Y86 function codes #####
- intsig FNONE 'F_NONE' # Default function code
- ##### Symbolic representation of Y86 Registers referenced explicitly #####
- intsig RESP 'REG_ESP' # Stack Pointer
- intsig REBP 'REG_EBP' # Frame Pointer
- intsig RNONE 'REG_NONE' # Special value indicating "no register"
- ##### ALU Functions referenced explicitly #####
- intsig ALUADD 'A_ADD' # ALU should add its arguments
- ##### Possible instruction status values #####
- intsig SAOK 'STAT_AOK' # Normal execution
- intsig SADR 'STAT_ADR' # Invalid memory address
- intsig SINS 'STAT_INS' # Invalid instruction
- intsig SHLT 'STAT_HLT' # Halt instruction encountered
- ##### Signals that can be referenced by control logic ####################
- ##### Fetch stage inputs #####
- intsig pc 'pc' # Program counter
- ##### Fetch stage computations #####
- intsig imem_icode 'imem_icode' # icode field from instruction memory
- intsig imem_ifun 'imem_ifun' # ifun field from instruction memory
- intsig icode 'icode' # Instruction control code
- intsig ifun 'ifun' # Instruction function
- intsig rA 'ra' # rA field from instruction
- intsig rB 'rb' # rB field from instruction
- intsig valC 'valc' # Constant from instruction
- intsig valP 'valp' # Address of following instruction
- boolsig imem_error 'imem_error' # Error signal from instruction memory
- boolsig instr_valid 'instr_valid' # Is fetched instruction valid?
- ##### Decode stage computations #####
- intsig valA 'vala' # Value from register A port
- intsig valB 'valb' # Value from register B port
- ##### Execute stage computations #####
- intsig valE 'vale' # Value computed by ALU
- boolsig Cnd 'cond' # Branch test
- ##### Memory stage computations #####
- intsig valM 'valm' # Value read from memory
- boolsig dmem_error 'dmem_error' # Error signal from data memory
- ####################################################################
- # Control Signal Definitions. #
- ####################################################################
- ################ Fetch Stage ###################################
- # Determine instruction code
- int icode = [
- imem_error: INOP;
- 1: imem_icode; # Default: get from instruction memory
- ];
- # Determine instruction function
- int ifun = [
- imem_error: FNONE;
- 1: imem_ifun; # Default: get from instruction memory
- ];
- bool instr_valid = icode in
- { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL,
- IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL, IIADDL, ILEAVE };
- # Does fetched instruction require a regid byte?
- bool need_regids =
- icode in { IRRMOVL, IOPL, IPUSHL, IPOPL,
- IIRMOVL, IRMMOVL, IMRMOVL, IIADDL };
- # Does fetched instruction require a constant word?
- bool need_valC =
- icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL, IIADDL };
- ################ Decode Stage ###################################
- ## What register should be used as the A source?
- int srcA = [
- icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA;
- icode in { IPOPL, IRET } : RESP;
- 1 : RNONE; # Don't need register
- ];
- ## What register should be used as the B source?
- int srcB = [
- icode in { IOPL, IRMMOVL, IMRMOVL, IIADDL } : rB;
- icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP;
- icode in { ILEAVE } : REBP;
- 1 : RNONE; # Don't need register
- ];
- ## What register should be used as the E destination?
- int dstE = [
- icode in { IRRMOVL } && Cnd : rB;
- icode in { IIRMOVL, IOPL, IIADDL} : rB;
- icode in { IPUSHL, IPOPL, ICALL, IRET, ILEAVE} : RESP;
- 1 : RNONE; # Don't write any register
- ];
- ## What register should be used as the M destination?
- int dstM = [
- icode in { IMRMOVL, IPOPL } : rA;
- icode in { ILEAVE } : REBP;
- 1 : RNONE; # Don't write any register
- ];
- ################ Execute Stage ###################################
- ## Select input A to ALU
- int aluA = [
- icode in { IRRMOVL, IOPL } : valA;
- icode in { IIRMOVL, IRMMOVL, IMRMOVL, IIADDL } : valC;
- icode in { ICALL, IPUSHL } : -4;
- icode in { IRET, IPOPL, ILEAVE } : 4;
- # Other instructions don't need ALU
- ];
- ## Select input B to ALU
- int aluB = [
- icode in { IRMMOVL, IMRMOVL, IOPL, ICALL,
- IPUSHL, IRET, IPOPL, IIADDL, ILEAVE } : valB;
- icode in { IRRMOVL, IIRMOVL } : 0;
- # Other instructions don't need ALU
- ];
- ## Set the ALU function
- int alufun = [
- icode == IOPL : ifun;
- 1 : ALUADD;
- ];
- ## Should the condition codes be updated?
- bool set_cc = icode in { IOPL, IIADDL };
- ################ Memory Stage ###################################
- ## Set read control signal
- bool mem_read = icode in { IMRMOVL, IPOPL, IRET, ILEAVE};
- ## Set write control signal
- bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };
- ## Select memory address
- int mem_addr = [
- icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL } : valE;
- icode in { IPOPL, IRET } : valA;
- icode in { ILEAVE } : valB;
- # Other instructions don't need address
- ];
- ## Select memory input data
- int mem_data = [
- # Value from register
- icode in { IRMMOVL, IPUSHL } : valA;
- # Return PC
- icode == ICALL : valP;
- # Default: Don't write anything
- ];
- ## Determine instruction status
- int Stat = [
- imem_error || dmem_error : SADR;
- !instr_valid: SINS;
- icode == IHALT : SHLT;
- 1 : SAOK;
- ];
- ################ Program Counter Update ############################
- ## What address should instruction be fetched at
- int new_pc = [
- # Call. Use instruction constant
- icode == ICALL : valC;
- # Taken branch. Use instruction constant
- icode == IJXX && Cnd : valC;
- # Completion of RET instruction. Use value from stack
- icode == IRET : valM;
- # Default: Use incremented PC
- 1 : valP;
- ];
- #/* $end seq-all-hcl */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement