SlideShare a Scribd company logo
1 of 11
Download to read offline
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x00
X 7 5 9
Y
We’re calling the max(7,5,9) function.
Arguments are placed in the X registers
and IP points to the first instruction in
the function.
We assume that we spawned a new
process just for this function call, so the
CP points to a special instruction that
will terminate the process normally
when the function returns.
In this example, all instructions have
been marked with fake addresses (they
ignore that operand also use memory),
that we’ll use with CP, IP and jump
operations.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x01
X 7 5 9
Y normal_exit ???
The allocate instruction allocates
one slot (1 is the first operand) on the
stack.
That means that we’re going to call a
function and one term will need to
survive this call.
The second operand says that there are
3 used X registers in case a garbage
collection is needed to complete this
instruction.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x02
X 7 5 9
Y normal_exit 9
Here we simply move the third
argument to the allocated slot on the
stack.
Note that it’s the top of the stack,
except the CP that was saved by the
allocate instruction.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP 0x03
IP 0x05
X 7 5 9
Y normal_exit 9
The call operation, jumps to another
function, that has been marked by the
label 2.
In order to do this, we set the CP to a
next operation in the current function,
and the IP to a first instruction in the
max/2 function.
Please note that we don’t need to
modify the X registers as the correct
arguments are already there.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP 0x03
IP 0x06
X 7 5 9
Y normal_exit 9
In this operation we compare
arguments in the X1 and X0 registers.
If X1 < X0 we simply advance the IP.
Otherwise we jump to the label 3.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP 0x03
IP 0x03
X 7 5 9
Y normal_exit 9
5 is less than 7, therefore we simply
advanced the IP.
The return instruction simply rewrites
CP to IP.
Please note that the result of this
function call is in the X0 register and we
don’t need to put it there as the result is
the first function argument

(max(7, 5) == 7).
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP 0x03
IP 0x04
X 7 9 9
Y normal_exit 9
Here we restore the argument we
saved on the stack.
At the same time we are preparing for
the second call to the max/2 function,
setting its second argument.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x05
X 7 9 9
Y
We’re calling the max/2 function for the
second time, but this time it’s more
tricky.
We don’t need to modify the result, so
we can simply do a tail-recursive call.
Therefore, instead of just jumping to the
function we need to do cleanup.
We clean 1 slot (third operand) on the
stack, we also restore the CP from the
stack and delete it.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x07
X 7 9 9
Y
We again compare the values of X1
and X0.
This time, X1 is not less than X0 so we
jump to the label 3.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP 0x08
X 9 9 9
Y
We’re preparing to return from the
function, by putting the result into the
X0 register.
{function, max, 3, 2}.
{label,1}.
0x00 {allocate,1,3}.
0x01 {move,{x,2},{y,0}}.
0x02 {call,2,{f,2}}.
0x03 {move,{y,0},{x,1}}.
0x04 {call_last,2,{f,2},1}.
{function, max, 2, 4}.
{label,2}.
0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}.
0x06 return.
{label,3}.
0x07 {move,{x,1},{x,0}}.
0x08 return.
CP normal_exit
IP normal_exit
X 9 9 9
Y
Now we can finally return from the
function and move to the original
Continuation Pointer.
The result is in the X0 register.

More Related Content

What's hot

Rules of derivatives 2.2
Rules of derivatives 2.2Rules of derivatives 2.2
Rules of derivatives 2.2Lorie Blickhan
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoChih-Hsuan Kuo
 
User defined functions
User defined functionsUser defined functions
User defined functionsshubham_jangid
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patternsTomasz Kowal
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Rick Copeland
 
Fighting null with memes
Fighting null with memesFighting null with memes
Fighting null with memesJarek Ratajski
 
PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsGraham Dumpleton
 
Javascript function
Javascript functionJavascript function
Javascript functionLearningTech
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Functionxxbeta
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Chih-Hsuan Kuo
 
2.7 chain rule short cuts
2.7 chain rule short cuts2.7 chain rule short cuts
2.7 chain rule short cutsmath265
 
Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Pablo Antuna
 
Lecture06 methods for-making_data_structures_v2
Lecture06 methods for-making_data_structures_v2Lecture06 methods for-making_data_structures_v2
Lecture06 methods for-making_data_structures_v2Hariz Mustafa
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functionsankita44
 

What's hot (20)

Rules of derivatives 2.2
Rules of derivatives 2.2Rules of derivatives 2.2
Rules of derivatives 2.2
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
 
Fighting null with memes
Fighting null with memesFighting null with memes
Fighting null with memes
 
PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating Decorators
 
Javascript function
Javascript functionJavascript function
Javascript function
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Function
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Refactoring
RefactoringRefactoring
Refactoring
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
2.7 chain rule short cuts
2.7 chain rule short cuts2.7 chain rule short cuts
2.7 chain rule short cuts
 
Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Lecture06 methods for-making_data_structures_v2
Lecture06 methods for-making_data_structures_v2Lecture06 methods for-making_data_structures_v2
Lecture06 methods for-making_data_structures_v2
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
c programming
c programmingc programming
c programming
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functions
 
Basic Mathematics
Basic MathematicsBasic Mathematics
Basic Mathematics
 

Similar to Erlang assembly

Storyboard math
Storyboard mathStoryboard math
Storyboard mathshandex
 
Introduction to functions
Introduction to functionsIntroduction to functions
Introduction to functionsElkin Guillen
 
