Hello, this is Dr. Miller, and this
is Episode two point one of
Assembly.
Today, we're going to learn about
assembly language and suddenly an
assembly instructions, identifiers,
directives, and then creating
a listing of a file
assembly language.
So machine language is the low level
that a machine uses
in order to execute instructions.
And so, for example, if we would
like to add Etext SBX
and then store the result in X,
we would run the machine
instructions zero three C
three.
Now, clearly that's not very
readable and it changes with
different processor types
and so a better language
is needed and that language is
assembly.
So given the machine language
zero three C three, in order to do
the movement of data,
we have the assembly language add
yet SBX.
So this will add those two registers
together and then store the
result in X.
Now clearly this is more readable
and it is a higher level language
than writing something in
binary in hex
from a previous lecture, you should
recognize that this is Hex given the
zero X and the letter C
in there.
And then we have four different
architectures.
We can keep the same code and
end up getting the right result.
Additionally, optimizations can be
made. So if you have a code that is
not working or is not needed, the
assembler and or compiler
can get rid of those or
pick a different instruction at the
low level, that will be faster.
And then the format of an assembly
instructions is we have a pneumonic
or something that you can remember,
and then that is followed by
operands.
Now, there is a difference between
an assembly line and a compiler.
So with an assembler, generally,
there's a one to one ratio of
assembly instructions
to machine code
and an assembly is machine
dependent. So if I write something
in assembler four x eighty six,
I have to write a completely
different code for ARM or
Fassbach, whereas
if we have a compiler again, it's
one higher level abstraction
and so one high level line
to create a variable
or move. Some data might generate
many machine and assembly
instructions, but
the benefit of it being higher level
is that it's more portable.
So you can write something and see
and if you have a compiler, it can
compiler to X eighty six code or
a compiler to arm code
and you don't have to change the
the high level code.
Now this is not always the case, but
generally it is the case.
So the assembler we're using for
this class is Nazim, and
so with that, we are
actually underneath it using the new
compiler collection.
So this is a compiler that will
compile code.
And then we're also using the C
programing language to interface
with GCC.
And then we should also be using
make, so that's part of our template
uses make in order to build
the program.
Assembly instructions.
So, again, we have a pneumonic and
then that is followed by operand, so
the mnemonic is add, whereas the
operands are what it's going to
do, that operation on.
And we have three general types.
So we have registers, as
we saw yak's SBX
are registers memory
locations, which we'll look at later
and intermediate value.
So that's an actual value that's
hard coded inside of the binary.
Additionally, we do have implied
so, for example, an increment
will affect a register
by default, so it'll add one
to that register or
decrement will decrease the register
by one.
So example instructions, so we
have our mnemonic, which is move,
and then we have the Register SBX
and we also have the the
hard coded values seven.
Right. So the seven is an immediate
and then SBX is
a register.
Here we have to register so into
Ebix, so this says that
SBX is value is going to go
get copied into X
or increment X or decrement
X, so those again, would increment
or decrement that register.
And the way that instructions are in
Nazem is that we have an optional
right, so the brackets mean
optional. We have a label
followed by a mnemonic, so we have
to have a mnemonic.
And then if a mnemonic doesn't have
implied operands, we need some
operands and then we have an
optional comment.
And so here are some example.
Mnemonics, move, add,
sub moule, jump,
call.
Notice that they aren't necessarily
spelled right. So there's no eone
move.
Jump doesn't have a you,
but those are examples of mnemonics
and then all of the Marnix that will
learn and then comments.
So a comment starts with
a semicolon.
So if you're used to programing and
C you might just
put a semicolon at the end of your
statements, but that is a
Nazeem comment.
Directives, so directives
are not actual instructions, they
just tell the assembler that you
want to do something, you want
it to, for example, set the size
of the stack, define some memory,
define some constants.
So directives are are for humans
to make things easier, but
they aren't actual assembly
instructions.
So, for example, percent define.
So if you've programed in a language
like C Pound define allows us
to create constants.
So also percent define
does so says percent
define size 10.
So every place that we'll see size,
it just replaces it with the actual
value of ten.
So this instruction would be
the same as movie 10.
We have data directives, which we
will have to do a lot of,
and so the D stands for
defined. So we've got to find a
bite, define a word
and define a D word.
I remember a bite is one bite, which
is Apitz.
A word is two bites
or 16 bits.
And a double word
is thirty two bites.
Identifiers,
so throughout the course, you're
going to be creating different
variables or identifiers,
and so we need to know how to
define them and what are actually
allowed.
So we use them for variables,
constants, procedures
or functions and
labels.
And so the main
key here is that you
need to start your variables
basically with a letter.
So that's the the easiest way
to start it. And then you can add
some of these additional characters.
But generally, most of my variables
would just have letters, possibly
numbers within them and then
maybe underscore is to make things
more readable.
All right, so here are some examples
of addition and subtraction, so move
into X 100 in hex,
add four hundred X,
so one plus four should give us
five and then subtract
X two hundred X.
So that should give us three hundred
and hex.
So if you open up your
editor you can type this code
in and see what the result is.
The dump regs one, we'll just
print off what all the registers are
and then it puts a number one in
front of it. So it does
hash tag number one.
And so you can call numbers multiple
times and you'll see
each one of those.
You can put a different number in
there.
So if you have the template already
set up, I would go ahead and pause
the video and I would enter this
in and see what it produces and
maybe change the numbers in here and
see if you get a different result,
generating a listing.
So listing will give us information
about offsets and
binary code for commands,
and it also will help us when we are
trying to find errors.
So this is to tell
us that we are using the program.
Nazeem, we are using LTH because
I'm on Lennix, I'm naming
the listing and then this
is the example that I want
to do for it.
So I'm going to go ahead and switch
to a
terminal window and go ahead and do
that.
So I'm going to create my project
here.
I'll just call it two point one.
So now if I look inside my directory
of my projects, so I already
entered that before I started, I
have a directory called two point
one.
And now I should have my assembly
file, so I'll go ahead and edit it.
And so let's put some
code in here.
So I'm just going to move the value
of negative 10 into yak's,
maybe I do another one.
I'll go ahead and write and quit,
I can run make in order to make sure
that my program will
assemble and compile
so you can see right make is the
program that we've been using.
It's running the command, Nazeem,
and it's also running in order
to generate our output.
And then the driver see is
the the program that
provides the skeleton so that our
program can run.
And so if we want to generate a
listing.
All right, so Nazem minus F.L.
So that's the type of executable
minus L is the listing file that
we're going to generate and then two
point one to ASM is a file that I
want to use for that.
So now I can look at that, I can use
a program like Cat,
which means concatenate or print to
the terminal.
So we can see and hear that,
ah, this is our assumption
and we can see the different
instructions, so.
The instruction to move something
into X
is this B eight
and then we can see we've got a
bunch of F's and a six.
So again, remember that this is
stored in twos complement, which we
talked about in a previous lecture.
So and it also stores it a little
bit backwards.
Right. So the first
byte is right here.
The second byte is right here.
The third byte is right here in the
fourth byte is right here.
And we'll talk about in in
subsequent lectures about little
Indian versus big Indian and why
it looks like this.
But this is the actual number,
negative 10 stored in two's
compliment, and then we can see that
in Hex in our
listing or the number 20.
So 20 is 14
and hex.
All right. It's a 16 plus a four.
And then we can see minus 30.
So if you want practice on your
twos, complement, pick a number
that you want to do.
So say negative seventy
six and try and figure out
what it's binary representation
is, figure out what it's hexadecimal
representation is, and then go
ahead and convert
it and then build a program
that does it generate a listing and
then you can see what the result is.
So here is an example that I had run
before.
Again, you see the bait, which is
move something into X
and then we have the numbers zero
one, which is the number one.
Additionally, we have commands that
we can run in order to view data
that's in an executable, so
like a listing.
So HSD is going to give us raw
hex by default.
It prints the actual data that's in
the file and also
can convert from its
its output back into binary
if you need to.
So, for example, my executable
is called two point one, so
I can say it's sixty
two point one.
In all of the raw bites
and we can actually see some ASCII
characters in our
file that represent
different things that are included
inside of the binary file.
So that's kind of interesting.
Additionally, we can run object
dump, so this will print off the
disassembly of a binary program.
And so if you have a binary program
that you want to look at and you
want to see the assembly of,
we can run object.
So object dump and then we
are using intel syntax.
So you need to set the disassemble
options to Intel.
The minus D is to do disassembly
and then edit out is the name of the
program that you want to run it on.
So let's go ahead and run it on our
program.
And so you can scroll through here
and you can look at the actual
disassembly of that program
or the assembly that
a or figure it out.
So this assembly is just a program
that is going to go
and convert all of the
the functions and the data into
assembly code.
So we can see here that we put
in our numbers as negative numbers
or positive numbers.
And the disassembly is going to show
us that raw number and not
necessarily the
number in Base 10 that we are used
to.
All right, so in summary, we learned
about assembly language and assembly
instructions, identifiers
and directives, and then creating
a listing of a file and looking at
the contents of a file that
you might have that you want to look
at.
Looking forward, we're going to talk
about logical operators, segments
and functions,
if you have questions, you can
contact me at Miller, MJ, at you
and Keda, Edu, or you can find
me on Twitter at Milhouse 30.