Assembly

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

Video Transcription

00:00
Hello. This is Dr Miller in this episode 14.1 of assembly.
00:05
Today we're gonna talk about C contracts, constructs and will give some examples, including unions and structures.
00:12
Constructs.
00:14
So a construct is a feature that is provided to the programmer and allows them to write programs more efficiently with their time instead of doing things manually by hand.
00:25
And we have some
00:26
constructs that are visible to the user and then some that are hidden by the language.
00:31
So things that might be visible would include structures and unions and a little bit on switch statements. But then jump tables might be hidden from the uses. They may not see those in their data they lives or understand how they're being implemented by the compiler.
00:47
So we're given example unions.
00:50
So union is where we have a value and who might have several different representation of that using a variety of different formats for the same thing. And this allows a program to use a programmer to use the same memory, but they can change how it's interpreted by the computer.
01:07
An example might be an I P address, so you might want to represent it using bites or characters,
01:11
Um, and then you might want to load the entire thing using an imager. So that's one example of where we might use a union.
01:19
So here we have an example of the union. We can see it's defined at the top. It's called Union, and our union is called My Union, and then it consists of afloat and an unsigned character.
01:30
And the way that the compiler determines what the size of this union is is it looks at this largest of the different types, so afloat is going to be four bites. An unsigned character is going to be six bites the rays side six, and so it'll make this union be six. So whichever one is the biggest right, it wants to be able to hold that. And so that's what it uses when it determines the size.
01:51
And then we can see here we have a loop that goes through all six characters and just assigns them to the value of F f.
01:57
And then we can see down here we go ahead and change that later and say, Oh, I want to save into that The number 3.14 and then we go ahead and we actually print off all those values,
02:07
um, again using the character method of accessing that.
02:14
So in this example, we can see accessing this field using x dot f equals 2.14 and we don't have an offset. So we can see here that we're loading a floating point number and stored in the data section and has a particular offset
02:30
that's loaded onto our floating point stack. And then we're going to go ahead and do a floating point store,
02:35
and it's using ah e v P minus 14. And so that's the location that it is saving into.
02:44
And then this is an example where we have an additional offset that stored in there so we can't just directly access it.
02:50
So we have to add in or offset.
02:53
And so we can see here again the place that we're gonna end up saving as e v P minus 14. So we load that address into et X.
03:00
We go ahead and load are offset or I into E X. We add the two together store that an E X,
03:07
and so now we're going to save the value F f into the location pointed to by E X, which again, is the offset plus the address
03:16
structures.
03:19
So a structure is a composite data type,
03:22
so it's gonna have similar syntax. But we have a bunch of variables that are all grouped together, and we can use one pointer in order to
03:29
I'm discussed those. And so we can use this in order to create composite data structures that have many different pieces of information inside of them.
03:38
So here's an example again, similar syntax. We define a list of things, but here each one of them occupies its own memory location. So we have a flow to character and imager and unsigned character array all sort in the same thing. And I can assign values to each one of those, and they are independent of each other.
03:58
Now, here is a debugging view of that so we can see in here that we have,
04:02
um, are registers and our stack and then inside of here, each one of these statements is again going to generate a variety of assembly statements down here.
04:13
But when we look when we print off what our structure is, we can see that it holds all of the data that we had saved in it, right? So it's not overriding something. It's Each one has its own reserve location,
04:25
and so we can see also it sort of prince our character as zero x 61 which is the character? A. We can also see B
04:33
um, in their
04:36
So today we talked about different see constructs and then we gave examples showing both unions and structures
04:45
Looking forward, we're actually gonna look at the structure layout and see how the access works for that layout for the different members inside of there. So we'll go a little bit more in depth with that
04:55
and then also in the future will try and understand the structure and we're going to or union using it to bugger so weaken sort of view the code and see how it manipulates it within the assembly room.
05:09
So here's our quiz.
05:11
So what Data type uses different memory locations for each variable?
05:16
That would be a structure
05:20
what determines the size of a union,
05:25
the sides of the largest member.
05:28
If you have questions, you can email me Miller MJ at you and Kate I e to you, and 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