Commit 4291a160 authored by Martin Pépin's avatar Martin Pépin
Browse files

Syscalls work !

parent 78bc7b0f
......@@ -8,11 +8,11 @@ let sys_input_int () = Scanf.scanf "%d " (fun x -> x)
(** Prints the string starting at start_addr in RAM on stdout.
The string must end with \000. *)
let sys_print_str rom start_addr =
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 rom !addr in
let c = Ram.int_of_bits @@ Ram.get_byte ram !addr in
current_char := c;
incr addr in
while (read_char () ; !current_char <> 0) do
......@@ -40,7 +40,7 @@ let syscall ram rom =
match v0 with
| 0 -> 0 (* a dummy syscall *)
| 1 -> reset ram ; sys_print_int a0
| 4 -> reset ram ; sys_print_str rom a0
| 4 -> reset ram ; sys_print_str ram a0
| 5 -> reset ram ; sys_input_int ()
| 10 -> reset ram ; sys_exit ()
| n -> failwith @@
......
.text
main:
addi $a0,$zero,21
addi $a0,$a0,21
addi $a0, $zero, 42
addi $v0,$zero,1
syscall
nop
addi $v0,$zero, 10
la $a0, hello
addi $v0,$zero, 4
syscall
addi $v0, $zero, 10
syscall
.data
hello: .asciiz "\nHello, 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