Week 6 Day 2 - Range Based Loops in Assembly
A range is when you have a pair of pointers (or iterators) which define the starting and ending points. The first pointer is the first element of the array (or whatever) you want to do your work on, and the second pointer is *one past the end* of the array. In C++, you could do this:
void doubler(int *begin, int *end) {
while (begin != end) *begin++ *= 2;
}
This would double the value pointed to by begin, and then moves the begin pointer four bytes (assuming 32 bit ints) to the right, doubles the value there again, over and over until begin equals end, at which point it terminates the loop.
The biggest challenge for students moving from C or C++ to assembly is that when you have an int array and you access element 3, let's say, that arr[3] does not mean 3 bytes to the right of arr, but 12 bytes to the right. When students forget to move 4 bytes at a time, bad things happen.
Other Videos By Bill Kerney
2021-02-24 | Week 7 Day 2 - Debugging II and Queues |
2021-02-24 | Week 6 Day 2 - Midterm Review |
2021-02-23 | Week 7 Day 1 - The Triangle in Games |
2021-02-23 | Week 7 Day 1 - Classes in C and Assembly |
2021-02-23 | Week 6 Day 1 - Fallacies III |
2021-02-22 | Week 7 Day 1 - Using Invariants to Debug Linked Lists |
2021-02-20 | Week 5 Day 2 - Fallacies II |
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 |