This commit is contained in:
Mylloon 2023-12-31 23:16:39 +01:00
parent 57f67d98e6
commit e4b1d10007
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
8 changed files with 27 additions and 36 deletions

View file

@ -1,24 +1,8 @@
globals (x, y, z, k)
x <- copy 6;
%rdi <- copy x;
print_int();
%rdi <- copy " ";
print_string();
y <- copy 7;
%rdi <- copy y;
print_int();
%rdi <- copy " ";
print_string();
z <- mul y, x;
%rdi <- copy z;
print_int();
%rdi <- copy " ";
print_string();
k <- sub z, x;
%rdi <- copy k;
print_int();
exit;
end

View file

@ -1,11 +1,9 @@
globals (res)
res <- copy 1;
res <- mul res, 5;
res <- mul 1, 5;
res <- mul res, 4;
res <- mul res, 3;
res <- mul res, 2;
res <- mul res, 1;
%rdi <- copy res;
print_int();
exit;
end

View file

@ -1,4 +1,6 @@
globals ()
%rdi <- copy 42;
observe_int();
exit;
end

View file

@ -9,4 +9,6 @@ globals ()
%rdi <- copy %rax;
observe_int();
exit;
end

View file

@ -1,12 +1,15 @@
def fact ()
local n:
n <- copy %rdi;
%rax <- copy 1;
condition:
jumpif lte %rdi, 1 -> fin, boucle;
jumpif lte n, 1 -> fin, boucle;
boucle:
%rax <- mul %rax, %rdi;
%rdi <- sub %rdi, 1;
%rax <- mul %rax, n;
n <- sub n, 1;
jump condition;
fin:
@ -14,12 +17,12 @@ def fact ()
end
globals (x)
x <- copy 5;
%rdi <- copy x;
%rdi <- copy 5;
fact();
x <- copy %rax;
%rdi <- copy x;
observe_int();
exit;
end

View file

@ -1,26 +1,26 @@
def fact ()
local x:
jumpif lte %rdi, 1 -> fini, rec;
local n:
n <- copy %rdi;
jumpif lte n, 1 -> fini, rec;
fini:
%rax <- copy 1;
ret;
rec:
x <- copy %rdi;
%rdi <- sub %rdi, 1;
%rdi <- sub n, 1;
fact();
%rax <- mul %rax, x;
%rax <- mul %rax, n;
ret;
end
globals (x)
x <- copy 5;
%rdi <- copy x;
%rdi <- copy 5;
fact();
x <- copy %rax;
%rdi <- copy x;
observe_int();
exit;
end

View file

@ -20,4 +20,6 @@ globals ()
%rdi <- copy %rax;
observe_int();
exit;
end

View file

@ -549,7 +549,7 @@ module FrameManager (IS : InstructionSelector) : FrameManager = struct
;;
let call fd ~kind ~f ~args =
(* TODO: je segfault.. *)
(* TODO *)
(* Appelle la fonction *)
[ T.Instruction (T.calldi ~tgt:f) ]
;;