-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |