summaryrefslogtreecommitdiff
path: root/asm/assembler.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-08 18:33:54 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-08 18:33:54 +0100
commit2ab6a18d17e0f16f359feafc582f2ff732f34492 (patch)
treea14e83560b4b577313f9ef2fe3f9c0be5220ef0a /asm/assembler.ml
parentb2c5356b3f6d2e0a836a19b4cae1791d350785d3 (diff)
parente07508129a81605f77ee410ef4db104a96fc44bf (diff)
downloadSystDigit-Projet-2ab6a18d17e0f16f359feafc582f2ff732f34492.tar.gz
SystDigit-Projet-2ab6a18d17e0f16f359feafc582f2ff732f34492.zip
Merge branch 'integration-progressive'
Conflicts: asm/asm.ml asm/asmlex.mll asm/asmpars.mly asm/assembler.ml
Diffstat (limited to 'asm/assembler.ml')
-rw-r--r--asm/assembler.ml45
1 files changed, 26 insertions, 19 deletions
diff --git a/asm/assembler.ml b/asm/assembler.ml
index 1158181..48049ef 100644
--- a/asm/assembler.ml
+++ b/asm/assembler.ml
@@ -74,19 +74,20 @@ let code = function
let its = function
| Imm i -> string_of_int i
| Lab l -> l
- | Labu l -> l
let print_program p =
let pc = ref 0 in
let value = function
| Imm i -> i
- | Lab l -> Imap.find l p.lbls
- | Labu l -> (Imap.find l p.lbls) lsr 8 in
+ | Lab l -> fst (Imap.find l p.lbls) in
let value2 = function
| Imm i -> i
- | Lab l -> Imap.find l p.lbls - !pc
- | _ -> assert false in
+ | Lab l -> fst (Imap.find l p.lbls) - !pc in
+ let value3 = function
+ | 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
@@ -100,20 +101,18 @@ let print_program p =
| Lb (r1,r2,i) -> k 0b10010 r1 r2 i, sprintf "lb %s %d(%s)" (rts r1) i (rts r2)
| Sb (r1,r2,i) -> k 0b10011 r1 r2 i, sprintf "sb %s %d(%s)" (rts r1) i (rts r2)
| Lra i -> j 0b01100 (value2 i), sprintf "lra %s" (its i)
- | Lil (r,i) -> (0b11000 lsl 11) lxor (r lsl 8) lxor (value i land 0xFF),
+ | Lil (r,i) -> (0b11000 lsl 11) lxor (r lsl 8) lxor ((byte 8 (value i)) land 0xFF),
sprintf "lil %s %s" (rts r) (its i)
- | Lilz (r,i) -> (0b11001 lsl 11) lxor (r lsl 8) lxor (value i land 0xFF),
+ | Lilz (r,i) -> (0b11001 lsl 11) lxor (r lsl 8) lxor ((byte 8 (value i)) land 0xFF),
sprintf "lilz %s %s" (rts r) (its i)
- | Liu (r,i) -> (0b11010 lsl 11) lxor (r lsl 8) lxor (value i land 0xFF),
+ | 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 (value i land 0xFF),
- sprintf "liuz %s %s" (rts r) (its i)
- | TwoRawBytes(a, b) -> (a) lxor (b lsl 8), sprintf "bytes %d %d" a b
- in
+ | 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
let rev_lbls = Array.make n "" in
- Imap.iter (fun l v ->
- if v/2 < n then rev_lbls.(v/2) <- rev_lbls.(v/2) ^ " " ^ l) p.lbls;
+ Imap.iter (fun l (v,t) ->
+ if t then rev_lbls.(v/2) <- rev_lbls.(v/2) ^ " " ^ l) p.lbls;
let f instr =
if rev_lbls.(!pc/2) <> "" then
printf "\t#%s:\n" rev_lbls.(!pc/2);
@@ -125,11 +124,19 @@ let print_program p =
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 f2 = function
- | (b,true) ->
- printf "%s\n" (wts (byte 16 b))
- | (b,false)->
- printf "%s\n" (bts (byte 8 b)) in
+ 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"