From 5ebebc8f57afc45b83adf4de7d5327fceb35370f Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sat, 11 Dec 2010 13:32:04 +0100 Subject: [PATCH] 3a_asm: use '-b' for binary representation --- 3_test/exectest.sh | 15 +++++++++++++-- 3a_asm/DTFormat.hs | 12 ++++++++++++ 3a_asm/Main.hs | 5 +++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/3_test/exectest.sh b/3_test/exectest.sh index eaf8ece..77ac27d 100755 --- a/3_test/exectest.sh +++ b/3_test/exectest.sh @@ -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 |sim |asmsim " + *) echo "first argument must be clean|build|" + echo "asm |asmbin |" + echo "sim |asmsim " esac diff --git a/3a_asm/DTFormat.hs b/3a_asm/DTFormat.hs index 3a43eb8..8b85ca1 100644 --- a/3a_asm/DTFormat.hs +++ b/3a_asm/DTFormat.hs @@ -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]) diff --git a/3a_asm/Main.hs b/3a_asm/Main.hs index 974cbd4..d62fe17 100644 --- a/3a_asm/Main.hs +++ b/3a_asm/Main.hs @@ -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] -- 2.25.1