Question: Many microprocessor instruction sets include an instruction that tests a condition and sets a destination operand if the condition is true. Examples include the SETcc
a. There are a few differences among these instructions:
¢ SETcc and Scc operate only on a byte, whereas Scond operates on byte, word, and doubleword operands.
¢ SETcc and Scond set the operand to integer one if true and to zero if false. Scc sets the byte to all binary ones if true and all zeros if false.
What are the relative advantages and disadvantages of these differences?
b. None of these instructions set any of the condition code flags, and thus an explicit test of the result of the instruction is required to determine its value. Discuss whether condition codes should be set as a result of this instruction.
c. A simple IF statement such as IF a > b THEN can be implemented using a numerical representation method, that is, making the Boolean value manifest, as opposed to a flow of control method, which represents the value of a Boolean expression by a point reached in the program. A compiler might implement IF a > b THEN with the following x86 code:
.png)
The result of (A > B) is a Boolean value held in a register and available later on, outside the context of the flow of code just shown. It is convenient to use register CX for this, because many of the branch and loop opcodes have a built-in test for CX. Show an alternative implementation using the SETcc instruction that saves memory and execution time.
d. Now consider the high-level language statement:
A: = (B > C) OR (D = F)
A compiler might generate the following code:
SUB MoV CMP JLE INC TEST JCXZ OUT CX. CX AX, B AX, A TEST CX set register CX to 0 move contents of location B to register AX compare contents of register AX and location A jump if AB add 1 to contents of register CX jump if contents of CX equal 0 THEN OUT
Step by Step Solution
3.51 Rating (164 Votes )
There are 3 Steps involved in it
a It might be convenient to have a wordlength result for passing as a parameter via a stack to make ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
896-C-S-S-A-D (2518).docx
120 KBs Word File
