aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Asm
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-25 20:53:10 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-25 20:53:10 +0100
commit1e33e1510bc5891f040137b0c33fa8d49fe3a4c9 (patch)
tree7ff8718150856104a62661a659589bb8e9818f23 /src/Micro/Asm
parent0c2b9dc0c37505a5134f904ea867f2a311bfe162 (diff)
downloadmicro-lang-hs-1e33e1510bc5891f040137b0c33fa8d49fe3a4c9.tar.gz
micro-lang-hs-1e33e1510bc5891f040137b0c33fa8d49fe3a4c9.zip
Slightly better
Diffstat (limited to 'src/Micro/Asm')
-rw-r--r--src/Micro/Asm/Sdcc.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Micro/Asm/Sdcc.hs b/src/Micro/Asm/Sdcc.hs
index a3f83ed..af4e7d7 100644
--- a/src/Micro/Asm/Sdcc.hs
+++ b/src/Micro/Asm/Sdcc.hs
@@ -62,6 +62,17 @@ mul8 a b p = do
toLabel loop0 True
]
+mul :: A.Expr -> A.Expr -> SourcePos -> [String]
+mul a b@(A.Num v _) p
+ | v == 2 = oCode (emit a) ++ ["\tsla a"]
+ | v == 4 = oCode (emit a) ++ replicate 2 "\tsla a"
+ | v == 8 = oCode (emit a) ++ replicate 3 "\tsla a"
+ | v == 16 = oCode (emit a) ++ replicate 4 "\tsla a"
+ | v == 32 = oCode (emit a) ++ replicate 5 "\tsla a"
+ | v < 6 = oCode (emit a) ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c"
+ | otherwise = mul8 a b p
+mul _ _ _ = [";; unimplemented"]
+
data Output = Output
{ oPre :: [String],
oInit :: [String],
@@ -104,14 +115,9 @@ emit x =
o {oCode = ["\txor a"]}
(A.BinOp A.Mul _ (A.Num 1 _) b) -> o {oCode = oCode (emit b)}
(A.BinOp A.Mul _ a (A.Num 1 _)) -> o {oCode = oCode (emit a)}
- (A.BinOp A.Mul _ a (A.Num 2 _)) ->
- o {oCode = oCode (emit a) ++ ["\tsla a"]}
- (A.BinOp A.Mul _ (A.Num 2 _) b) ->
- o {oCode = oCode (emit b) ++ ["\tsla a"]}
- (A.BinOp A.Mul _ a (A.Num v _)) ->
- o {oCode = oCode (emit a) ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c"}
- (A.BinOp A.Mul p a b) -> do
- o {oCode = mul8 a b p}
+ (A.BinOp A.Mul pos a b@(A.Num _ _)) -> o {oCode = mul a b pos}
+ (A.BinOp A.Mul pos a@(A.Num _ _) b) -> o {oCode = mul b a pos}
+ (A.BinOp A.Mul p a b) -> o {oCode = mul8 a b p}
(A.BinOp A.Assign _ (A.Variable id _) b) ->
o {oCode = oCode (emit b) ++ ["\tld (" ++ toIdent id ++ "), a"]}
_ -> o {oCode = [";; unimplemented " ++ show x]}