Hello, this is Dr. Miller, and this
is Episode two point two of
Assembly.
Today, we're going to talk about
logical operators and the memory
hierarchy,
logical operators.
So we have four logical operators
that we're going to talk about
today. And these all operate on
binary data.
And this is how computers will
do different types of operations
that a computer needs to use.
So we have and so with.
And if both bits are one,
then one is the result and
zero otherwise, or
if either a bit is a one,
then one is the result and zero
otherwise.
So if they're both zero, then you
get a zero.
Not every zero becomes a one
and every one becomes a zero.
And then X or if the bits are
different, the result is a one and
then we have a zero otherwise.
So let's do an example for each
one of these. You should try and
figure out what it is before I go
through it.
So bitwise. And so if
both of them are one, our result
is a one.
If both of them are a zero or
one of them is a zero, sorry,
then our results is going to be a
zero. So we can see that these two
should be one and the rest of these
should all be zeros.
Bitwise or.
Again, try it on your own.
So with a bitwise or if either
one of them is a one than our result
is a one. So we have a one, a
one one one
one zero.
A one and a zero.
For not every zero becomes a one
and everyone becomes a zero.
So here's our number and we just
have one that we're not knotting.
And so everything has been flipped
just like we did when we talked
about TEUs compliment
and then X or so
with X or if they are different,
then we get a one.
So they're not different.
They're not different.
They are different.
Right.
There I see these two are
different. These are not different,
these are different, and these are
not different.
And so there's our result,
one of the interesting things with
EXER is that if you take
and do the reverse, then
we end up with the same result.
So if I take a
and I saw that with result.
I end up with B
and one and zero becomes one,
one in zero becomes one zero
and one becomes one.
So these are different and then
these are all the same.
And so the reason why we talk about
X or is X is used
in encryption and encryption.
So if A is
our key and B is
our text that we want to encrypt,
we saw them together and we end
up with our encrypted result.
And then to reverse the operation,
we take our key and our encrypted
result.
And we saw them together and we
end up with our plain text data.
So let's go ahead and try and do an
example with this.
So I'll go ahead and build a
project.
So we'll just move some data into
some of these registers.
Now, let's try this.
For example, before we had a.
And we can try some Xeros.
And then we can go ahead and do
a logical operator on it, so
let's, for example, do X or.
I can type
so this will do an X or of X
and SBX and instore will result
in X.
And then I can print out of my
registries are so let's go ahead and
print them before.
Go ahead and write in my file.
Oh, I made a mistake.
So because these
start with letters and things that
they are identifiers, so if you have
a number that starts with letters,
you need to put a zero in front
of it.
All right, and then I had to put a.
H at the end to tell that these
tell the assembly that these are
hexadecimal members, it was getting
confused, thinking they were four
decimal numbers.
All right.
So we've built our project, if we
do, unless we
can see that.
We have our resulting
binary.
And so we can see what a looked like
it has the value that we moved into
it, we can see what B look
like, and then it did the EXER
and we ended up with the result
in X, and
so we got sixes
and then B's xieng something
was zero. You end up with that thing
again. But if we X or
ANC, we
get the number six.
And so you should go ahead and try
that on your own.
If you get out a pen and paper
and try a different result
and then put it into your program,
build it and then run it and you
should see your result.
All right, the memory hierarchy,
so with eighty six processors, we've
talked about that there is a
arithmetic logic unit or ALIYU
that can do mathematical operations.
We also have our floating point unit
and then we have things like the
database. So this is how data gets
moved from one location to another.
It is a shared communication medium,
meaning that multiple
processors might have to use the
same medium.
We have registers which we've talked
about. These are small and very
fast. They run at the clock
rate of the sister and
the system and the clock
is it has what
are called cycles.
A cycle is the smallest amount of
time that you can execute a single
instruction.
Now there are some instructions that
take more time than others.
And so they might be
a repeat instruction, might go over
and over again. And so it might take
more than one operation or some of
the multiplication takes
longer than doing, for
example, shifting.
And then recently we've it's come to
light about branch prediction
and how that has been used
to do different attacks.
And so branch prediction means
that the processor is going
to basically guess which branch,
when we talk about branching, which
branch is the most likely to
be used, and then it'll
automatically execute that before it
actually knows the result of the
previous operation.
And so we have a hierarchy of
of access times for our memory.
So, again, registers are in the one
nanosecond to two nanoseconds.
So these are as fast as we can go.
And then we have these caches in
here. And so these caches are faster
than main memory, but they're
slower than the registers.
And so they act as a buffer to
where you can read data into the
cache and then reread it over and
over again without having to go
to memory.
So one of the things to note here is
that, for example, if you're looking
at two nanoseconds for a register,
access and main memory
is 90 nanoseconds,
then it is much, much slower
rate than a register.
And so loading data from main memory
is very slow in comparison to
loading it from the registers.
And then you start getting into
things like hard drives, which are
quite slow or taped
back up and they don't list.
Even here, it could be on the
network. Right.
So when you're pulling code from the
network, it has to go all the way
out to the Internet and come all the
way back.
And so in order to make our
processors as efficient as possible,
we want to use the fastest
amount of memory that we can at
any time.
And so it's fundamental to try and
keep these caches
cohesive and having the right data
in them such that our result
is going to go as fast as possible.
We can do as much processing as
possible in that machine.
So, again, this cycle is we're going
to fetch. Well, it actually
has to load it from somewhere.
So you're executable
might be on the Internet, so you
download it to your hard disk and
your hard disk is going to be where
you would cash it for a little
while.
And then when you want to run it,
you might loaded into RAM or main
memory.
And then as it's executing on the
processor, the OS will
load different parts into these
different caches, level one, level
two and level three.
And so that way, if it just keeps
going back to that level one cache,
I don't have to go all the way to
main memory or all the way to the
hard disk, which are extremely slow.
And then after you've fetched it,
then you go ahead and decoded and
execute it and then you store it.
And that storage might be in cash
and might be in RAM.
It might be on your hard disk or the
Internet.
Right. And so we have to go through
all of these different hierarchies
when we're executing instructions on
the front end and then on the back
end. In the middle, it's just all
running on the processor.
And then when you have a program
like we did in our example, right,
that's actually stored on disk
and so the operating system is going
to search what's called the path,
and the path is going to tell it.
Where do you look for programs?
So, for example, most Linux systems
have been or slash user
slash been.
And so the OS will look in those
places for an executable.
So when you say else, it's
going to look in the bin and see
is there an LS command in the bin
folder? If it exists,
then what it does is it takes that
program, it loads it into RAM
and then it creates a process for
it. It's a process as a PID
or process identifier that
says which process that is.
So if your program goes haywire
and is not working, then you can use
things like kill in order to stop
that process.
So that way you know which process
it is. And there might be 20 people
running BASCHE Right.
And so if they're all running back,
I need to know which process
identifier of Basche it is that I
want to kill.
And so once it's loaded that process
and created it, then it starts
executing it and every
process thinks that they are unique,
so they think that they are the only
one running on the processor.
So they think they have access to
all the memory and all the
instructions. Now, that's not
really true, but that's the way we
conceptualize it.
And then generally the operating
system will handle the resources
like this guy.
So reading and writing from disk,
reading data and writing data,
reading data from the keyboard,
moving graphics into the display,
or at least onto the graphics cards,
then they can be put on the display
and then switching between different
tasks that are running.
So when we switch between tasks, the
OS sort of automatically does
this.
It switches between processes really
fast. So back in the day,
there were only a single core
processors.
And so in order for you to be
watching a video and typing on
a word processor at the same time,
the OS would switch rapidly back
and forth, ping pong right back and
forth, and then processors
might be waiting.
And so then other processors can
run. So, for example, a
process might try to read data from
a disk or write data to a network
or wait for the user to type in
something.
And so if those are waiting, then it
goes ahead and executes some other
process that has some work that
needs to be done.
And then the OS will generally have
a priority list saying
what processes are high priority,
what processes are low priority.
And so if something high priority
comes in, it'll automatically
execute that and pause
low priority.
So, for example, if you're watching
a video, you probably want that to
be high priority.
But if your computer is doing an AV
scan, you might want that to be low
priority.
So when I'm not using my computer,
great run a Navy scan, but if I'm
watching for a video
on Netflix, I want that to be very
high priority.
And when it switches these tasks,
it saves water called the context.
So the context is basically the
state of all of the different
registers.
So we've talked about registers like
Xbox,
so it saves those values and then
loads a different processes,
registers into memory, and
then it starts running of that new
process.
And then there's been a lot of talk
in the past about risk versus
risk. So risk is the reduced
instruction set computer and
risk is the complex instruction
set computer.
So generally we see a intel
processor as the complex.
Right. So we have larger op codes.
We have a lot of instructions, but
we have fewer instructions
that do things right.
So there are lots of complicated
instructions.
And so, for example, there's lots of
multimedia instructions or
multiple data instructions.
And so we can run one instruction
instead of running 20.
But the reduced we have smaller op
codes and we have more instructions.
And so this tends to be armed.
And so a lot of our desktop
computers are Intel and they
use a lot more power than these
Cesc arm processors, which
have smaller op codes, which means
they have less transistors,
which means that they actually use
less power.
And so that's why cell phones and
iPads have really
good battery life, because they're
running a reduced instruction set
that consumes less power
per instruction than it has to
execute.
So in summary, today, we talked
about Lodrick operators and then the
memory hierarchy
looking forward, we're going to talk
about segments and functions and
calling functions that are built
into our libraries.
If you have questions, you can
contact me at Miller, MJ At and
Edu and on Twitter.
I'm at Milhouse 30.