@@ -42,6 +42,11 @@ func IsValidPC(PC int64) bool {
42
42
return isValidPC
43
43
}
44
44
45
+ // isEmptyInstruction is a method to check for null instructions (NoOps)
46
+ func isEmptyInstruction (currentInstruction string ) bool {
47
+ return len (currentInstruction ) == 0
48
+ }
49
+
45
50
// ExtractLabels is a method to extract labels from instructions.
46
51
func (instructionMemory * InstructionMemory ) ExtractLabels () {
47
52
@@ -65,6 +70,11 @@ func (instructionMemory *InstructionMemory) ValidateAndExecuteInstruction() erro
65
70
//get next instruction to be executed from instruction memory
66
71
currentInstruction := instructionMemory .Instructions [instructionMemory .PC ]
67
72
73
+ if isEmptyInstruction (currentInstruction ) {
74
+ instructionMemory .updatePC ()
75
+ return nil
76
+ }
77
+
68
78
var err error
69
79
70
80
if strings .HasPrefix (currentInstruction , "ADD " ) {
@@ -450,7 +460,7 @@ func (instruction *AddImmediateInstruction) parse() error {
450
460
instruction .constant = uint (constant )
451
461
452
462
address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
453
- if address > MEMORY_SIZE * WORD_SIZE {
463
+ if address > MEMORY_SIZE * WORD_SIZE {
454
464
return errors .New ("Stack underflow error in : " + instruction .inst )
455
465
}
456
466
@@ -518,7 +528,7 @@ func (instruction *SubImmediateInstruction) parse() error {
518
528
instruction .constant = uint (constant )
519
529
520
530
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 {
522
532
return errors .New ("Stack overflow error in : " + instruction .inst )
523
533
}
524
534
0 commit comments