Exercises

1:

Four Itanium logical instructions directly correspond to four of the sixteen logical functions in Table 6-1. Write single Itanium instructions that compute some of the other logical functions.

2:

Suppose that registers r2 and r3 contain the values 0x12345678 and 0x9abcdef0, respectively. What would be the results computed and stored in register r1 by each of the Itanium logical instructions?

3:

Devise examples to show that andcm r1=r2,r3 does not produce r1 = r2 NAND r3.

4:

What is the net result of the following instruction sequence?

 xor    r23=r22,r23 xor    r22=r23,r22 xor    r23=r22,r23 
5:

When an immediate value is used in an Itanium logical instruction, state in words what can be said a priori about bits <63:8> of the result for: (a) and, (b) andcm, (c) or, and (d) xor in relation to an unknown pattern in bits <63:8> of the second source operand in a register.

6:

Make a table, enlarged from Table 6-3, that shows explicitly all the cases for addition of three single-bit operands (A, B, and an incoming carry) to produce two output functions, a sum, and an outgoing carry. Relate this table to the exposition near the end of Section 6.1.6 in the text.

7:

Consider interleaving the hypothetical Itanium instruction sequences for computing the sum and outgoing carry for a single bit position (Section 6.1.6). What would be the apparent smallest number of clock cycles overall? Show the instruction sequence and any necessary stops.

8:

Find out how the assembler that you are using responds to an attempt to use a count greater than 63 in register r2 with the all-register forms of Itanium shift instructions. Similarly try to tell the assembler to use a count larger than 63 with the immediate forms of Itanium shift instructions. Describe your findings.

9:

When the Itanium shr instruction divides an integer value by some power of 2, the remainder is lost. Explain how to compute the remainder using one or more Itanium instructions from this chapter.

10:

Show that implementation of the shrp instruction is equivalent to a combination of these steps: logical shift right on the contents of register r3 by count6 bit positions, logical shift left on the contents of register r2 by (64 count6) bit positions, and combination of those partial results using logical OR to produce the final result in register r1.

11:

What explicit sequence of instructions would be necessary:

  1. to isolate into separate registers all 8 bytes loaded from a quad word in memory?

  2. to package 8 bytes in separate registers into a single quad word for storage into memory?

12:

Propose several different short sequences of Itanium instructions that would determine whether register r27 contains:

  1. a negative signed integer, and defend the best alternative; or

  2. an address corresponding to quad word alignment, and defend the best alternative.

13:

Modify the MAXIMUM program so that it reports both the greatest number found and the index position at which that value occurs in the array num().

14:

Complete the task begun at the end of Section 6.5.1 by preparing a full program that multiplies two 64-bit signed integers, N and X. Test thoroughly with different magnitudes and sign combinations. Estimate the figure of merit for the loop body that you use.

15:

Modify the DECNUM program to handle negative numbers of up to six digits in their base 10 representation. Can you make it issue a leading minus sign if and only if a number is negative?

16:

A table of consecutive 8-byte memory locations is called PTRTBL. The length of the table (i.e., the number of slots) is unknown, but the contents of each entry in the table is known in advance to be:

  • an address pointer to data of double word size (a nonzero number divisible by 4);

  • zero, marking an empty slot; or

  • the value 1, marking the end of the table.

Write a routine that passes through PTRTBL only once and counts:

  1. the number of valid address pointers; and

  2. the total number of occupied and empty slots, exclusive of the 1 marker.

The routine should copy these tallies into quad word locations labeled ACTIVE and TOTAL just before it finishes. Use the following data for the first actual run:

 PTRTBL:    data80, 4000, 0, 0, 0, 0x8ACE642012345678, 5276, -1 

Conduct a second run using about a dozen entries of your own.

17:

Explain why the output of the IO_C program produces one more line of output, if you enter no characters before pushing the return (or enter) key, than when you do supply one or more other characters first.

18:

Documentation for the C library says that putchar "returns the character written" (unless a system-detected error occurs). Use the debugger to verify this for chrput.

19:

Why should LEN in the BACKWARD program be no bigger than 213 bytes (admittedly an extreme line length)?

20:

Adapt BACKWARD to edit a sentence by inserting the word "not" at a predetermined location.

21:

Combine and adapt relevant portions from SCANTEXT, DECNUM, IO_C, and BACKWARD to build a program that prints on the screen the number of words found in a line of input from the keyboard.

22:

Write a program that prompts for a decimal number with arbitrarily many digits, and then formats it using commas to set off the digits in groups of three i.e., according to the standard pattern x,xxx,xxx. You will need to determine the length of the input string of digits. Test all the cases (length modulo 3).

23:

Many text editors have a Change Case command that will modify selected text by converting A Z to a z and a z to A Z, while leaving all other ASCII characters unchanged. Write a routine incorporating some Itanium logical instructions that performs this task. Test its operation on several strings and on the following:

 "'Why, I don't know Bertha,' Bert said." 

You will first have to devise a way to store in the .data segment a string that contains quotation marks. The program must not alter spaces and punctuation marks.

24:

Puzzle solvers know about palindromes, or words that read the same backwards and forwards (RADAR, OTTO).

  1. Write a routine to test whether a word is a palindrome. As you plan the loop in which some sort of comparison instruction occurs, think carefully about an appropriate exit condition. Consider carefully whether the two cases of even and odd numbers of letters require special care. Test thoroughly.

  2. (More difficult) Write a routine to test whether a sentence in mixed upper/lower case that contains appropriate punctuation for reading in the forward direction is palindromic. Punctuation characters and spaces are to be ignored. Here are some palindromic phrases and sentences:


                  Madam, I'm Adam.
                  A man, a plan, a canal: Panama!
                  He won now, eh?
                  Doc, note, I dissent. A fast never prevents a fatness. I diet on cod.
                  Was it a bar or a bat I saw?
                  Norma is as selfless as I am, Ron.
                  Able was I ere I saw Elba.
                  Poor Dan is in a droop.
                  Sununu's tonsil is not Sununu's.
                  Sonar possesses sopranos.
                  Tell a body do ballet.
                  Never ever ever even.
                  Won ton? Not now.
                  Zeus was I ere I saw Suez.
                  A Toyota.

  3. (Much more difficult) Write a routine to test whether a sentence in mixed upper/lower case with appropriate punctuation for reading in the forward direction is palindromic by whole words, not by characters. Punctuation characters are to be ignored. Some word-palindromic sentences are as follows:


                  All for one and one for all.
                  In order to stop hunger, stop to order in.
                  Fall leaves after leaves fall.
                  First ladies rule the state and state the rule, "Ladies first."



ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net