@@ -42,6 +42,11 @@ func IsValidPC(PC int64) bool {
4242 return isValidPC
4343}
4444
45+ // isEmptyInstruction is a method to check for null instructions (NoOps)
46+ func isEmptyInstruction (currentInstruction string ) bool {
47+ return len (currentInstruction ) == 0
48+ }
49+
4550// ExtractLabels is a method to extract labels from instructions.
4651func (instructionMemory * InstructionMemory ) ExtractLabels () {
4752
@@ -65,6 +70,11 @@ func (instructionMemory *InstructionMemory) ValidateAndExecuteInstruction() erro
6570 //get next instruction to be executed from instruction memory
6671 currentInstruction := instructionMemory .Instructions [instructionMemory .PC ]
6772
73+ if isEmptyInstruction (currentInstruction ) {
74+ instructionMemory .updatePC ()
75+ return nil
76+ }
77+
6878 var err error
6979
7080 if strings .HasPrefix (currentInstruction , "ADD " ) {
@@ -450,7 +460,7 @@ func (instruction *AddImmediateInstruction) parse() error {
450460 instruction .constant = uint (constant )
451461
452462 address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
453- if address > MEMORY_SIZE * WORD_SIZE {
463+ if address > MEMORY_SIZE * WORD_SIZE {
454464 return errors .New ("Stack underflow error in : " + instruction .inst )
455465 }
456466
@@ -518,7 +528,7 @@ func (instruction *SubImmediateInstruction) parse() error {
518528 instruction .constant = uint (constant )
519529
520530 address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
521- if address < (MEMORY_SIZE - STACK_SIZE ) * WORD_SIZE {
531+ if address < (MEMORY_SIZE - STACK_SIZE )* WORD_SIZE {
522532 return errors .New ("Stack overflow error in : " + instruction .inst )
523533 }
524534
0 commit comments