Hello, this is Dr. Miller, and this
is Episode ten point four of
Assembly
today. What we're going to do is
we're going to go through a strong
example.
So what's our problem to be solved?
So what we'd like to do is write a
program that reads in a string
and then converts all of the letters
in that string to uppercase letters
and then prints that string
as an uppercase string.
And a little bit of background, so
the cases of letters and aski,
so here is a table that I grabbed
from Wikipedia about
Askey and here it's showing me
the letter, the hex value
and then the binary value for that.
And it's got the six
or seven bits
that are used in ASCII.
The additional bit we won't worry
about.
And so if we look and compare
the binary of an uppercase letter
like A with the
lowercase of an A., we can see
that there is only one bit that is
different. So a six, the first
starting counting from the
left.
So basically, if you take that bit
and if you turn it into a zero, a
lowercase letter all of a sudden
becomes an uppercase letter.
And so we're going to use that
for converting these letters from
lowercase into uppercase.
So we'll go ahead and
start our project. So I created the
project directory, entered that, and
now we'll go ahead and edit our
program.
So the first thing we need to do is
we need to scan in our string.
So we'll define our SCANA
from that.
It is going to be a percent
s, so that is for string's
Terminator's during one zero.
I'm going to allocate a couple of
days so I might as well get those
done here. So we'll have A
and B, we're going to reserve
some one hundred bytes
for both A and B,
and then we're going to use a couple
of functions. So we're going to use
ganef and we're going to use
Easterlin.
OK,
so the first thing we need to do is
we need to scan our
data in, we'll go ahead and use a
as a reference so we can
go ahead and push
a.
And then we need to push our format.
And then we'll call SCANA
and then we've got to crack the
stack,
so we push two things on, so we have
to correct it by two.
Now we need to find out how long our
string is right.
So we scanned it into a
we need to figure out how long it
is.
So we again, can
push
a call
or one
and then add is
for four to
correct our stack and now
X has how long our string
is. And so we're going to use that
inside of a loop.
So we'll use the
standard loops and move X.
We'll just copy how long that string
is.
And we'll go up here.
Will define our label for the
beginning of our loop and then we'll
loop to upper.
All right, so
we're going to use the
load string and store string,
and so those both require Essi
and Etai.
So a couple of things we'll need to
do is we
will want to move.
So we're going to copy it into B,
so B will be our destination.
And then he is going to be our
source, so we're going to read data
from a using the load
load string byte
so that copy that into Al.
Now, here's the part that we have to
you have to figure out.
So now Al has our value
that we want to turn into an
uppercase letter.
And so we saw that we needed to
change one bit.
Probably the easiest way to do that.
We want to change that one bit to
a zero.
The easiest way to do that is to use
the an operation so
we can and al
and then if we write out what our
bits are going to look like.
So we wanted to do
bits six.
So all of these, when
we hand them, if we put a one in,
then whatever the original is, we're
going to get out.
But right here, we're putting a
zero. And so always this
is going to get set to zero.
And so if we take this and
convert it into hex,
we end up with.
Zero F
in hex, and so
this is a D.
This is an F, and so
now we have taken
that one bit and we have turned
it into a zero when it was
possibly a one or possibly a zero,
but we made sure that it was a zero
and now we just need to save so
stores during byte.
So now that will save into B
the value. So we loaded it from A
we did our An operation and then
we stored it into B and so
we'll just copy the data
into there
and then we'll go ahead and loop on
upper.
So that'll keep going until
we get to the length of our string.
So that'll exclude that zero that's
there.
And then we can simply print our
string. You could use print F if you
want. I'm just going to use
Prinstein.
I'll print a new line here at the
end.
All right.
OK, so now if we run our program.
And we type in Abbi's
ABC.
Oh, looks like we crashed it,
so it looks like I missed
something.
Let's look and see what I missed.
So we got.
Oh, I need X
there mistyped.
All right, so we can see if we
type in the right letters,
which have been ABC, that's what we
get. We can say this
is a test of
our.
Kaye's program.
And it looks like ours are
scanning looked for
spaces, which then makes that
a little bit difficult.
So then I have to use this.
Oh.
That's one of the problems
of using scan F
is it looks for by default,
a space will break it.
And so we can see that it changed
all of the cases, so
there is a way let me see
if we can fix this.
To scan and look
for.
Oh, I see.
No, but
I'll see if I can get this right
here, a new
line, so we're
going to look for all the characters
that are not a new line.
So new line is ten normally
types life and
in C
and so let's see if that
works.
No, I didn't like my format.
There is a format that would fix
this, I don't
know it off the top of my head, but
there is a format that you can use
in scan after to basically tell it
to read until it gets
to a
new line, which is
a way that you can make it so that
you could type in an entire
sentence, because typically by
default, we we are just wanting to
scan a single string and not a an
entire sentence.
And so that's something that we can
look up. And if you look that
up, then you should be able to
be able to read in that string
and then print it off.
All right, so today we looked at how
to read a string and then how to
convert it into uppercase.
And looking forward, we'll
see some different C programing
constructs and we'll look at
examples of how those manifest
themselves in assembly
and then we'll start looking at the
architecture.
If you have questions, you can email
me Miller, MJ at you in Edu.
You can find me on Twitter at
Milhouse 30.