Question: Assembly Language: On page 107, section 4.2.6 is a list of flags possibly affected by addition and subtraction. Write three versions of basically the same

Assembly Language:

On page 107, section 4.2.6 is a list of flags possibly affected by addition and subtraction.

Write three versions of basically the same program that runs a loop and adds or subtracts from the EAX register (you can use inc and dec if you want) until the flag change stops the loop. Use the Carry, Zero, and Overflow flags; one in each version of the program.

Hint: Since loops are potentially endless, remember you need a variation of the JMP instruction to jump out of the loop at a certain event, such as a flag change. I suggest you look at the variations of JMP on pg 201.

Assembly Language: On page 107, section 4.2.6 is a list of flags

possibly affected by addition and subtraction. Write three versions of basically the

4.2.6 Flags Affected by Addition and Subtraction When executing arithmetic instructions, we often want to know something about the result. Is it neg- ative, positive, or zero? Is it too large or too small to fit into the destination operand? Answers to such questions can help us detect calculation errors that might otherwise cause erratic program behavior. We use the values of CPU status flags to check the outcome of arithmetic operations. We also use status flag values to activate conditional branching instructions, the basic tools of program logic. Here's a quick overview of the status flags. The Carry flag indicates unsigned integer overflow. For example, if an instruction has an 8-bit destination operand but the instruction generates a result larger than 11111111 binary, the Carry flag is set. The Overflow flag indicates signed integer overflow. For example, if an instruction has a 16- bit destination operand but it generates a negative result smaller than 32,768 decimal, the Overflow flag is set. The Zero flag indicates that an operation produced zero. For example, if an operand is sub- tracted from another of equal value, the Zero flag is set. The Sign flag indicates that an operation produced a negative result. If the most significant bit (MSB) of the destination operand is set, the Sign flag is set. The Parity flag indicates whether or not an even number of 1 bits occurs in the least signifi- cant byte of the destination operand, immediately after an arithmetic or boolean instruction has executed. The Auxiliary Carry flag is set when a 1 bit carries out of position 3 in the least significant byte of the destination operand. To display CPU status flag values when debugging, open the Registers window, right-click in the window, and select Flags. 6.3 201 202 Chapul 6 . Conditional Procesi In the following example, the JL instruction jumps to label L1 because AX is less than 6: 20v 2,5 capax, fi 11 1.1 ; jump it less In the following cxample, the jump is takca because AX is greater than 4: ,ax , ig L1 : jump if greater 6.3.3 Types of Conditional Jump Instructions The x86 instruction set bas a large bumber of conditional jump instructions. They are able to compare signed and unsigned integers and perform actions based on the values of individual CPU flags. The conditional jump instructions can be divided into four groups: Jumps hised on specific flag values Jumps hised om equality hetween crperands on the value of (ECX - Jumps kesed on cxmparisons of unsigned operaxls Jumps based on comparison of signed ciperands Table 6-2 shows a list of jumps based on the Zero, Carry. Overflow, Parity, and Sign flags. Table 6-2 Jumps Based on Specific Flag Values Mnemonic Description Flags / Registers JZ Jump iler INZ Jump if not ZF =0 JC Jump if we CT = 1 INC Jump i not ry ) JO Jump inceler OF-1 JNO Josip if not overtog OF-0 - JS Jump it signed SF-1 JNS Jamp if not signed SF-11 JP Jumpit party level) FF -1 JNP Jump if not party codd) FC = 0 Table 6-3 Jumps Based on Equality Mnemonic Description JE Jump if paletop-righiop) INE Jump if rol qiliny righ:0p) JCXZ Jumpir JECXZ Jumpir RCX- JRCXZ Jump if RCX - 0161-bit mode) Although the JE instruction is equivalent to JZ (jump if Zero) and JNE is exquivalent to INZ (jump if not Zero), it's best to select the mnemonic (JE O IZ) that best indicates your intention to either compare two operands or examine specific status flag Following are code examples that use the JE, JNE, JCXZ, axl JECXZ instructions. Examine the Outenis carefully to be sure that you understand why the conditional jurns were (or were taken Example : DDV edx, CAS 23h Carp ede, 04523 in 1.5 i jump not taken je 11 jump is taken Example 2: mov bx, 12341 Bubbx, 12341 jne LS jump not taken je i jump is taken Equality Comparisons Table 6-3 lists jump instructions based on evaluating quality. In some cases, two opcrands are compared in other cases, o jump is taken based on the value of CX, ECX, or RCX. In the table, the notations lefiop and rightOp refer to the left (destination) and right source) operands in a CMP instruction: CMP leftog sig op The operand names reflect the ordering of operands for relational operators in algebra For example, in the expression X -123

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!