Aggregates / Block Operations pt. 2
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
This is a continuation of a previous lesson on block operations and this is the same thing that we looked at before but with a label and the loop instructions gone. Instead, an REP, short for Repeat Prefix is included in front of the block copy instruction. It does the same thing that was done with the loop. It repeatedly executes the instruction, reducing the ECX Register by one until ECX is zero. This is about as small a block of code as you can write that will copy memory from one location to another and you can do more than copy blocks of code. You can compare memory. This compare instruction compares the two 8-bit values at the current source and destination locations and sets the flags accordingly. It then modifies the index register to prepare for the next time through the loop, if there is one. The code drops through if a match is never found but this code requires a looping label and both a jump and loop instructions. Here is another way to write this. This version of the code uses a special form of the repeat prefix. This one repeats the instruction as long as this zero flag is set and the ECX Register is not zero. So when the execution gets to the jump if not zero instructions, either there has been a mismatch and the flag is set or all the bytes have been found to be equal. Now, this example uses a new form of the repeat prefix. These two prefixes are the same. They will repeat an instruction only if the zero flag is set. The second form, repeat on equal, can be used if you'd prefer. It all depends on how you think of your algorithm. The two other forms are also possible. They are the opposite. They will repeat the instruction only if the flag is not set. All of these instructions subtract one from the ECX Register and repeat only as long as the result is not zero. And if the zero flag is in the right state. There are six different forms of the repeatable compare instruction. These three perform a memory-to-memory compare. The first one compares one byte each time. The second one, one word and the third one a double word. Now, the CMP instruction shown in these examples doesn't really exist. I just wrote it this way to explain the operation. These three instructions compare a location in memory with a value you preset in the Register AL, AX or EAX. This can be used to search through a block of memory for a particular character or a particular integer value. You can see how the instructions described in these two lessons can be used to build a set of string manipulation functions. You can compare strings, copy string and locate any character inside a string, including the termination character at the end. But watch out for the most common error when you use these instructions. Don't forget to set the direction flag. If your code expects values to be added to the index registers but the direction flag is set so it subtracts instead, then your code can fail in a mysterious and inconvenient way.
Tutorial Information
| Course: | Assembly Language Programming |
| Author: | Arthur Griffith |
| SKU: | 33995 |
| ISBN: | 1-935320-44-0 |
| Release Date: | 2009-05-28 |
| Duration: | 5.5 hrs / 70 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 