summaryrefslogtreecommitdiff
path: root/asm/assembler.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-09 15:50:45 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-09 15:50:45 +0100
commit8a3c8393b078084e8712641a2d2abdba728a0be1 (patch)
tree9704660c4ce756467996a0d2b048a742aa0b6736 /asm/assembler.ml
parentb8df2847aa60728b72a9a48769c8662214ba30c8 (diff)
parent9495dd3a9e4aa9e27004ce9718ac39c197db13c0 (diff)
downloadSystDigit-Projet-8a3c8393b078084e8712641a2d2abdba728a0be1.tar.gz
SystDigit-Projet-8a3c8393b078084e8712641a2d2abdba728a0be1.zip
Merge branch 'emile'
Conflicts: asm/asm.ml asm/asmlex.mll asm/asmpars.mly
Diffstat (limited to 'asm/assembler.ml')
-rw-r--r--asm/assembler.ml49
1 files changed, 22 insertions, 27 deletions
diff --git a/asm/assembler.ml b/asm/assembler.ml
index 48049ef..66999fb 100644
--- a/asm/assembler.ml
+++ b/asm/assembler.ml
@@ -75,6 +75,10 @@ let its = function
| Imm i -> string_of_int i
| Lab l -> l
+let size = function
+ | Byte _ -> 1
+ | _ -> 2
+
let print_program p =
let pc = ref 0 in
let value = function
@@ -87,7 +91,6 @@ let print_program p =
| Imm i -> i
| Lab l -> (byte 16 (fst (Imap.find l p.lbls))) lsr 8 in
let get_reps = function
- | TwoRawBytes(a, b) -> (a) lxor (b lsl 8), sprintf "bytes %d %d" a b
| R (o,r1,r2,r3) -> r (code o) r1 r2 r3,
sprintf "%s %s %s %s" (List.assoc o rev_keywords) (rts r1) (rts r2) (rts r3)
| Incri (r,d) -> i 0b00110 r d, sprintf "incri %s %d" (rts r) d
@@ -108,37 +111,29 @@ let print_program p =
| Liu (r,i) -> (0b11010 lsl 11) lxor (r lsl 8) lxor ((byte 8 (value3 i)) land 0xFF),
sprintf "liu %s %s" (rts r) (its i)
| Liuz (r,i) -> (0b11011 lsl 11) lxor (r lsl 8) lxor ((byte 8 (value3 i)) land 0xFF),
- sprintf "liuz %s %s" (rts r) (its i) in
- let n = List.length p.text in
+ sprintf "liuz %s %s" (rts r) (its i)
+ | Hlt -> (0b01111 lsl 11),"hlt"
+ | Word w -> (byte 16 w), ""
+ | Byte b -> byte 8 b, "" in
+ let n = List.fold_left (fun n i -> size i + n) 0 p.text in
let rev_lbls = Array.make n "" in
Imap.iter (fun l (v,t) ->
- if t then rev_lbls.(v/2) <- rev_lbls.(v/2) ^ " " ^ l) p.lbls;
+ if t then rev_lbls.(v) <- rev_lbls.(v) ^ " " ^ l) p.lbls;
let f instr =
- if rev_lbls.(!pc/2) <> "" then
- printf "\t#%s:\n" rev_lbls.(!pc/2);
+ if rev_lbls.(!pc) <> "" then
+ printf "\t#%s:\n" rev_lbls.(!pc);
let w,s = get_reps instr in
- printf "%s\t\t# %s\n" (wts w) s;
- pc := !pc + 2 in
- printf "%d %d\n" (2*n) 8;
+ let size = size instr in
+ if size = 2 then (
+ printf "%s" (wts w);
+ if s <> "" then
+ printf "\t\t# %s\n" s
+ else printf "\n";
+ pc := !pc + 2
+ ) else (
+ printf "%s\n" (bts w) ) in
+ printf "%d %d\n" (n) 8;
List.iter f p.text;
- let n2 = List.fold_left (fun n (_,w) -> if w then n + 2 else n + 1) 0 p.data in
- if n2 > 0 then (
- printf "\n%d %d\n" n2 8;
- let rev_lbls = Array.make n2 "" in
- Imap.iter (fun l (v,t) ->
- if not t then rev_lbls.(v) <- rev_lbls.(v) ^ " " ^ l) p.lbls;
- pc := 0;
- let f2 (b,w) =
- if rev_lbls.(!pc) <> "" then
- printf "\t#%s:\n" rev_lbls.(!pc);
- if w then (
- printf "%s\n" (wts (byte 16 b));
- pc := !pc + 2
- ) else (
- printf "%s\n" (bts (byte 8 b));
- pc := !pc + 1) in
- List.iter f2 p.data
- );
printf "\n"
let print_error e sp ep =