Created
March 10, 2017 01:14
-
-
Save relrod/02366bd89044106edb231030c2f4323d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ASM6809 where | |
import Data.ByteString.Builder | |
import Data.Word | |
import System.IO | |
data Instruction = | |
NOP | |
| ADDA Word8 | |
| LDA Word8 | |
| STA Word8 | |
assemble :: Instruction -> [Word8] | |
assemble NOP = [0x12] | |
assemble (ADDA w) = [0x8b, w] | |
assemble (LDA w) = [0x86, w] | |
assemble (STA w) = [0x97, w] | |
-- 56 + 43 = 99 (0x63) | |
program :: [Instruction] | |
program = | |
[ LDA 0x38 -- 56 | |
, ADDA 0x2b -- 43 | |
, STA 0x42 | |
] | |
main :: IO () | |
main = do | |
hSetBuffering stdout (BlockBuffering Nothing) | |
hSetBinaryMode stdout True | |
let assembled = program >>= assemble | |
mapM_ (hPutBuilder stdout . word8) assembled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment