Week 7 Day 1 - Classes in C and Assembly

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=m0mA4fA67Do



Duration: 1:54:45
63 views
0


Today we reviewed the midterm, and then went over two important topics.


1) The difference between C and C++. I like C, but I prefer C++ since it has features in it that prevent you from making stupid mistakes (such as having a type conflict in mallac, which I totally did intentionally to show the problem, cough). C has a philosophy of nothing being hidden - the programmer can see every function call that takes place, whereas C++ has hidden things like constructors that run without the programmer seeing it. There's 5 or 6 important differences that I cover in the lecture.


2) Classes in assembly. A class is really just an array. A class with four integer members in it is treated more or less than same as int arr[4] as far as an assembly function is concerned. But most classes have a variety of member variables in them, and so you can think of them as "heterogeneous arrays", in other words arrays where not all the elements are the same type. You need to figure out the offset to each member variable (I show how in lecture), and then let's say that foo's int member variable bar is at offset +24, you'd load it like this:
LDR R10,[R5,#24]
...where R5 is a pointer to foo, and R10 is the register we're going to load the value into.


So overall it's pretty easy to work with unless someone changes the member variables.


We also talked a bit about padding and alignment. All 4 byte values are aligned on 4 byte boundaries, 8 byte values (like doubles) on 8 byte boundaries, and so forth, and so you can get some wasted space due to padding depending on how you make your class in C++.







Tags:
csci45
arm32
asm
classes
classes in assembly