Hello, this is Dr. Miller, and this
is Episode five point two of
Assembly.
Today, we're going to be talking
about more arithmetic shifts,
including double precision, and
we'll give an example.
So arithmetic shift.
So last time we learned about
the normal shift or we just shift
the bits and we don't care about
if the thing is assigned number
or not.
And so we
they invented the arithmetic shift
or sine shift.
And so it's like the logical shift,
except for we make sure
that we keep track of the sign
so that our number doesn't change
when we divide by two or multiply
by two or power of.
And so we have shift arithmetic
left and shift arithmetic right.
And then we also have our double
precision shifts and we'll see those
in a little bit.
So double precision.
So the double precision shift,
we can use S.H.
LD to denote
that we're going to do that.
And we basically have a destination
where we have the bits that are
going to get shifted the source
and then how much count and the
sources used to fill in the bits.
And so if you need to fill them in
with ones or need to fill them
in zeros, you would set source
appropriately.
And either one of these.
So let's do an example, so we'll
prompt the user for a couple numbers
and then we'll get the amount to
shift and then we'll shift it
and then we'll print off the result
and we'll do some testing with
both positive and negative numbers.
All right. So I've logged on.
And so if we run, Jen,
make five point two, which is the
lesson, it'll generate a folder for
us so I can see
all my folders.
Go ahead and enter
the current directory.
So what I want to do is I'm going to
get a couple of different prompts
for the user again so that they know
what we're doing.
And these are bite's.
Put my colon in here to make it look
nice. Make sure I know, terminate
it.
Again, putting a colon to make it
look nice and know,
terminating that.
Let me get down here in our main.
So in here, we'll go ahead and
we have to put our prompt into X
once again.
All print string,
which will print off the string that
is pointed to by
X,
and then we'll go ahead and call
read it.
And so this is getting the
shift amount and then we're
going to have to move that somewhere
else. So I'll go ahead and use X
and remember the call to read
it is going to read a value and then
store it in X..
And so I copy it from X into
X
and I can print on my second prompt.
It looks like I spilled
prompter on.
So
there we go,
so move it into yak's and
then that's what I can use to call
print string and then I'll once
again call
Reed
and to get a number from
the user.
All right. And so now this is the
part where I'm going to want to do
my shifting.
So I can do shift
arithmetic left.
I see Yak's is our number,
and then the amount we want to move,
it will have stored in we started
an X which remember
is broken down into six
and then see X is further broken
down into S.L and S.H.
And so we'll just use the little
bits in s.L.
I'll go ahead and call dump regs
so we can see what the registers
look like after we do that.
And then I want to print my own
result. So my result
is an X, but I want to print
a string
saying the result. So let's go ahead
and put a
prompt here,
saying the
result.
No terminate that
can back down here.
So since I'm going to print it, I'll
go ahead and I'm going to have to
use the ax in order to print that
string. And so I'm just going to
copy.
My value into
SBX and so that we will have
it stay saved, so when we go to
print, it will be there and want to
move it back into X, so
move the X
result, which is my prompt.
OK.
Now, I got a copy back into yak's
and stored in Ebix
currently.
All right, so
that should be my program.
Looks like I typed it right.
So now you can go ahead and run it.
So let's say we're going to shift by
two, which is going to
be by for
two to two
or two squared is four.
And so we'll start off with an easy
numbers. Let's do just 20.
All right, so 20 times four
is 80,
but what if we do
two and negative
20?
All right, so we can see that our
sign got kept right?
So when we did our shift, the sign
is the same now multiplication,
right. Is going to shift it over one
way. If we want to do division,
we can go ahead and edit this
and we'll go down to the line
where it says shift left and we can
change that into a shift.
Right.
Go ahead and build my project.
Run it.
And so now if I do so, let's let's
do an example of dividing by four
and we'll do negative 50,
right. And so we're shifting
normally when we shift in this
direction.
Right. These FS, if we use
a regular shift, those are not going
to get filled back in with FS.
And so when we're doing the
arithmetic shift, it's as if that
bit is a one.
Then when you do the shift, you fill
it in with one's.
And so and then it also works if we
do positive numbers, so do two
and 50,
and then we can see when we divide
it by four fifty, divided by four
is twelve and a half.
We got it rounded up to 13
or rounded down to 12.
And so those are just some issues
you have to take into account,
right. If you're doing a whole no
division. And so we just lopping
stuff off and we're not actually
keeping track of it.
Later on, we'll learn about floating
point and how we could get more
exact numbers than this.
And then we're also going to look at
so we can use
the additional way of shifting.
So using the double precision.
So.
In this takes so we'll still use
X, but then we'll want to move
something into another register,
so let's say we use SBX.
So if we got positive numbers, we
can just use zero in here
and add this as an additional
argument.
And so it will shift X
Bichel and then when it goes
to fill in the bits, it's going to
use SBX.
So let's just look at this
running this one so well
let's type make
to build our project,
go ahead and run it and we'll say
shifting by two and
again we'll take the number
negative 50.
So because our number was negative
when it did the shift, it used
SBX and I had set it to zero, so
it filled in zeros at the top.
So the top two bits got set to zero.
So then all of a sudden our number
got changed from a negative number
into a positive number.
So if I was doing this shift
and I knew I had a negative number,
then instead of using
SBX set to zero, I
consented to either all
F's.
So that's one way or another way to
get all F's in something that's a
lot simpler for a person to type
is I could use just negative one.
All right. And if you know to his
compliment, you'd be able to figure
out what negative one would be.
It would be all F's.
So now when I build my project
and I go ahead and run it, so if I
want to shift bye to my
number is negative
50
and again, I get the correct number.
So it took the bits out of SBX
and used those to fill it in.
And so if we had other
values that we wanted to do shifts
on and we knew that we wanted a
certain number of bits and we
weren't actually doing
arithmetic arithmetic,
then we could use a different
value in here to get those bits that
got shifted into the top.
All right, so today we learned about
the arithmetic shift and then
even doing a double precision one,
and then we went through an example
of each one of those.
So looking forward, we're going to
talk about rotation and how that
differs from shifting
and rotation with Kerry.
If you have questions, you can
contact me at Miller, M.J.
at Unclutter Edu, and
you can find me on Twitter at
Milhouse 30.