summaryrefslogtreecommitdiff
path: root/notes.txt
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-01 22:24:48 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-01 22:24:48 +0000
commitd57a02efd8b6388c43c85078ccd20fd6bd7a8e37 (patch)
tree81c38f63bb521df191ce3f1a4ed6ad8b7763ca5a /notes.txt
parent6aaff7ae54dbe34ea6bf3f9ee8c93e9d79db3c22 (diff)
downloadpp2cc-d57a02efd8b6388c43c85078ccd20fd6bd7a8e37.tar.gz
Update TODO, README and add notes for call convention
Diffstat (limited to 'notes.txt')
-rw-r--r--notes.txt46
1 files changed, 46 insertions, 0 deletions
diff --git a/notes.txt b/notes.txt
new file mode 100644
index 0000000..d2998c1
--- /dev/null
+++ b/notes.txt
@@ -0,0 +1,46 @@
+Build a table for a (x+1)-bit number and their signed values in binary/decimal
+var a = [], x=4;
+var zpad = (new Array(x+1)).join("0"), pad = (new Array(x+1)).join(" ");
+for(var i=0;i<2<<x;i++) {
+ var n = i & ((2<<(x-1))-1);
+ n-=i&(2<<(x-1))
+ a.push((zpad+i.toString(2)).substr(-(x+1)) + " = " + (pad+n).substr(-(x+1)))
+}
+a.join("\n")
+
+Function call try to follow the convention at
+http://www.cs.virginia.edu/~evans/cs216/guides/x86.html#calling
+
+Reminder
+The stack starts at the end of the memory. If the stack grows, SP decreases.
+
+Caller:
+1. <no regs to push>
+2. For n parameters, do a PUSH. The last parameter is the first on the stack
+3. Call subroutine (BRS: PUSH return address on stack and BRanch Always)
+(after call when returned:)
+4. Remove parameters from the stack: ADD SP n
+5. Result is in R0
+6. (perhaps a CMP R0 0 or LOAD R0 R0 if in expression context?)
+
+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
+3. Grow stack for local variables (by SUB SP n) if necessary
+4. <function body>
+5. LOAD SP R5 (clear local vars)
+5. PULL R5 (restore the "BP" of the caller)
+6. RTS (go back to caller)
+
+parameter access (i-th parameter):
+LOAD R0 [R5+i]
+local variable access (i-th local var)
+LOAD R0 [R5+-i]
+global variable access
+LOAD R0 [GB+name]
+
+
+Initially, the stack size on the PP2 is 240 words, but it can be adjusted with:
+@STACKSIZE newsize
+The constant 'stacksize' (lowercase) contains the previous stack size