summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Variables.py3
-rw-r--r--notes.txt5
-rw-r--r--tests/params.c4
3 files changed, 8 insertions, 4 deletions
diff --git a/Variables.py b/Variables.py
index 89c8501..26de704 100644
--- a/Variables.py
+++ b/Variables.py
@@ -48,7 +48,8 @@ class Variables(object):
# XXX don't hardcode R5
return ("R5", str(-self.local_vars[name]))
try:
- return ("R5", str(1 + self.param_vars.index(name)))
+ # 1 for the return address, 1 for the stored BP
+ return ("R5", str(2 + self.param_vars.index(name)))
except ValueError:
pass
# lookup in the parent
diff --git a/notes.txt b/notes.txt
index d2998c1..5d8bbe0 100644
--- a/notes.txt
+++ b/notes.txt
@@ -26,7 +26,8 @@ Caller:
Callee:
1. push R5 (base pointer "BP" in stack for local variables and parameters)
2. Store current stack pointer in R5 (LOAD R5 SP). [R5] now contains the return
- address, [R5+i] the i-th parameter and [R5+-i] the i-th local var
+ address, [R5+i+1] the i-th parameter and [R5+-i] the i-th local var. Param i
+ is at R5 + i + 1 because BP was pushed too
3. Grow stack for local variables (by SUB SP n) if necessary
4. <function body>
5. LOAD SP R5 (clear local vars)
@@ -34,7 +35,7 @@ Callee:
6. RTS (go back to caller)
parameter access (i-th parameter):
-LOAD R0 [R5+i]
+LOAD R0 [R5+i+1]
local variable access (i-th local var)
LOAD R0 [R5+-i]
global variable access
diff --git a/tests/params.c b/tests/params.c
index eb91b83..2232fdd 100644
--- a/tests/params.c
+++ b/tests/params.c
@@ -1,5 +1,7 @@
int square(int x) {
- return x * x;
+ int res;
+ res = x * x;
+ return res;
}
int main() {
int x;