Implemented iterative fibonacci in X86Lite. Done with HW2.

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-02-02 01:20:57 -08:00
parent 1a122c85b8
commit 9556695bed

View file

@ -67,6 +67,44 @@ let crack_tests =
]
let fib_rec n = [ text "fib"
[ Cmpq, [~$1; ~%Rdi]
; J Eq, [Imm (Lbl "exit1")]
; Cmpq, [~$2; ~%Rdi]
; J Eq, [Imm (Lbl "exit2")]
; Movq, [~$0; ~%R08]
; Movq, [~$1; ~%R09]
; Movq, [~$2; ~%R11]
]
; text "loop"
[ Cmpq, [~%Rdi; ~%R11]
; J Eq, [Imm (Lbl "exit")]
; Movq, [~%R09; ~%R10]
; Addq, [~%R08; ~%R10]
; Movq, [~%R09; ~%R08]
; Movq, [~%R10; ~%R09]
; Addq, [~$1; ~%R11]
; Jmp, [Imm (Lbl "loop")]
]
; text "exit"
[ Movq, [~%R09; ~%Rax]
; Retq, []
]
; text "exit1"
[ Movq, [~$0; ~%Rax]
; Retq, []
]
; text "exit2"
[ Movq, [~$1; ~%Rax]
; Retq, []
]
; gtext "main"
[ Movq, [~$n; ~%Rdi]
; Callq, [~$$"fib"]
; Retq, []
]
]
let provided_tests : suite = [
Test ("My Tests", [
@ -77,7 +115,9 @@ let provided_tests : suite = [
Test ("Student-Provided Big Test for Part III: Score recorded as PartIIITestCase", [
("fib", program_test (fib_rec 7) 8L);
("fib", program_test (fib_rec 8) 13L);
("fib", program_test (fib_rec 9) 21L);
]);
]