File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,11 @@ func (instruction *AddImmediateInstruction) parse() error {
391391 instruction .reg2 = SP
392392 instruction .constant = uint (constant )
393393
394+ address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
395+ if address >= MEMORY_SIZE {
396+ return errors .New ("Stack underflow error in : " + instruction .inst )
397+ }
398+
394399 return nil
395400 }
396401
@@ -454,6 +459,11 @@ func (instruction *SubImmediateInstruction) parse() error {
454459 instruction .reg2 = SP
455460 instruction .constant = uint (constant )
456461
462+ address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
463+ if address < (MEMORY_SIZE - STACK_SIZE ) {
464+ return errors .New ("Stack overflow error in : " + instruction .inst )
465+ }
466+
457467 return nil
458468 }
459469
You can’t perform that action at this time.
0 commit comments