[Music]
g'day folks and welcome to tutorial one
one sixty four-bit assembly
I've written a bit of a spiel here on
why I use assembly called who's afraid
of Big Data sembly now you can pause
that and give it a read if you like it's
a bit too long for me to say but I
really want to concentrate on showing
programmers that X 64 isn't a scary
language at all it's really easy it's
extremely powerful it's ridiculously
fast and if most of you are familiar
with object-oriented programming
languages only then it's a real
eye-opener I'll be using visual C++ 2010
Express Edition which you can download
free from Microsoft but if anyone cares
all of this stuff is easy enough to do
in Linux with the net white assembler
and the gnu compiler okay off we go I've
got visual see if it's flashing sorry
about that I don't know what that is
something about the screen recorder okay
what we do we go file new project empty
project will do you're going to call it
tutorial one okay
now we don't need these directories I
usually just delete them yes and we're
going to add our main C++ file call it
main okay we're going to include
iostream or see the output again include
college age using namespace STD
[Music]
catch that's what we got from Conneaut
h0 okay so I just look gets there so me
[Music]
okay first of all we're going to do some
inline 32-bit assembly we're going to
get a single value from from a function
within line 32 disassembly awesome said
awesome okay so we got to write this
function now get value from Assam and
it's going to return a single int and
we're printing it out just to prove that
we're getting a value from Assembly int
get the value on awesome here's our
function now to get into 32-bit assembly
or inline assembly all we do is it will
be underscore a s and keyword and we
open up a code block anything within
these two braces is 32-bit assembly how
do we return an integer from 32-bit
assembly off it's very easy all we do is
we move a value into EAX the ax is a
variable on the CPU it's one of the
registers if you move 39 into EAX by the
time the function closes that's what's
returned so multi ax 39 is functionally
equivalent to that body now we run our
program and see what happens
[Music]
now we go awesome said $39 good that's
just what we told him to say okay that's
thirty two-bit inline assembly I'm not
interested in thirty two-bit inline
assembly I want to show you guys how to
do sixty four-bit assembly so the first
thing that we've got to do is change our
project from 32-bit to 64-bit defaults
to 32-bit so we've got to change it we
go up here to solution platforms we
click configuration manager and in the
platform column click new and everything
should be selected here already to
change our project to 64-bit copies
things from there we have new solution
platforms we pick ok and close now we
have a 64-bit program we try and run it
bang we've got problems what's happened
well the kind folks over at Microsoft
decided the inline assembly wouldn't be
supported for 64-bit so as soon as we
change our project to 64 bits we can't
use inline assembly anymore it's all
function is gone we've got to add an
assembly source code file to our project
and compile that and link it how do we
do that well
[Music]
the first thing that we've got to do is
tell the program or tell the compiler
that it can't use the C++ compiler to
compile assembly files it's got to use
Masum the macro assembler and we do that
by right-clicking on our solution up
here and clicking on build
customizations then you should see a box
here with Masum and dot target's dot
props we want to check that box that
means whenever the compiler comes across
a file with a dot ASM extension it's to
use the macro assembler to compile it
instead of the C++ compiler ok so we
check that box and click OK now we're
ready to add our assembly code file we
do that by right clicking on tutorial
and adding a new item just as before
only we select the C++ file here but
down the bottom aha dot ASM we give it
an awesome extension that way the macro
sent macro assembler compiles it not the
C++ compiler click Add here we are in
our new assembly file
so how do we write this function in pure
x64 assembly well it's in what's called
the code segment and the function is
called get value from Assam it's a proc
two procedure so we say proc then put
our function body which was and I'm
moving something Dax melting TX that
returns P so that's the start of our
procedure that's the end of our
procedure end P and finally that's the
end of our assembly code file so that's
the whole function almost the same as
using inline assembler we come back to
our main file and we can run what what's
happened get value from Assam isn't
defined we're not linking it to a C++
file yet it's just compiled as an object
file
so we've got to link it how do we do
that well say it's an external I'm sorry
what we've got to do is add up function
prototype to our C++ file so the
prototype for this function is that it's
external it returns an integer and it's
called get value from awesome friend
there you go Oh worries he reckons it's
all good
why did we hit play still problems
what's happened well what's happened is
that C + + has mangled the name that
it's looking for instead of looking for
get value from assam it's added things
to this name to reflect that the
function returns an integer and that it
doesn't take any parameters this is
called name mangling and it's to do with
the C++ calling convention but we don't
want it to make learning names so we've
got to tell it that this function hasn't
got a mangled name it's just called get
value from assam we do that by saying
that it uses the c calling convention c
calling convention doesn't mangle names
so c++ will now be looking for exactly
get value from Assam which is a name of
a function body we hit play now we go to
seven eight three two seven eight three
I think that's more than a coincidence
let's have a look
[Music]
there we go folks this is a 64-bit
assembly function and it's being called
from a C++ program in a later tutorial
I'll go through all of the parts of the
64 bit assembly program but for now
thank you for listening
[Music]