3a_asm: use '-b' for binary representation
authorBernhard Urban <lewurm@gmail.com>
Sat, 11 Dec 2010 12:32:04 +0000 (13:32 +0100)
committerBernhard Urban <lewurm@gmail.com>
Sat, 11 Dec 2010 12:32:04 +0000 (13:32 +0100)
3_test/exectest.sh
3a_asm/DTFormat.hs
3a_asm/Main.hs

index eaf8ece6eb81ecfc5e6364747a38ebfa08a7a2c6..77ac27da596fbd76abddbc20ebad9b07eaa1ad0c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash -x
+#!/bin/bash
 
 ARG2=$2
 
@@ -22,6 +22,14 @@ runasm() {
        ../3a_asm/dtas < $ARG2 > ${ARG2%.s}.dthex
 }
 
+runasmbin() {
+       if [ "$ARG2" == ""  ]; then
+               echo "runasm: please provide a assembler file"
+               exit 1
+       fi
+       ../3a_asm/dtas -b < $ARG2 > ${ARG2%.s}_bin.dthex
+}
+
 runsim() {
        if [ "$ARG2" == ""  ]; then
                echo "runsim: please provide a dthex file"
@@ -43,8 +51,11 @@ case $1 in
        clean) cleantools;;
        build) buildtools;;
        asm) runasm;;
+       asmbin) runasmbin;;
        sim) runsim;;
        asmsim) runasmsim;;
-       *) echo "first argument must be clean|build|asm <file.s>|sim <file.dthex>|asmsim <file.s>"
+       *) echo "first argument must be clean|build|"
+          echo "asm <file.s>|asmbin <file.s>|"
+          echo "sim <file.dthex>|asmsim <file.s>"
 esac
 
index 3a43eb8b854487ca6b4c18dbd13af4c44b0f5566..8b85ca1cca9c0656e4155bd0b6c391b4600b6db6 100644 (file)
@@ -1,6 +1,8 @@
 module DTFormat where
 
+import Numeric
 import Data.Word
+import Data.Char
 import Text.Printf
 import Text.Parsec
 import Text.Parsec.String
@@ -51,6 +53,16 @@ showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
 datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
 datins = printf "%s;%08x;%08x;%s;%s;%s\n"
 
+tobin :: Value -> String
+tobin v = reverse $ take 32 $ reverse $ (['0' | _<-[0..32]]) ++ (showIntAtBase 2 (chr. ((+)0x30)) v "")
+
+showsDTFBase :: DTF -> Int -> ShowS
+showsDTFBase (DTF_Data a v c l s) 2 = (++) (datinsBin "0" a (tobin v) c l s)
+showsDTFBase (DTF_Instr a v c l s) 2 = (++) (datinsBin "1" a (tobin v) c l s)
+showsDTFBase d _ = showsDTF d
+
+datinsBin :: String -> Address -> String -> Code -> Label -> Comment -> String
+datinsBin = printf "%s;%08x;%s;%s;%s;%s\n"
 
 -- datastructure for managing labels and defines
 type Dict = (Address,[DictElem])
index 974cbd47d03250f6dfc61b82d26c5c570b2a3aed..d62fe17360220692b8defa51d7e7495b49dd2a71 100644 (file)
@@ -25,7 +25,7 @@ main = do
        content <- getContents
        let src = (filter (((/=) "") . snd) $ (zip [1..] (lines content)))
        let (dict,formatedsrc) = convertDTF src NoState 0x00 0x00 [("start_",0x00)]
-       if (not $ null args) && (head args == "-d")
+       if (not $ null args) && ("-d" `elem` args)
                then do
                        printf "\nlabels:\n"
                        sequence_ [printf "%20s @ 0x%08x\n" l a | (l,a) <- (reverse dict)]
@@ -34,8 +34,9 @@ main = do
                        printf "\nafter parsing the instructions:\n"
                else do
                        printf ""
+       let base = if "-b" `elem` args then 2 else 16
        let parsed = parseInstr dict formatedsrc
-       sequence_ [printf "%s" (show x) | x <- parsed]
+       sequence_ [printf "%s" (showsDTFBase x base "") | x <- parsed]
 
 
 parseInstr :: [DictElem] -> [DTF] -> [DTF]