File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ const MEMORY_SIZE = 4096
9
9
// Stack size in number of words
10
10
const STACK_SIZE = 256
11
11
12
+ // Number of bytes in a word
13
+ const WORD_SIZE = 4
14
+
12
15
// XZR register number
13
16
const XZR = 31
14
17
Original file line number Diff line number Diff line change 1
1
package memory
2
2
3
3
import (
4
+ "fmt"
4
5
"errors"
5
6
ALU "github.com/coderick14/ARMed/ALU"
6
7
"regexp"
@@ -392,7 +393,7 @@ func (instruction *AddImmediateInstruction) parse() error {
392
393
instruction .constant = uint (constant )
393
394
394
395
address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
395
- if address >= MEMORY_SIZE {
396
+ if address > MEMORY_SIZE * WORD_SIZE {
396
397
return errors .New ("Stack underflow error in : " + instruction .inst )
397
398
}
398
399
@@ -460,7 +461,7 @@ func (instruction *SubImmediateInstruction) parse() error {
460
461
instruction .constant = uint (constant )
461
462
462
463
address := getRegisterValue (instruction .reg2 ) + int64 (instruction .constant )
463
- if address < (MEMORY_SIZE - STACK_SIZE ) {
464
+ if address < (MEMORY_SIZE - STACK_SIZE ) * WORD_SIZE {
464
465
return errors .New ("Stack overflow error in : " + instruction .inst )
465
466
}
466
467
You can’t perform that action at this time.
0 commit comments