Created
February 23, 2016 02:04
-
-
Save BGR360/4532ad7aac1da74a72d3 to your computer and use it in GitHub Desktop.
A quick example of how to write a function with parameters in E100 assembly :)
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
// Checks if var1 is less than var2 and stores the result in var3 | |
// Pass the arguments into the function | |
main cp less_than_left var1 | |
cp less_than_right var2 | |
// Call the less_than function | |
call less_than less_than_ra | |
// Store the return value in var3 | |
cp var3 less_than_result | |
var1 5 | |
var2 11 | |
var3 0 // Expected value: 1 | |
#include less_than |
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
// This function takes in two parameters, left and right, and returns 1 if left is less than right, 0 if not | |
less_than blt less_than_true less_than_left less_than_right | |
cp less_than_result less_than_num0 | |
ret less_than_ra | |
less_than_true cp less_than_result less_than_num1 | |
ret less_than_ra | |
// Function parameters | |
less_than_left 0 | |
less_than_right 0 | |
// Return value | |
less_than_result 0 | |
// Return address | |
less_than_ra 0 | |
// Local variables | |
less_than_num0 0 | |
less_than_num1 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment