7

Programming Examples

This chapter consists of five programming examples in assembly language. The first three examples show typical assembly language code sequences; the last two examples show the correspondence between C, a higher-level programming language, and assembly language.

Example 1 Calculates the highest bit position set in a passed parameter. A binary search is used to enhance performance.

Example 2 Copies bytes from a source location to a destination location. Both locations and the number of bytes to copy are passed in as parameters.

Example 3 Uses Divide Step to divide a 64-bit signed dividend by a 32-bit signed divisor.

Example 4 Uses a procedure call from a C program to the Assembler to verify that the program is passing the correct argument.

Example 5 Shows a C program that generates assembly code to call printf().

129