Hello, this is Dr. Miller, and this
is Episode three point one of
assembly
today we're going to talk about
changing data sizes, multiplication
and division.
Changing sizes.
So changing sizes, we want to take
something and we want to either make
it smaller or make it bigger,
so making it smaller means that
we're going to just move it to a
smaller register.
And this can be converting from a
word to a bite and removing
the upper eight bits.
So if you remember, X is composed
of two smaller registers, H
and A-L, and so
inside of X, A-L
would have three, four
X and H would have
one to hex.
So if we move into s.L H,
right, the number one two in Hex
would get moved into s.L.
So we're taking something X and
we're moving it into a smaller one.
So we just remove the the bits that
we don't need.
If we want to increase the size,
then we have to care about things
like the sign, so we've talked about
to compliment and you should
have the ability to write the number
negative seven into a compliment
using one bite.
You can take the time to do that and
we'll show the results on the next
slide.
So negative seven is
zero x F nine,
and so we can move into the register
ball, the number negative seven.
So again, we have that top bit being
our sign.
And then we have two ways in order
to increase the size, we can
either use sign extend so we
know that we're using signed
numbers. And so we want to extend
the sign if needed or zero
extend if we don't care about the
sign and we just want to fill it
with zeros.
So, for example, we move into B L
negative seven and then if we do
move sign, extend into a bigger
register X B.L.
because this top bit is a one.
Remember when we if we convert F
is one one, one one.
So it'll fill that all with ones.
And so X will have
f f f f f
f nine.
If we do the same thing into, say,
X, right, the no
negative seven and we use
Psionics, then again it will fill it
with zeros but it'll be an X
as opposed to X, right.
X is thirty two bits.
X is 16 bits.
And if the number is not
signed, so for example, the number
seven, so zero seven,
then we're going to fill the bits
with zeros.
And so if I move with a sign, extend
XBRL,
the number seven doesn't have the
top it set and we're
saying fill it with zeros if it's a
zero. And so that's what will happen
then. We also have zero extend.
So basically we say we don't care if
the number is negative or not.
We want to put zeros in it.
So if I do the same operation move
be all negative seven again, it's F
nine.
If I move zero, extend into
X from B.L.,
it'll be
six zeros and then F nine.
So the top zeros, top bits
are filled with zero.
Again, I can move into this is a
thirty two to register eight, but
this is a 16 bit register
again eight bits and so this
is how I can change any of my signs.
And then we get the same result
on this one zero extender sign exten
because this number is positive.
So it doesn't have that top it set.
So it would have filled it with
zeros anyway, but zero and
guarantees that it will fill it with
zeros.
So arithmetic, again, we've talked
about to compliment, so this allows
for both signed and unsigned numbers
and then we've mentioned briefly we
have these flags and these flags
will get set when you do some
operations.
And so, for example, the carry flag.
So if I have to
16 bit numbers, zeros.
So here's my 16 pin number zero
zero to see and my other
16 bit number F F F F.
Right. If these are not signed
numbers, i.e.
they're not stored in twos
compliment, then when I go
ahead and add them together,
right. Then I get a what we call
carry or overflow.
And so if these were going
into a 16 bit register then our
carry flag gets get set to say
the number we're trying to store is
too big to store in a sixteen
bit register.
But if I were using a 32 bit
register, then I'm just taking two
numbers. And clearly this is not a
negative number because all
the rest of the top bits are not
set.
And so these two numbers are
positive. And so this is my result
of doing adding to positive
numbers together in a thirty two but
register and again,
flags will get set to carry a flag
is just one example.
Multiplication.
So we're multiplication, we have two
different op codes, so the first
one is going to be mall and this is
for unsigned numbers.
So numbers that are always positive
and we can use a eight bit register.
So Al is implicit
in here. And so we take
the source times al store
the result in X..
So if I do mobile
that's going to multiply B.L.
Times Al and store the result
in X.
If I have a sixteen bit register
then we're going to implicitly
multiply by X that register
times the source that I pick.
So in this example, SCIEX,
so in this example I'll take six
times a X and then I'll store
the top 16 bits
in D, D, X and
the bottom sixteen bits and X.
And then if we have a thirty two bit
register, we are again
mall SBX,
well, times a source, so
X times SBX and
then the top thirty two bits get
stored in E, D, X
and the bottom thirty two bits get
stored in E, X.
So here are a couple of examples,
so, for example, we do more B.L.,
so Ebix has to
which implicit means B.L.
has the number two.
So two times 10 is
20.
We multiply those together and then
we can see that are a result is 14
and Hecks, which is the
same as 20 in decimal.
And the second one, we're
multiplying by six.
And so I take X
or X, write the number 10,
multiplying that by six
three. So I should get 30.
And if you do that, it is
in here one
E is our result
again. Notice that.
So in the first example, we only
modified X.
Or to be more precise acts,
and the second, remember, we're
doing a 16 bit multiplication
and so notice here how the
beef disappeared, right?
So we took the
beef in here and we set it to zero
because the top bits of that were
set.
So if I take three times 10,
that gives me 30.
And so 30 goes in the bottom part
and then zeros get filled in the
top.
And then if I do a full thirty two
bit multiplication, so I take
Yak's, which is gadzooks
A and I multiply that
by Ebix, so 10 times two
is 20.
Again, we got 14,
which is 20 and Hecks, but then we
erased all of the
IDEX.
So feed beef disappeared.
So this is an example you can try on
your own so you can either
try and do it longhand
or you can open up a terminal
and enter your program and
then print off the result and see
what would change.
Now, if we want to do sign more,
sign multiplication, we use
the OP code I.M.,
so that's going to take either
to thirty two bit numbers or a
thirty two bit number and a memory
address or a thirty two
to thirty two bit numbers
and a immediate and it's
going to multiply them together.
So for example, if I do I'm all
SBX then X
gets the result of multiplying X
times X
or if I do I'm all IACI.
Eddi twenty five.
That's going to take Eddi times
twenty five and then store the
result in Essi.
So here is an example, so if I
do, I'm all SBX,
it's going to take X, multiply
it by X and then store
the result in X.
So again, we have a negative number.
So negative, two times ten
is negative 20 and you should
be able to using to complement,
convert that and verify that it is
the number negative 20.
Division,
so division is like multiplication,
we have, again, unsigned with
div or we have signed with
it.
And then the result, so we have a
cushion and the remainder.
So when you do division, right, how
many times it goes into that number
is your quotient and then your
remainder is what's left.
And so again, we have different
registers to get used depending
on if we're doing an eight bit or a
sixteen bit or a thirty two bit.
So again, we are going to take, for
example, X and divide it
by the source store.
The question in a L store the
remainder and H if
we're doing sixteen bit again, it's
going to use the entire registers
of X and X put
together and divide those by the
source and then store the quotient
and X and the remainder index.
And then if we have a thirty two bit
we are using IDEX and
X together and then dividing
those by the source and then the
question gets stored in X and
the remainder gets stored in X.
So in this, I put an example,
so here we have has one
hundred in decimal
and then Ebix has seven
and I just do a division
of Ebix.
So again, that's going to take
X and X together as
my number and then divide it by
SBX.
And so my remainder,
if we take one hundred divided by
seven is E,
you can convert that and
then the remainder is two.
So we get the number ninety eight
when we multiply seven times
E and then we have a remainder
of two
in here. I put you need to zero
or else.
So if you forget to zero it out
and you run this code and you can
type it in yourself, you will get
a floating point exception because
the result that I tried to store
couldn't fit in
X, right.
So when you're doing the division,
we couldn't store that full thing in
X, and so we get a floating point
exception.
So this isn't a mistake that often
my students make.
So today, we talked about changing
sizes, we talked about
doing multiplication and doing
division.
In the future, we're going to learn
about doing multiplication
and division, given some actual
examples of typing it in
and then doing comparisons and
doing looping,
if you have questions, you can
contact me at Ramjet, you and Kada
Edu and you can find me on Twitter
at Milhouse 30.