Week 6 Day 2 - Range Based Loops in Assembly

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



Duration: 1:43:04
51 views
0


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.







Tags:
csci45
arm32
array
range-based loop