Skip to content

Commit

Permalink
gitignore fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Apr 15, 2024
1 parent ee9d248 commit 496be27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cairo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/

!/lang/compiler/lib/
Empty file.
18 changes: 18 additions & 0 deletions cairo/lang/compiler/lib/registers.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Returns the contents of the fp and pc registers of the calling function.
// The pc register's value is the address of the instruction that follows directly after the
// invocation of get_fp_and_pc().
func get_fp_and_pc() -> (fp_val: felt*, pc_val: felt*) {
// The call instruction itself already places the old fp and the return pc at
// [ap - 2], [ap - 1].
return (fp_val=cast([ap - 2], felt*), pc_val=cast([ap - 1], felt*));
}

// Returns the content of the ap register just before this function was invoked.
@known_ap_change
func get_ap() -> (ap_val: felt*) {
// Once get_ap() is invoked, fp points to ap + 2 (since the call instruction placed the old fp
// and pc in memory, advancing ap accordingly).
// Hence, the desired ap value is fp - 2.
let (fp_val, pc_val) = get_fp_and_pc();
return (ap_val=fp_val - 2);
}

0 comments on commit 496be27

Please sign in to comment.