summaryrefslogtreecommitdiff
path: root/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Compiler.hs')
-rw-r--r--Compiler.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/Compiler.hs b/Compiler.hs
index f02a50a..23ce5d3 100644
--- a/Compiler.hs
+++ b/Compiler.hs
@@ -64,12 +64,18 @@ compileIns (ICopy _ _ 0) = return ()
compileIns (ICopy from to m) = do
emit $ "mov al, [" ++ cursorOffset from ++ "]"
case m of
- 1 -> return ()
- _ | Just p <- isTwoPower m -> emit $ "shl al, " ++ show p
+ 1 -> emit $ "add [" ++ cursorOffset to ++ "], al"
+ -1 -> emit $ "sub [" ++ cursorOffset to ++ "], al"
+ _ | Just p <- isTwoPower m -> do
+ emit $ "shl al, " ++ show p
+ emit $ "add [" ++ cursorOffset to ++ "], al"
+ | Just p <- isTwoPower (-m) -> do
+ emit $ "shl al, " ++ show p
+ emit $ "sub [" ++ cursorOffset to ++ "], al"
| otherwise -> do
- emit $ "mov cl, " ++ show m
- emit "mul byte cl"
- emit $ "add [" ++ cursorOffset to ++ "], al"
+ emit $ "mov cl, " ++ show m
+ emit "mul byte cl"
+ emit $ "add [" ++ cursorOffset to ++ "], al"
compileIns (ISlide off) = emit $ "add " ++ cursorReg ++ ", " ++ show off
compileIns (ILoop inss off) = do
loopid <- genId
@@ -84,8 +90,7 @@ compileIns (IInput off) = do
emit $ generateCall "getchar"
emit $ "mov [" ++ cursorOffset off ++ "], al"
compileIns (IOutput off) = do
- emit "xor edi, edi"
- emit $ "mov dil, [" ++ cursorOffset off ++ "]"
+ emit $ "movzx edi, byte [" ++ cursorOffset off ++ "]"
emit $ generateCall "putchar"
compileIns IStart = return ()