mirror of
https://gitlab.com/jusax23/raspberry-pi-pico-machine-code-emulator.git
synced 2024-11-21 22:26:44 +01:00
while loop
This commit is contained in:
parent
670c75ff2f
commit
5834077608
4 changed files with 118 additions and 0 deletions
79
compiler/output/loops.as
Normal file
79
compiler/output/loops.as
Normal file
|
@ -0,0 +1,79 @@
|
|||
|
||||
v0 = 0;4
|
||||
SHS 4
|
||||
;code
|
||||
|
||||
;defvar: executing value:
|
||||
|
||||
;num: Loading num
|
||||
LIA 0
|
||||
|
||||
;defvar: Store Value
|
||||
STA 4 v0
|
||||
|
||||
beforloop2:
|
||||
|
||||
;<: execute first
|
||||
|
||||
;var: load Variable
|
||||
LDA 4 v0
|
||||
|
||||
PSH 4
|
||||
;<: execute secound
|
||||
|
||||
;num: Loading num
|
||||
LIA 65535
|
||||
|
||||
CAB
|
||||
PUL 4
|
||||
CMP 0 0
|
||||
LIA 1
|
||||
JS .endcompare1
|
||||
LIA 0
|
||||
endcompare1:
|
||||
|
||||
LIB 1
|
||||
CMP 0 0
|
||||
JNE .afterloop3
|
||||
;loop code
|
||||
|
||||
|
||||
;print: executing value:
|
||||
|
||||
;var: load Variable
|
||||
LDA 4 v0
|
||||
|
||||
;print Value
|
||||
OUT 0
|
||||
|
||||
;let: executing value:
|
||||
|
||||
;+: next value
|
||||
|
||||
;var: load Variable
|
||||
LDA 4 v0
|
||||
|
||||
|
||||
PSH 4
|
||||
|
||||
;+: next value
|
||||
|
||||
;num: Loading num
|
||||
LIA 1
|
||||
|
||||
|
||||
;+: Pull/Add next
|
||||
CAB
|
||||
PUL 4
|
||||
ADD 0 0 0
|
||||
|
||||
;let: Store Value
|
||||
STA 4 v0
|
||||
|
||||
|
||||
JMP .beforloop2
|
||||
afterloop3:
|
||||
|
||||
HLT
|
||||
;functions
|
||||
|
1
compiler/output/loops.b16
Normal file
1
compiler/output/loops.b16
Normal file
|
@ -0,0 +1 @@
|
|||
fe00040f00000000080400000104000039040f0000ffff133a043100000f0000000137002a0f00000000100000000131000034005401040000fd000104000039040f00000001133a04220000000804000032000cff
|
7
compiler/scripts/loops.lisp
Normal file
7
compiler/scripts/loops.lisp
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
(defvar i:uint32 0)
|
||||
|
||||
(loop while (< i 0xffff)
|
||||
(print i)
|
||||
(let i (+ i 1))
|
||||
)
|
|
@ -558,6 +558,37 @@ endcompare${id}:
|
|||
LIA 0
|
||||
endcompare${id}:
|
||||
`;
|
||||
}else if(data[0]=="loop"){
|
||||
if(data[1] == "while"){
|
||||
let [c,etype] = execute(data[2],"bool",context,local);
|
||||
var idbefor = nid++;
|
||||
var idafter = nid++;
|
||||
var codeinsert = "";
|
||||
|
||||
for (var i = 3; i < data.length; i++) {
|
||||
let [ci,ti] = execute(data[i],i==data.length-1?expect:"any",context,local);
|
||||
ptype = ti;
|
||||
codeinsert+=ci;
|
||||
}
|
||||
code+=`
|
||||
beforloop${idbefor}:
|
||||
${c}
|
||||
LIB 1
|
||||
CMP 0 0
|
||||
JNE .afterloop${idafter}
|
||||
;loop code
|
||||
|
||||
${codeinsert}
|
||||
|
||||
JMP .beforloop${idbefor}
|
||||
afterloop${idafter}:
|
||||
`;
|
||||
|
||||
}else if(data[1] == "for"){
|
||||
error("Methode 'for' will be implemented later.",...data[1].pos);
|
||||
}else{
|
||||
error(`Unknown loop Methode: ${data[1]}`,...data[1].pos);
|
||||
}
|
||||
}else{
|
||||
if(extrafuns[data[0]]){
|
||||
var fun = extrafuns[data[0]];
|
||||
|
|
Loading…
Reference in a new issue