fuck this hist
This commit is contained in:
parent
0c2c2dd293
commit
ebb7466edd
36
cst337/lec/lec13.md
Normal file
36
cst337/lec/lec13.md
Normal file
@ -0,0 +1,36 @@
|
||||
# lec13
|
||||
|
||||
Let's break down what most/any program must have(executable):
|
||||
|
||||
> Data
|
||||
|
||||
We need a place to put variables and maybe some compile time constants so when we compile our program we can place those things here.
|
||||
|
||||
> Code
|
||||
|
||||
This section will contain all of our running code(_duh it's in the name_). If you write any functions, loops etc they will live here.
|
||||
|
||||
> Stack
|
||||
|
||||
This area is used heavily for functions.
|
||||
Any time we call a function we push a return address onto our stack for instance so that we know where to go back to when that function ends.
|
||||
|
||||
## Little Endian & Big Endian
|
||||
|
||||
Let's say we have the number `5431`.
|
||||
Since the 5 is the _largest_ number here we'll say this number is in _big endian_ format but if we wrote backwards... we have `1345` we would say it's stored as _little endian_ because 1 is the _smallest_ number but its at the front.
|
||||
|
||||
For hex we do something very similar: take `0x45FA` as big endian.
|
||||
Converting `0x45FA` to little endian we get `0xFA45`
|
||||
|
||||
> ??Wait that does seem right!?!
|
||||
|
||||
Here's the one caveat: _bytes aren't affected by little or big endianess_.
|
||||
So just leave the bytes alone and reverse them from there.
|
||||
|
||||
## Significance of this
|
||||
|
||||
The reason why we care is because if you're going to be writing assembly code then you must understand these things to successfully create anything with assembly.
|
||||
Even so this will give a deeper understanding of what goes on when something happens in your code.
|
||||
|
||||
|
71
cst337/lec/lec14.md
Normal file
71
cst337/lec/lec14.md
Normal file
@ -0,0 +1,71 @@
|
||||
# lec14
|
||||
|
||||
Just like any other binary, those written for MIPS must follow a specific structure for any level of compatibility.
|
||||
In the case of MIPS, binaries have a few _sections_ which allow us to cleanly organize our files.
|
||||
|
||||
_Note that for the rest of this course I'll be discussing the [ELF file format](https://en.wikipedia.org/wiki/Executable_and\_Linkable\_Format), although most of this information is conceptually the same across most other [binary file formats](https://en.wikipedia.org/wiki/Binary_file).
|
||||
|
||||
## From Disk to Memory
|
||||
|
||||
### Binaries on disk will have the following structure
|
||||
|
||||
* Header
|
||||
* Think of this like the metadata for the whole file
|
||||
* Keep in mind however that every section also has its own respective header that let's the O.S. loader know what is going on.
|
||||
* Data section
|
||||
* Here you'll find any compile time constants and compile time variables held in this section
|
||||
* Text Section
|
||||
* This is where the _code_ actually live on disk. Any functions, loops, etc that gets compiled from something like C++ or C will be written to this part of the file.
|
||||
|
||||
### Binaries in memory
|
||||
|
||||
|
||||
Once the binary is passed through the system loader the operating system will be able to determine that we may need a stack for the newly loaded code.
|
||||
I say "may need" because not all binaries require its own stack.
|
||||
A shared object file might not need its own stack because it will only be used as kind of _extension_ by some executable binary.
|
||||
|
||||
At this point any previous structure from disk is preserved as one might expect.
|
||||
Once the file is loaded into memory however, the system loader must then also allocate some space of memory for our heap and stack; finally our program is in memory and we can begin execution(right?).
|
||||
|
||||
## DataTypes
|
||||
|
||||
Truth be told there are no _types_ in mips or really any assembly language, instead we determine _types_ by their size in bytes.
|
||||
In the case of MIPS we have the following types
|
||||
|
||||
| Type | Size |
|
||||
| --- | --- |
|
||||
| byte | 1 |
|
||||
| half-word | 2 |
|
||||
| word | 4 |
|
||||
| dword | 8 |
|
||||
|
||||
Likewise we also have _registers_, which are similar to global
|
||||
## Actually writing mips now
|
||||
|
||||
Just like any other sensible architecture we have the ability in MIPS to use system calls to let us do things like writing to stdout or reading from stdin.
|
||||
If you're writing mips code in mars there's a useful list of syscalls [here]().
|
||||
|
||||
For now let's translate some code to disect the different parts of MIPS.
|
||||
|
||||
```
|
||||
int main(void) {
|
||||
write("hello", 5, 1);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
If you compile this you'll have 1 compile time constant which contains `hello` but in hex followed by 1 byte of `0x00`.
|
||||
We also have some code, in this case we want to write something to stdout, then we want to exit the program safely.
|
||||
|
||||
From the top we have a need for some data:
|
||||
|
||||
```
|
||||
# comments look like this btw
|
||||
# first we declare that we have some data
|
||||
.data
|
||||
|
||||
# here is where our 'instructions' lie
|
||||
.text
|
||||
|
||||
|
||||
```
|
3
cst337/lec/lec15.md
Normal file
3
cst337/lec/lec15.md
Normal file
@ -0,0 +1,3 @@
|
||||
# lec15
|
||||
|
||||
_functions and recursion_
|
14
readme.md
14
readme.md
@ -1,10 +1,7 @@
|
||||
# What this is
|
||||
# REMINDER
|
||||
|
||||
The staging branch for all my notes taken during my time at CSUMB.
|
||||
This branch is bound to have typos, logical errors, and downright incorrect and incomplete information.
|
||||
For that reason you should really not rely on this branch for anything other than knowing that I just uploaded the rough draft of some things.
|
||||
|
||||
If you're looking for anything close to reliable then go to the master branch where the information there is more likely to have been reviewed andd edited for both clarity and accuracy.
|
||||
UNDER NO CIRCUMSTANCES DO I LET THIS LEAVE ME CLUTCHES.
|
||||
The general populace are genuily retaded don't let them
|
||||
|
||||
## cst311/ - Introduction to Networking and internet Programming
|
||||
|
||||
@ -12,8 +9,3 @@ If you're looking for anything close to reliable then go to the master branch wh
|
||||
|
||||
## cst363/ - Introduction to Database systems
|
||||
|
||||
Info here should be useful for general purpose but material is guided for CSUMB's curriculum.
|
||||
|
||||
### Regarding Accuracy
|
||||
|
||||
Until I am more experienced some of this info may be imprecise however, I will be keeping some tabs on this repo since it's inevtiable that someone somewhere use this information for their own studies.
|
||||
|
Loading…
Reference in New Issue
Block a user