Assembly

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14

Video Transcription

00:00
Hello. This is Dr Miller, and this is Episode 10.4 of Assembly
00:05
today. What we're gonna do is we're going to go through a string example.
00:12
So what's our problem? To be solved.
00:15
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 upper case letters
00:22
and then prints that string as an uppercase string
00:29
and a little bit of background. So the cases of letters and asking So here is a table that I grabbed from Wikipedia
00:37
about asking, and here is showing the letter the hex value and then the binary value. For that, it's got the six or seven bits that are used in asking the additional bit we won't worry about.
00:51
And so if we look and compare the binary oven uppercase letter like a with the lower case oven A, we can see that there is only one bit that is different. So bit six for starting
01:03
accounting from the left.
01:04
So basically, if you take that bit and if you turn it into a zero, a lower case letter all of a sudden becomes an uppercase letter.
01:12
And so we're going to use that,
01:15
um, for converting these letters from lower case into uppercase
01:22
so we'll go ahead and
01:23
start our project. So I created the project directory, entered that, and now we'll go ahead and edit our program.
01:29
So the first thing we need to do is we need to scan in our string, so we'll define our scan of foam at
01:38
it is going to be a percent s. So that is for strings Terminators. During with zero,
01:45
I'm going to allocate a couple of raise, so I might as well get those done here. So we'll have A and B
01:51
We're gonna reserve some 100 bytes
01:53
for both A and B,
01:57
and then we're going to use a couple functions. So we're gonna use scan app when we're going to use sterling.
02:12
Okay,
02:14
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
02:21
so we can go ahead and push,
02:23
okay?
02:25
And then we need to push our format
02:30
and then we'll call skin if
02:35
and then we got to correct the stack.
02:38
So we pushed to things on. So we had to correct it by two. Now we need to find out how long are string is. And so we scanned it into a We need to figure out how long it iss
02:47
so we again can push
02:52
a
02:53
call, stir Lynn,
02:55
and then add Yes, people
02:59
four to correct our stack. And now,
03:02
yea, X has how long are string is. And so we're going to use that inside of a loop, so
03:07
we'll use the standard loops and movie. See ex.
03:12
We'll just copy how long that string is,
03:17
and we'll go up here,
03:22
we'll find our label for the beginning of our loop, and then we'll loop to upper.
03:28
All right,
03:29
so we're going to use the load, string and store string. And so those both require Yes, I and e d I.
03:38
So a couple things will need to do
03:42
is we will want to move, So we're gonna copy it in to be
03:47
so be will be our destination,
03:58
and then a is gonna be our source. So we're going to read data from a using the load
04:04
load string bite. So little copy that into a L.
04:11
Now, here's the part that we have toe,
04:14
you have to figure out. So now a l has our value
04:17
that we want to turn into an uppercase letter.
04:20
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
04:28
zero. The easiest way to do that is to use the and operation so we can and l
04:34
And then if we write out what are bits are gonna look like So
04:40
we wanted to do bet ***.
04:43
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.
04:49
But right here, we're putting a zero, and so always this is going to get set to zero.
04:56
And so if we take this and converted into Hex, we end up with
05:01
zero D f
05:04
in hex.
05:05
And so this is a D. This is an F.
05:10
And so now we have taken that one bit
05:13
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,
05:20
and now we just need to save. So store, string, bite.
05:25
So now that will save in to be the value. So we loaded it from a we did our and operation, and then we stored it in to be And so we'll just copy the data
05:34
into their
05:36
and then we'll go ahead and loop on upper.
05:40
So that will keep going until we get to the length of our strings. That will exclude that zero that's there.
05:47
And then we can simply print our string. You could use print off if you want. I'm just going to use Prince Jane.
06:00
I'll print a new line here at the end.
06:03
All right.
06:08
Okay. So now if we run our program
06:12
and we type in a bee's ABC
06:15
No, it looks like we crashed it.
06:17
So it looks like I missed something. Let's look and see what I missed.
06:25
So they got
06:32
Oh,
06:32
I need e X there
06:35
mistyped.
06:43
All right, so we can see if we type in the right letters,
06:46
which have been ABC. That's what we get. We can say this is a test of our
06:56
K's program,
07:00
and it looks like ours are scan f looked for, um,
07:04
spaces which then makes that a little bit difficult. So then I have to use
07:10
the
07:12
hope
07:27
That's one of the
07:28
problems of using
07:30
scan. If is, it looks for by default,
07:32
a space will break it.
07:40
And so we can see that it changed all of the cases.
07:43
So there is a way. Let me see if we can fix this
07:47
to scan and look for
07:54
Oh, I see.
07:57
No, it's
07:59
I'll see if I can get this right here
08:01
a new line.
08:03
So we're gonna look for all the characters that are not a new line. The new line is 10 normally types life, and,
08:11
um, and see
08:13
until let's see if that
08:16
works.
08:24
No, it didn't like my format.
08:31
There is a format that would fix this. Um, I don't know it off the top of my head, but there is a format that you can use,
08:39
um, in scan after basically tell it to read until it gets to a,
08:45
um, new line, which is
08:48
a way that you can make it so that you could type in an entire sentence because typically by default, we were just wanting to scan a single string and not a an entire sentence.
08:58
And so that's something that we can look up. And if you look that up, then you should be able to,
09:03
um, be able to read in that string and then print it off.
09:11
All right, so today we looked at how to read a string and then how to convert it into uppercase
09:18
and looking forward will see some different C programming constructs and look at examples of how those manifest themselves in assembly. And then we'll start looking at the arm architecture.
09:31
If you have questions, you can email me Miller, MJ at you and Keita et you,
09:35
you can find me on Twitter at Milhouse 30.

Up Next

Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

Instructed By

Instructor Profile Image
Matthew Miller
Assistant Professor at the University of Nebraska at Kearney
Instructor