Programming.with.Linux,.3rd.Edition.Oct.2009

advertisement
Index
RCL (Rotate Carry Left), 288-289
RCR (Rotate Carry Right), 288-289
REP prefix
copying tm structure with MOVSD, 466-469
read-only memory (ROM), 71
real mode
memory, 82
memory addresses and, 211-212
real mode flat model
overview of, 78
programming model for x86 CPU, 97-99
real mode segmented model
megabytes of addressable memory, 82-83
overview of, 78, 99-101
paragraph boundaries and, 86
seeing megabytes of memory through
blinders, 83-85
segments in, 85
recursion, 340, 341
reference documentation
for beginners, 231-232
for flags, 232
overview of, 230-231
register addressing
accessing register data, 207-209
overview of, 205-207
register data
as operand, 205
overview of, 207-209
register halves, 8-bit registers, 93-95
registers
16-bit and 32-bit, 90-91
20-bit addresses from 16-bit registers, 88-90
burden of 16-bit registers, 317-318
CPUs and, 60-61
defined, 88
flags register, 96
general-purpose registers, 91-93
instruction pointer and, 63, 95-96
memory addresses and, 211-212
peripherals, 61
procedures and, 343
register halves and, 93-95
saving caller's register values, 343-346
saving/restoring when linking to C
libraries, 447-448
string defined by register values, 395
Registers view, Insight Debugger
displaying register's value in three formats,
223-224
overview of, 198-199
viewing EAX register with, 206
viewing flags with, 216-218
relay switches, 48
relocatability, linkers and, 128
ECX decrement and, 408-409
MOVSB with, 418-419
single-stepping with Insight Debugger,
418-419
STOSB with, 403-404
STOSB without, 407
REPE prefix, 435-436
REPNE prefix, 435-436
repositories, package managers, 140
RESB directive, 402
RET (Return from procedure), 563
LoadBuff example, 337-338
recursion and, 340-341
reference, 561
returning control to caller, 446
reuse. See code reuse
ROL (Rotate Left), 288-289, 564-565
ROM (read-only memory), 71
ROR (Rotate Right), 288-289, 566-567
rotating bits, 288-289
Ruler procedure
adding ASCII digits, 411-413
displaying, 409
lesson learned, 414
MUL instruction compared with IMUL,
410-411
runtime errors, 137-138
S
sandbox
minimal NASM program for using with,
202-204
for working with x86 machine instructions,
201-202
SBB (Arithmetic subtraction with borrow),
568-569
scanf(), C language, 458-462
SCASB (Scan String by Byte), 432-435
screens. See also virtual text display
displaying ruler on, 409
MUL instruction compared with IMUL,
410-411
searches
search and replace, 172
text, 171-172
seed values
for random numbers, 475
srand() function for getting seed value of
random numbers, 476-477
segment addresses, 86-87
■
R-S
605
606
Index
■
S-S
segment registers
not responding to bitwise logical
instructions, 285-286
porting from CPU 8080 to 8086, 80-82
protected flat mode model and, 102
real flat mode and, 97
segments
as horizons not places, 88
making 20-bit addresses out of 16-bit
registers, 88-90
nature of, 85-87
offset addresses and, 89-90
selecting text, in Kate, 170-171
semicolons (;), as comment delimiters,
124
serial-access devices, 52
services dispatcher, Linux, 256
Session Chooser dialog, Kate, 159
sessions, Kate
file management and, 165-167
overview of, 162-163
SF (sign flag)
DEC EBX instruction clearing, 217
in EFlags register, 214
flag rules, 510
uses of, 301
shifting bits
<count> operand for, 286-287
how it works, 287
multiplying by shifting and adding,
295-298
SHR and SHL instructions, 286
SHL (Shift Left)
multiplying by shifting and adding,
296-298
reference, 570-571
shifting bits, 286
short jumps, conditional jumps,
354-355
short-term storage, stack for, 253-254
showchar program
closing inner loop, 421-422
closing outer loop, 422-423
displaying ASCII table, 419-420
nested instruction loops, 420-421
recapping, 423-424
SHR (Shift Right)
compared with DIV, 209
masking unwanted nybbles, 293
reference, 572-573
shifting bits, 286
sign bit, 221
sign flag. See SF (sign flag)
signed values
jump instructions and, 302-304
MOVSX for moving, 224-225
overview of, 221
ranges of, 223
silicon chips. See also memory chips
bit capacity of, 51
CPU (central processing unit), 58
size specifiers
for memory data, 211
using with NASM, 220
SMP (symmetric multiprocessing), 73
software, package managers for installing,
140
software interrupts
vs. hardware interrupts, 261-262
nature of, 254-255
source code files
.ASM file extension for, 131
assembling, 125-126, 131-132
debugging information in, 128
editing, 131
examining AT&T gas source file produced
by gcc, 471-474
Kate editing controls for, 168-172
source code highlighting, macros and, 390
source code window, Insight Debugger, 195,
197
source operand
immediate data and, 206
machine instructions and, 205
sum of source and destination operands,
207
source strings, types of strings in x86, 395
SpeedCrunch calculators, 28
srand(), C language, 476-477
SS (stack segment) register, 91
sscanf(), C language, 487-489
stack
anatomy of Linux stack, 427-429
calling procedures within procedures and,
340
examining with command-line arguments,
424
examining with Insight's memory view,
430-432
LIFO (last in, first out), 246-248
overview of, 246
POP instructions, 251-253
popping vs. addressing, 436-438
PUSH instructions, 249-251
real flat mode model and, 98-99
saving caller's register values and, 344-345
Index
for short-term storage, 253
upside down structure of, 248-249
why stack addresses are not predictable, 429
stack frame
calling procedures and, 346
destroying, 450
setting up, 448-450
stack pointer. See ESP (stack pointer)
stack segment (SS) register, 91
Stallman, Richard, 440-441
standard error (stderr), Unix files, 179
standard input (stdin), Unix files, 179
standard output (stdout), Unix files, 179
STC (Set carry flag), 574
STD (Set direction flag), 575
steps
in Assembly Language Game, 10
in board games, 5
in laundry list, 2-3
machine instructions as, 66
summary, 12
storage
in board games, 5
CPU registers for, 60-61
cubbyholes in Assembly Language Game,
11
short-term storage in stack, 253-254
STOS (Store String)
16-bit and 32-bit versions of, 414
reference, 576
STOSB (Store String by Byte)
for clearing display buffer memory, 403
DF (direction flag) and, 405-406
ECX decrement and, 408-409
executing , 404-405
nested instruction loops, 420-421
REP and, 407
Ruler procedure using STOSB without
REP, 409-414
setting up registers for showchar program,
420
string variables
deriving string length with EQU and $,
244-246
overview of, 242-244
strings
converting time_t values to formatted
strings, 464-465
ECX decrement and, 408-409
HexStr, 295-298
moving. See MOVS (Move string)
not having boundary values or length
indicators, 394
overview of, 393-394
searching with SCASB, 432-435
single-stepping REP string instructions
with Insight, 418-419
source strings and destination strings, 395
sscanf() for converting into numbers,
487-489
storing by byte. See STOSB (Store String by
Byte)
storing data to discontinuous strings,
419-424
virtual text display example. See virtual text
display
subtraction
SBB (Arithmetic subtraction with borrow),
568-569
SUB (Arithmetic subtraction), 577-578
subtraction, in hex
borrows and, 35-37
overview of, 32
successive refinement
designing non-trivial program, 266-271
of programs, 277
switches
as on/off memory device, 47-48
transistor, 48-49
symbol tables, linkers building, 127
symmetric multiprocessing (SMP), 73
Synaptic Package Manager, 140, 141
system clock
CPU and, 63
fetching time_t values from, 464
T
tables
accessing from procedures, 343
displaying ASCII table, 419-420
using lookup tables, 293-295
writing values to, 295
terminal emulation, Unix/Linux, 176
terminal utilities, Konsole, 143
terminal window
in Kate, 173
text display and, 402
terminals
character encoding in Konsole, 177-179
console applications, 176-177
control cautions for Linux terminals,
377-378
escape sequences controlling, 183-184
not launching Kate via terminal command,
159
■
S-T
607
Download