import { MemoryView } from "../memory-view" ; import { NumericConstant } from "../memory-view" ; import { CPU , REGISTER_INDEX } from "../cpu" ; export interface Indexer { indexReg : number ; multiplier : number ; constant : number ; } export abstract class Parameter { public static get Reg ( ) { return "Reg" ; } public static get Memory ( ) { return "Mem" ; } public static get Constant ( ) { return "Constant" ; } public static get DerefConstant ( ) { return "DerefConstant" ; } constructor ( protected size = 4 ) { } abstract fetchData ( cpu ) ; } export class RegisterParameter extends Parameter { constructor ( size , private registerIndex ) { super ( size ) ; } fetchData ( cpu ) { return cpu . getRegisterByIndex ( this . registerIndex ) ; } } export class MemoryParameter extends Parameter { constructor ( size , private baseReg , private indexer ) { super ( size ) ; } fetchData ( cpu ) { let baseReg = cpu . getRegisterByIndex ( this . baseReg ) ; let indexReg = cpu . getRegisterByIndex ( this . indexer . indexReg ) ; return cpu . derefAddress ( cpu . calculateEffectiveAddressFromRegister ( baseReg , indexReg , this . indexer . multiplier , this . indexer . constant ) , this . size ) ; } } export class LabelParameter extends Parameter { protected value : number = - 1 ; constructor ( size , private _label = "" ) { super ( size ) ; } get label ( ) : string { return this . _label ; } set label ( value ) { this . _label = value ; } resolveLabel ( value ) { this . value = value ; } fetchData ( cpu ) { return new NumericConstant ( this . value , this . size ) ; } } export class DerefLabelParameter extends LabelParameter { constructor ( size , label = "" , private indexer ) { super ( size , label ) ; } fetchData ( cpu ) { let indexReg = cpu . getRegisterByIndex ( this . indexer . indexReg ) ; return cpu . derefAddress ( cpu . calculateEffectiveAddress ( this . value , indexReg , this . indexer . multiplier , this . indexer . constant ) , this . size ) ; } }