domain, range of a function.pptx
domain, range of a function.pptxdomain, range of a function.pptx
domain, range of a function.pptxJohnmarkBaron
 
introduction-to-functions-grade-11general-math.ppt
introduction-to-functions-grade-11general-math.pptintroduction-to-functions-grade-11general-math.ppt
introduction-to-functions-grade-11general-math.pptPauline Misty Panganiban
 
Relations and functions
Relations and functions Relations and functions
Relations and functions Nabeel Simair
 
Functions and Relations
Functions and RelationsFunctions and Relations
Functions and RelationsJailah13
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to FunctionsMelanie Loslo
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Will Kurt
 
APPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONAPPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONDhrupal Patel
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
Functions
FunctionsFunctions
FunctionsJJkedst
 
Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Vanathi24
 

Similar to Erlang assembly (20)

Storyboard math
Storyboard mathStoryboard math
Storyboard math
 
Note introductions of functions
Note introductions of functionsNote introductions of functions
Note introductions of functions
 
Introduction to functions
Introduction to functionsIntroduction to functions
Introduction to functions
 
Fourier series
Fourier seriesFourier series
Fourier series
 
MLE Example
MLE ExampleMLE Example
MLE Example
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 
Relation and function pdf
Relation and function pdfRelation and function pdf
Relation and function pdf
 
domain, range of a function.pptx
domain, range of a function.pptxdomain, range of a function.pptx
domain, range of a function.pptx
 
introduction-to-functions-grade-11general-math.ppt
introduction-to-functions-grade-11general-math.pptintroduction-to-functions-grade-11general-math.ppt
introduction-to-functions-grade-11general-math.ppt
 
Relations and functions
Relations and functions Relations and functions
Relations and functions
 
Piecewise functions
Piecewise functions Piecewise functions
Piecewise functions
 
Functions and Relations
Functions and RelationsFunctions and Relations
Functions and Relations
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to Functions
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)
 
APPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONAPPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATION
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Functions
FunctionsFunctions
Functions
 
Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Very interesting C programming Technical Questions
Very interesting C programming Technical Questions
 
GENMATH-TOPIC1 (1).pptx
GENMATH-TOPIC1 (1).pptxGENMATH-TOPIC1 (1).pptx
GENMATH-TOPIC1 (1).pptx
 
Computer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipseComputer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipse
 

Recently uploaded

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Erlang assembly

  • 1. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x00 X 7 5 9 Y We’re calling the max(7,5,9) function. Arguments are placed in the X registers and IP points to the first instruction in the function. We assume that we spawned a new process just for this function call, so the CP points to a special instruction that will terminate the process normally when the function returns. In this example, all instructions have been marked with fake addresses (they ignore that operand also use memory), that we’ll use with CP, IP and jump operations.
  • 2. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x01 X 7 5 9 Y normal_exit ??? The allocate instruction allocates one slot (1 is the first operand) on the stack. That means that we’re going to call a function and one term will need to survive this call. The second operand says that there are 3 used X registers in case a garbage collection is needed to complete this instruction.
  • 3. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x02 X 7 5 9 Y normal_exit 9 Here we simply move the third argument to the allocated slot on the stack. Note that it’s the top of the stack, except the CP that was saved by the allocate instruction.
  • 4. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP 0x03 IP 0x05 X 7 5 9 Y normal_exit 9 The call operation, jumps to another function, that has been marked by the label 2. In order to do this, we set the CP to a next operation in the current function, and the IP to a first instruction in the max/2 function. Please note that we don’t need to modify the X registers as the correct arguments are already there.
  • 5. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP 0x03 IP 0x06 X 7 5 9 Y normal_exit 9 In this operation we compare arguments in the X1 and X0 registers. If X1 < X0 we simply advance the IP. Otherwise we jump to the label 3.
  • 6. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP 0x03 IP 0x03 X 7 5 9 Y normal_exit 9 5 is less than 7, therefore we simply advanced the IP. The return instruction simply rewrites CP to IP. Please note that the result of this function call is in the X0 register and we don’t need to put it there as the result is the first function argument
 (max(7, 5) == 7).
  • 7. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP 0x03 IP 0x04 X 7 9 9 Y normal_exit 9 Here we restore the argument we saved on the stack. At the same time we are preparing for the second call to the max/2 function, setting its second argument.
  • 8. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x05 X 7 9 9 Y We’re calling the max/2 function for the second time, but this time it’s more tricky. We don’t need to modify the result, so we can simply do a tail-recursive call. Therefore, instead of just jumping to the function we need to do cleanup. We clean 1 slot (third operand) on the stack, we also restore the CP from the stack and delete it.
  • 9. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x07 X 7 9 9 Y We again compare the values of X1 and X0. This time, X1 is not less than X0 so we jump to the label 3.
  • 10. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP 0x08 X 9 9 9 Y We’re preparing to return from the function, by putting the result into the X0 register.
  • 11. {function, max, 3, 2}. {label,1}. 0x00 {allocate,1,3}. 0x01 {move,{x,2},{y,0}}. 0x02 {call,2,{f,2}}. 0x03 {move,{y,0},{x,1}}. 0x04 {call_last,2,{f,2},1}. {function, max, 2, 4}. {label,2}. 0x05 {test,is_lt,{f,3},[{x,1},{x,0}]}. 0x06 return. {label,3}. 0x07 {move,{x,1},{x,0}}. 0x08 return. CP normal_exit IP normal_exit X 9 9 9 Y Now we can finally return from the function and move to the original Continuation Pointer. The result is in the X0 register.