Diagrama de flujo
Sin título
Contenido del diagrama
Status Flags
You should note that once a flag is set or cleared, it remains in that state until another instruction changes its value.
not all assembly language instructions affect all the flags
instructions affect all six status flags
The mov, push, and pop instructions , on the other hand, do not affect any of the flags.
The Zero Flag
The purpose of the zero flag is to indicate whether the execution of the last instruction that affects the zero flag has produced a zero result
Usage: There are two main uses for the zero flag: testing for equality, and counting to a preset value.
The Carry Flag
The carry flag records the fact that the result of an arithmetic operation on unsigned numbers is out of range (too big or too small) to fit the destination register or memory location
Usage The carry flag is useful in several situations
To propagate carry or borrow in multiword addition or subtraction operations.
To detect overflow/underflow conditions.
T o test a bit using the shift/rotate family of instructions.
The Overflow Flag
How does the system know how your program is interpreting a given bit pattern?
the processor does not have a clue. It is up to our program logic to interpret a given bit pattern correctly
Usage Th e main purpose of the overflow flag is to indicate whether an arithmetic operation on signed numbers has produced an out-of-range result.
The Sign Flag
Usage Th e main use of the sign flag is to test the sign of the result produced by arithmetic and related instructions
Another use for the sign flag is in implementing counting loops that should iterate until (and including) the control variable is zero.
The Auxiliary Flag
The auxiliary flag indicates whether an operation has produced a result that has generated a carry out of or a borrow into the low-order four bits of 8-, 16, or 32-bit operand
The Parity Flag
This flag indicates the parity of the 8-bit result produced by an operation;
if this result is 16 or 32 bits long, only the lower-order 8 bits are considered to set or clear the parity flag.
The parity flag is set if the byte contains an even number of 1 bits; if there are an odd number of 1 bits , it is cleared.
Arithmetic Instructions
Addition
Subtraction
Multiplication
Division
Multiplication Instructions
Multiplication is more complicated than the addition and subtraction operations for two reasons
First , multiplication produces double-length results. Tha t is, multiplying two n-bit values produces a 2n-bit result.
Second , unlike the addition and subtraction operations , multiplication o f signed numbers should be treated differently from tha t of unsigned numbers.
A Note on Multiplication Th e multiplication instruction is an expensive one in the sense it takes more time than the other arithmetic instructions like add and sub.
The add instruction takes only one clock cycle whereas the multiplication instruction takes 10+ clock cycles.
Division Instructions
The division operation is even more complicated than multiplication for two reasons
Divisio n generates two result components: a quotient and a remainder.
In division, divide overflow is a real possibility. The processor generates a special software interrupt when a divide overflow occurs.
If the source operand is a byte, the dividend is assumed to be in the AX register and 16 bits long.
Conditional Execution
Unconditional Jump
It unconditionally transfers control to the instruction located at the target address.
There are several versions of the j mp instruction depending on how the target address is specified and where the target instruction is located.
Specification of Target
There are two distinct ways by which the target address of the j mp instruction can be specified: direct and indirect
Direct Jumps I n the direct jump instruction, the target address is specified direcdy as part of the instruction
As an assembly language programmer, you only specify the target address by using a label
Relative Address Th e address specified in a jump instruction is not the absolute address of the target.
The specification of relative address as opposed to absolute address of the target instruction is appropriate for dynamically relocatable code
Where Is the Target?
I f the target of a jump instruction is located in the same segment as the jump itself, it is called an intrasegment jump; if the target is located in another segment, it is called an intersegment jump.
If the target is outside this range, 2 or 4 bytes are used to specify the relative displacement. A two-byte displacement is used for 16-bi t segments, and 4-byte displacement for 32-bit segments.
Compare Instruction
Implementation of high-level language decision structures like if - then- el se in assembly language is a two step process:
An arithmetic or comparison instruction updates one or more arithmetic flags
A conditional jump instruction causes selective execution of the appropriate code fragment based on the values of the flags.
Th e main purpose o f the cmp instruction is to update the flags so that a subsequent conditional jump instruction can test these flags.
Conditional Jumps
Conditional jump instructions can be divided into three groups
Jump s based on the value of a single arithmetic flag;
Jump s based on unsigned comparisons;
Jump s based on signed comparisons.
Jumps Based on Single Flags
Jumps Based on Unsigned Comparisons
Jumps Based on Signed Comparisons
A Note on Conditional Jumps
The IA-32 instruction set provides two conditional jump instructions—one for jumps i f the flag tested is set, and the other for jumps when the flag is cleared—for each arithmetic flag except the auxiliary flag
When comparing two numbers it is necessary to know whether these numbers numl and num2 represent singed or unsigned numbers in order to establish a relationship between them should appropriately update flags to yield that AL > DL if we treat their contents as representing unsigned numbers.
The = and != comparison s work with either signed or unsigned numbers, as we essentially compare the bit pattern for a match.
For signed comparisons, three flags record the necessary information : th e sign flag (SF), the overflow flag (OF), and the zero flag (ZF). Testing for = and ^ simpl y involves testing whether the ZF is set or cleared, respectively.
All conditional jump instructions are encoded into the machine language using only 2 bytes
. A s a consequence, al l jumps should be shor t jumps. Tha t is , the target instruction of a conditional jump must be 128 bytes before or 127 bytes after the instruction following the conditional jump instruction.
TEC, sede central, Fundamentos de organizacion de computadoras
Resumen #10 (Sivarama caps 14 y 15)
Jossy Mejia Vargas 2017109693
Lunes 13 de noviembre, 2 semestre, Esteban Arias Mendez
Información
- Descripción
- Diagrama sobre Sin título, creado por Jossy Ivan Mejia Vargas el 14/11/2017.
- Creado por
- Jossy Ivan Mejia Vargas
- Visitas
- 0
- Valoración