added examples (fib,69420/fizzbuzz)
This commit is contained in:
@@ -73,6 +73,23 @@ handleSymbol h (ZorthASTWord "-") = do
|
||||
\ push rax\n"
|
||||
return ()
|
||||
|
||||
handleSymbol h (ZorthASTWord "*") = do
|
||||
liftIO $ hPutStr h
|
||||
" pop rbx\n\
|
||||
\ pop rax\n\
|
||||
\ imul rax, rbx\n\
|
||||
\ push rax\n"
|
||||
return ()
|
||||
|
||||
handleSymbol h (ZorthASTWord "/") = do
|
||||
liftIO $ hPutStr h
|
||||
" pop rbx\n\
|
||||
\ pop rax\n\
|
||||
\ cqo\n\
|
||||
\ idiv rbx\n\
|
||||
\ imul rax, rbx\n"
|
||||
return ()
|
||||
|
||||
handleSymbol h (ZorthASTWord "ret") = do
|
||||
liftIO $ hPutStr h
|
||||
" mov rax,60\n\
|
||||
@@ -87,6 +104,16 @@ handleSymbol h (ZorthASTWord "dup") = do
|
||||
\ push rax\n"
|
||||
return ()
|
||||
|
||||
handleSymbol h (ZorthASTWord "rot") = do
|
||||
liftIO $ hPutStr h
|
||||
" pop rax\n\
|
||||
\ pop rbx\n\
|
||||
\ pop rcx\n\
|
||||
\ push rbx\n\
|
||||
\ push rax\n\
|
||||
\ push rcx\n"
|
||||
return ()
|
||||
|
||||
handleSymbol h (ZorthASTWord "swap") = do
|
||||
liftIO $ hPutStr h
|
||||
" pop rax\n\
|
||||
|
||||
25
examples/69420.zorth
Normal file
25
examples/69420.zorth
Normal file
@@ -0,0 +1,25 @@
|
||||
: over swap dup rot rot ;
|
||||
: mod over over / * - ;
|
||||
|
||||
1
|
||||
|
||||
begin
|
||||
dup 50<
|
||||
while
|
||||
dup 15 mod 0 = if
|
||||
69420 .
|
||||
else
|
||||
dup 3 mod 0 = if
|
||||
69 .
|
||||
else
|
||||
dup 3 mod 0 = if
|
||||
420 .
|
||||
else
|
||||
dup .
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
1+
|
||||
repeat
|
||||
|
||||
ret
|
||||
18
examples/fib.zorth
Normal file
18
examples/fib.zorth
Normal file
@@ -0,0 +1,18 @@
|
||||
: fib
|
||||
0 1
|
||||
begin
|
||||
rot
|
||||
dup 0>
|
||||
while
|
||||
1-
|
||||
rot rot
|
||||
dup
|
||||
dup .
|
||||
rot
|
||||
+
|
||||
repeat
|
||||
;
|
||||
|
||||
15 fib
|
||||
|
||||
ret
|
||||
Reference in New Issue
Block a user