본문 바로가기

전체 글154

3.6.8 Switch Statements A switch statement provides a multiway branching capability based on the value of an integer index. They are particularly useful when dealing with tests where there can be a large number of possible outcomes. The advantage of using a jump table over a long sequence of if-else statements is that the time taken to perform the switch is independent of the number of switch cases. The array jt contai.. 2023. 4. 14.
3.6.7 Loops Do-While Loops While Loops The first translation method, which we refer to as jump to middle, performs the initial test by performing an unconditional jump to the test at the end of the loop. It can be expressed by the following template for translating from the general while loop form to goto cod The second translation method, which we refer to as guarded do, first trans- forms the code into a .. 2023. 4. 14.
3.6.5 Implementing Conditional Branches with Conditional Control The most general way to translate conditional expressions and statements from C into machine code is to use combinations of conditional and unconditional jumps 3.6.6 Implementing Conditional Branches with Conditional Moves Processors employ sophisticated branch pre- diction logic to try to guess whether or not each jump instruction will be followed. the code compiled using conditional moves requ.. 2023. 4. 13.
3.6 Control 3.6.1 Condition Codes the CPU maintains a set of single-bit condition code registers describing attributes of the most recent arithmetic or logical oper- ation. 3.6.2 Accessing the Condition Codes Rather than reading the condition codes directly, there are three common ways of using the condition codes: (1) we can set a single byte to 0 or 1 depending on some combination of the condition codes (.. 2023. 4. 10.
3.5 Arithmetic and Logical Operations the instruction class add consists of four addition instructions: addb, addw, addl, and addq, adding bytes, words, double words, and quad words, respectively 3.5.1 Load Effective Address The load effective address instruction leaq is actually a variant of the movq in- struction. It has the form of an instruction that reads from memory to a register, but it does not reference memory at all. 3.5.2.. 2023. 4. 10.
3.4.2 Data Movement Instructions Copying a value from one memory location to another requires two instructions—the first to load the source value into a register, and the second to write this register value to the des- tination. 3.4.3 Data Movement Example When the procedure begins execution, procedure parameters xp and y are stored in registers %rdi and %rsi, respectively For each entry in the table, show the two instructions .. 2023. 4. 8.
3.2.3 Notes on Formatting All of the lines beginning with ‘.’ are directives to guide the assembler and linker 3.3 Data Formats Due to its origins as a 16-bit architecture that expanded into a 32-bit one, Intel uses the term “word” to refer to a 16-bit data type. Based on this, they refer to 32- bit quantities as “double words,” and 64-bit quantities as “quad words 3.4 Accessing Information An x86-64 central processing u.. 2023. 4. 7.
3 Machine-Level Representation of Programs 3.2 Program Encodings higher levels of optimization (e.g., specified with the option -O1 or -O2) are considered a better choice in terms of the resulting program performance. the C preprocessor expands the source code to include any files specified with #include commands and to expand any macros, specified with #define declarations. Second, the compiler generates assembly- code versions of the t.. 2023. 4. 6.
2.2.8 Advice on Signed versus Unsigned We have seen multiple ways in which the subtle features of unsigned arith- metic, and especially the implicit conversion of signed to unsigned, can lead to errors or vulnerabilities. One way to avoid such bugs is to never use unsigned numbers 2.3 Integer Arithmetic Many beginning programmers are surprised to find that adding two positive num- bers can yield a negative result, and that the compar.. 2023. 4. 5.
2.2.5 Signed versus Unsigned in C Generally, most numbers are signed by default. For example, when declaring a constant such as 12345 or 0x1A2B, the value is considered signed. Adding character ‘U’ or ‘u’ as a suffix creates an unsigned constant; for example, 12345U or 0x1A2Bu. When printing numeric values with printf, the directives %d, %u, and %x are used to print a number as a signed decimal, an unsigned decimal, and in hexad.. 2023. 4. 4.
728x90