Commit e43a6bc8 authored by Daru13's avatar Daru13
Browse files

Merge branch 'master' of https://git.eleves.ens.fr/mpepin/sysdig

parents be4bba3b 856313cd
......@@ -11,16 +11,15 @@ require alu/main
(* --------------------------- *)
(*
main (b) = (instruction:[word], syscall, ctrl:[2], alu_result:[32],
alu_input_2:[32], alu_ctrl:[4]) where
*)
main () = (instruction:[word], pc_value:[word], is_jr,
imm_addr:[word], is_jal, pc_incr:[word])
where
*)
main () = () where
(* Reading the next instruction from the ROM *)
(instruction, syscall, ctrl, pc_incr, pc_value) = next_instruction(instruction[6..],
imm_addr, jump, branch and (not(is_beq) xor alu_zero), is_jr);
(instruction, pc_incr) = next_instruction(
instruction[6..], imm_addr, jump,
branch and (not(is_beq) xor alu_zero), is_jr);
(* If is_jr is set, the immediate value is replaced by the 1st read register value *)
imm_addr = mux_n<word>(is_jr, read_data1, extended_imm);
......
......@@ -39,10 +39,9 @@ end where
(* Gives the last value of PC and sets PC to the next instruction's address. *)
PC (partial_jump_addr:[word-6], imm:[word], jump, branch, is_jr, wait)
= (value:[word], incr_addr:[word]) where
= (r:[word], incr_addr:[word]) where
(next_addr, incr_addr) = calc_address(r, partial_jump_addr, imm, jump, branch, is_jr);
r = meta_reg<word>(next_addr, not wait);
value = r;
end where
couter4(init) = ctrl:[2] where
......@@ -53,7 +52,7 @@ end where
(* Reads the next instruction and handles the syscalls *)
next_instruction(partial_jump_addr:[word-6], imm:[word], jump, branch, is_jr)
= (instruction:[word], syscall, ctrl:[2], pc_incr:[word], pc_value:[word]) where
= (instruction:[word], pc_incr:[word]) where
(* The real instruction read from the ROM *)
(pc_value, pc_incr) = PC(partial_jump_addr, imm, jump, branch, is_jr, wait);
......
......@@ -104,14 +104,14 @@ let write_instruction (rom_env : rom_t env) (ram_env : ram_t env) instr =
| Iinstrl2(opcode, r1, r2, label) ->
let addr = try find_label rom_env label
with UnknownLabel _ ->
find_label ram_env label in
4*(find_label ram_env label) in
[boiu 6 opcode; reg r2; reg r1; boiu 16 addr]
| Iinstrofs(opcode, r1, r2, ofs) ->
[boiu 6 opcode; reg r2; reg r1; boiu 16 ofs]
| Lui_l(r, label) ->
let addr = try find_label rom_env label
with UnknownLabel _ ->
find_label ram_env label in
4*(find_label ram_env label) in
[boiu 6 0xF; zeros 5; reg r; boiu 16 (addr lsr 16)]
(*
J format: opcode address
......
......@@ -14,12 +14,12 @@ let sys_print_str ram start_addr =
let addr = ref start_addr in
let current_char = ref 0 in
let read_char () =
let c = Ram.int_of_bits @@ Ram.get_byte ram !addr in
current_char := c;
current_char := (Ram.int_of_bits @@ Ram.get_byte ram !addr);
incr addr in
while (read_char () ; !current_char <> 0) do
print_char (char_of_int !current_char)
Printf.printf "%c" (char_of_int !current_char)
done;
flush stdout;
0
(** Stops the simulator execution, maybe a little bit violent but… It will do
......
.text
main:
la $a0, hello
li $v0, 1
syscall
la $a0, world
li $v0, 1
syscall
la $a0, hello
li $v0, 1
syscall
la $a0, hello
addi $a0, 8
li $v0, 1
syscall
end:
li $v0, 10
syscall
.data
hello: .asciiz "Hello"
world: .asciiz "World\n"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment