Week 5 Day 2 - Syscalls
We reviewed mapping 3D to 1D arrays using the powers of algebra. The formula is plane*plane_size + row*row_size + col. Row size is COLS, Plane size is ROWS*COLS.
We then reviewed GDB again, this time showing how to use it in TUI mode:
1) gdb -tui a.out
2) ctrl-x 2 to switch to 2 window mode
3) layout next to switch the layout to one that shows your registers in real time
4) set a breakpoint on the line or function you want to stop on
5) run (it will stop at the breakpoint)
6) step to step into or next to step over each line of code
7) Hit enter to repeat
We talked a bit about ln -s which can be used to create symlinks (shortcuts) in UNIX systems.
We then talked about callbacks, which means you register a function that will get called when something happens. We talked about atexit() which calls the function you pass it when your code exits, and also signal() which takes an int corresponding to the signal (for example SIGINT is the ctrl-c signal) and a function that will get called when, say, the user hits ctrl-c.
Finally, we talked about syscalls. Syscalls are a series of functions provided by the Operating System that actually allow you to do things. Most C and C++ stdlib functions are wrappers around syscalls.
In assembly, you invoke a syscall by putting the syscall number into R7, and then give a "SWI 0" command.
The most basic syscalls are exit (quit), open (open a file, which gives you a file descriptor, which is just an int), close (closes the given file descriptor), read (reads from the file descriptor into a memory address up to a certain number of bytes), and write (which writes to the given file descriptor a certain number of bytes at the given memory address).
I forgot (since I rarely call syscalls directly) one of the flags for open, it should have been this:
int fd = open("./macros_are_gone.txt",O_CREAT | O_WRONLY,00600);
Other Videos By Bill Kerney
2021-02-19 | Week 6 - Auto Landscapes |
2021-02-19 | Week 6 Day 2 - Linked Lists Part III |
2021-02-18 | Week 6 Day 2 - Auto Landscapes |
2021-02-18 | Week 6 Day 2 - Range Based Loops in Assembly |
2021-02-17 | Week 5 Day 1 - Invalid / Valid / Sound Arguments II |
2021-02-17 | Week 6 Day 1 - C++ Trivia: Const |
2021-02-16 | Week 6 Day 1 - Water and Landscapes III |
2021-02-16 | Week 6 Day 1 - Midterm Review and Generations of Architectures |
2021-02-12 | Week 4 Day 3 - Invalid / Valid / Sound Arguments |
2021-02-12 | Week 5 Day 2 - Dynamic Materials II - Water |
2021-02-11 | Week 5 Day 2 - Syscalls |
2021-02-11 | Week 4 Day 2 - Fallacies Part 1 |
2021-02-10 | Week 5 Day 2 - Linked List II |
2021-02-10 | Week 5 Day 1 - Dynamic Materials and Water |
2021-02-09 | Week 5 Day 1 - GDB and 2D Arrays with ARM32 |
2021-02-08 | Week 4 Day 1 - Scratch Part 2 |
2021-02-08 | Week 5 Day 1 - Linked Lists |
2021-02-06 | Week 3 Day 3 - Scratch |
2021-02-05 | Week 4 - Tracelines and Bounding Boxes |
2021-02-05 | Week 4 Day 3 - TDD and Linked Lists |
2021-02-04 | Week 4 Day 2 - UE4 Materials |