SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
{function, max, 3, 2}. %% max/3
{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}. %% max/2
{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 assigned fake addresses, that
we’ll use for demonstration purposes.
{function, max, 3, 2}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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}. %% max/3
{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}. %% max/2
{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.

Weitere ähnliche Inhalte

Was ist angesagt?

The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181Mahmoud Samir Fayed
 
Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Pablo Antuna
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196Mahmoud Samir Fayed
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patternsTomasz Kowal
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYvikram mahendra
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methodsphil_nash
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
2.7 chain rule short cuts
2.7 chain rule short cuts2.7 chain rule short cuts
2.7 chain rule short cutsmath265
 
11. Linear Models
11. Linear Models11. Linear Models
11. Linear ModelsFAO
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84Mahmoud Samir Fayed
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFabio Collini
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency APISeok-joon Yun
 

Was ist angesagt? (20)

The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2Derivatives of Trigonometric Functions, Part 2
Derivatives of Trigonometric Functions, Part 2
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212
 
R programming
R programmingR programming
R programming
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196
 
redes neuronais
redes neuronaisredes neuronais
redes neuronais
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAY
 
Calc 2.4a
Calc 2.4aCalc 2.4a
Calc 2.4a
 
Calc 2.4a
Calc 2.4aCalc 2.4a
Calc 2.4a
 
Data aggregation in R
Data aggregation in RData aggregation in R
Data aggregation in R
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
2.7 chain rule short cuts
2.7 chain rule short cuts2.7 chain rule short cuts
2.7 chain rule short cuts
 
11. Linear Models
11. Linear Models11. Linear Models
11. Linear Models
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 

Andere mochten auch

Andere mochten auch (20)

CNN Presentation
CNN PresentationCNN Presentation
CNN Presentation
 
Datomic
DatomicDatomic
Datomic
 
Datomic
DatomicDatomic
Datomic
 
Datomic
DatomicDatomic
Datomic
 
Tesco
TescoTesco
Tesco
 
Selena Gomez
Selena GomezSelena Gomez
Selena Gomez
 
French Property Market 2014
French Property Market 2014French Property Market 2014
French Property Market 2014
 
論文紹介: Fast R-CNN&Faster R-CNN
論文紹介: Fast R-CNN&Faster R-CNN論文紹介: Fast R-CNN&Faster R-CNN
論文紹介: Fast R-CNN&Faster R-CNN
 
intel core i7
intel core i7intel core i7
intel core i7
 
Oprah Winfrey
Oprah WinfreyOprah Winfrey
Oprah Winfrey
 
Clojure
ClojureClojure
Clojure
 
Medical devices
Medical devicesMedical devices
Medical devices
 
French Property market 2015 - Cushman & Wakefield
French Property market 2015 - Cushman & WakefieldFrench Property market 2015 - Cushman & Wakefield
French Property market 2015 - Cushman & Wakefield
 
Bill Gates, Who is he?
Bill Gates, Who is he?Bill Gates, Who is he?
Bill Gates, Who is he?
 
Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014
Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014
Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014
 
In memory computing
In memory computingIn memory computing
In memory computing
 
Reverse Engineering
Reverse EngineeringReverse Engineering
Reverse Engineering
 
The big bang theory
The big bang theoryThe big bang theory
The big bang theory
 
Chess
ChessChess
Chess
 
Product management
Product managementProduct management
Product management
 

Ähnlich wie Erlang assembly

Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
Storyboard math
Storyboard mathStoryboard math
Storyboard mathshandex
 
Introduction to functions
Introduction to functionsIntroduction to functions
Introduction to functionsElkin Guillen
 
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
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxgilpinleeanna
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to FunctionsMelanie Loslo
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
Functions and Relations
Functions and RelationsFunctions and Relations
Functions and RelationsJailah13
 
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
 
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
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab
 

Ähnlich wie Erlang assembly (20)

bobok
bobokbobok
bobok
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
MLE Example
MLE ExampleMLE Example
MLE Example
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
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
 
Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Very interesting C programming Technical Questions
Very interesting C programming Technical Questions
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to Functions
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Functions and Relations
Functions and RelationsFunctions and Relations
Functions and Relations
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 
Mat lab day 1
Mat lab day 1Mat lab day 1
Mat lab day 1
 
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
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 

Kürzlich hochgeladen

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Kürzlich hochgeladen (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Erlang assembly

  • 1. {function, max, 3, 2}. %% max/3 {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}. %% max/2 {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 assigned fake addresses, that we’ll use for demonstration purposes.
  • 2. {function, max, 3, 2}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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}. %% max/3 {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}. %% max/2 {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.