Start with project

This commit is contained in:
Jan-Niclas Loosen
2025-10-23 13:45:02 +02:00
parent 5e616dd0a2
commit b0974af092
21 changed files with 658 additions and 84 deletions

View File

@@ -0,0 +1,14 @@
// Quellkode: y = x*3+5*2
// Annahmen: Variable x durch Kellerzelle 0 und Variable y durch Kellerzelle 1 implementiert,
// sowie PP=0, FP=0 und TOP=1.
CONST 6
STORE 0 0
LOAD 0 0
CONST 3
MUL
CONST 5
CONST 2
MUL
ADD
STORE 1 0
HALT

View File

@@ -0,0 +1,13 @@
// Quellkode: x=10; if(x == 0) 100 else 200; 3
// Annahmen: Variable x durch Kellerzelle 0 implementiert, sowie PP=0, FP=0 und TOP=0.
//
CONST 10
STORE 0 0
LOAD 0 0
IFZERO L1
CONST 200
GOTO L2
L1: CONST 100
L2: NOP
CONST 3
HALT

View File

@@ -0,0 +1,37 @@
// Quellkode: let f (x, y, z) {
// x = y + z;
// if ( y == 3) then
// 15
// else
// f ( z = 3 ; 4 , y, z)
// } in f (2, 3, 4)
//
// Annahmen: keine
GOTO L1
LF: LOAD 1 0
LOAD 2 0
ADD
STORE 0 0
LOAD 0 0
POP
LOAD 1 0
CONST 3
EQ
IFZERO L2
CONST 15
GOTO L3
CONST 3
STORE 2 0
LOAD 2 0
POP
CONST 4
LOAD 1 0
LOAD 2 0
INVOKE 3 LF 1
L3: NOP
RETURN
L1: CONST 2
CONST 3
CONST 4
INVOKE 3 LF 0
HALT

View File

@@ -0,0 +1,11 @@
// Quellkode: let square(x) { x*x }
// in square(10)
// Annahmen: Das Argument von square wird durch Kellerzelle 0 repraesentiert,
// sowie PP=0, FP=0 und TOP=-1
CONST 10
INVOKE 1 LSQUARE 0
HALT
LSQUARE: LOAD 0 0
LOAD 0 0
MUL
RETURN

View File

@@ -0,0 +1,28 @@
GOTO L2
L1: LOAD 0 0
CONST 0
EQ
IFZERO L3
CONST 0
GOTO L4
L3: LOAD 0 0
CONST 1
EQ
IFZERO L5
CONST 1
GOTO L6
L5: LOAD 0 0
CONST 1
SUB
INVOKE 1 L1 1
LOAD 0 0
CONST 2
SUB
INVOKE 1 L1 1
ADD
L6: NOP
L4: NOP
RETURN
L2: CONST 6
INVOKE 1 L1 0
HALT

View File

@@ -0,0 +1,29 @@
// Quellkode: let wrapper(number, threshold) {
// let square(x) {
// if (x*x > threshold) x
// else x*x
// }
// in square(number)
// }
// in wrapper(4, 10)
// Annahmen: Die Argumente von wrapper werden durch die Kellerzellen 0 und 1 repraesentiert,
// sowie PP=0, FP=0 und TOP=-1
CONST 4
CONST 10
INVOKE 2 LWRAPPER 0
HALT
LWRAPPER: LOAD 0 0
INVOKE 1 LSQUARE 0
RETURN
LSQUARE: LOAD 0 0
LOAD 0 0
MUL
LOAD 1 1
GT
IFZERO L1
LOAD 0 0
RETURN
L1: LOAD 0 0
LOAD 0 0
MUL
RETURN