Introduction to 64 Bit Windows Assembly Programming Fourth Edition Ray Seyfarth pdf download
Introduction to 64 Bit Windows Assembly Programming Fourth Edition Ray Seyfarth pdf download
https://ebookfinal.com/download/introduction-to-64-bit-windows-
assembly-programming-fourth-edition-ray-seyfarth/
https://ebookfinal.com/download/building-regulations-in-brief-fourth-
edition-ray-tricker/
https://ebookfinal.com/download/windows-kernel-programming-second-
edition-pavel-yosifovich/
https://ebookfinal.com/download/an-introduction-to-stochastic-
modeling-fourth-edition-pinsky/
https://ebookfinal.com/download/introduction-to-biotechnology-an-
agricultural-revolution-2nd-edition-ray-v-herren/
Introduction to Pharmaceutical Calculations Fourth Edition
Judith A Rees
https://ebookfinal.com/download/introduction-to-pharmaceutical-
calculations-fourth-edition-judith-a-rees/
https://ebookfinal.com/download/simply-java-an-introduction-to-java-
programming-programming-series-1st-edition-james-levenick/
https://ebookfinal.com/download/cytoskeleton-methods-and-protocols-
fourth-edition-ray-h-gavin-editor/
https://ebookfinal.com/download/microsoft-silverlight-edition-
programming-windows-phone-7-charles-petzold/
https://ebookfinal.com/download/introduction-to-java-programming-
comprehensive-version-6th-edition-liang/
Introduction to 64 Bit Windows Assembly Programming
Fourth Edition Ray Seyfarth Digital Instant Download
Author(s): Ray Seyfarth
ISBN(s): 9781543138849, 1543138845
Edition: 4
File Details: PDF, 7.46 MB
Year: 2017
Language: english
Introduction to 64 Bit
Windows Assembly
Programming
Ray Seyfarth
Ray Seyfarth
Hattiesburg, MS
USA
Seyfarth, Ray
Introduction to 64 Bit Windows Assembly Programming
Includes index
ISBN-13: 978-1543138849
ISBN-10: 1543138845
ii
Preface
The Intel CPU architecture has evolved over 3 decades from a 16 bit CPU
with no memory protection, through a period with 32 bit processors with
sophisticated architectures into the current series of processors which
support all the old modes of operation in addition to a greatly expanded
64 bit mode of operation. Assembly textbooks tend to focus on the history
and generally conclude with a discussion of the 32 bit mode. Students are
introduced to the concepts of 16 bit CPUs with segment registers allowing
access to 1 megabyte of internal memory. This is an unnecessary focus on
the past.
With the x86-64 architecture there is almost a complete departure
from the past. Segment registers are essentially obsolete and more
register usage is completely general purpose, with the glaring exception
of the repeat-string loops which use specific registers and have no
operands. Both these changes contribute to simpler assembly language
programming.
There are now 16 general purpose integer registers with a few
specialized instructions. The archaic register stack of the 8087 has been
superseded by a well-organized model providing 16 floating point
registers with floating point instructions along with the SSE and AVX
extensions. In fact the AVX extensions even allow a three operand syntax
which can simplify coding even more.
Overall the x86-64 assembly language programming is simpler than
its predecessors. Today most personal computers ship with 64 bit
operating systems. In fact the latest versions of the Apple OS X operating
system are only available in 64 bits, though Linux and Microsoft Windows
still have 32 and 64 bit versions. The era of 32 bit CPUs and operating
systems is nearly over. Together these trends indicate that it is time to
teach 64 bit assembly language.
The focus in this textbook is on early hands-on use of 64 bit assembly
programming. There is no 16 or 32 bit programming and the discussion of
the history is focused on explaining the origin of the old register names
and the few non-orthogonal features of the instruction set.
iii
The first version of this book discussed using the yasm assembler and
the gdb debugger directly. Now the author provides a free integrated
development environment named “ebe”, which automates the process of
using nasm1. The ebe environment is a GUI program written in C++ using
the Qt system and supports C and C++ in addition to assembly language,
though its purpose is to support assembly programming. There was a
previous version of ebe written in Python, but the newer version offers
many more features. The Qt version of ebe is available at
http://qtebe.sourceforge.net.
This version of the book discusses assembly programming for the
Windows operating system. There is a companion book discussing
assembly programming for Linux and OS X which use a different function
call interface. There is a discussion of the function call protocol differences
for Linux, OS X and Windows, so having one of the two books should be
sufficient for someone interested in programming on multiple operating
systems.
The Linux/OS X book contains examples using gdb for debugging. Alas
this seems to be impractical under Windows and, in fact, under OS X. The
nasm assembler does not generate sufficient information under Windows
or OS X to determine source code line numbers from memory addresses.
Ebe uses the nasm listing file along with the addresses of global symbols
like main to build translations internally while using memory addresses
for breakpoints and to determine line numbers with gdb. The ebe user
perceives a simple interface, but using gdb manually would require the
user to compute addresses for break points and observe source code in a
separate window. For this reason this book has abandoned the use of
debugging with gdb,
Another issue with Windows is the prevalence of assembly code
examples built around structured exception handling (SEH). The idea
there is to augment the code with data which describes the stack frame
and register usage in such a manner that SEH can “unwind” the stack to
determine which exception handler is the first to be found to handle a
particular exception. Exception handling is arguably a critical feature in
C++, but it is possibly too cumbersome for beginning assembly
programmers. The model used in the book is compatible with C and far
simpler than the code one finds which addresses SEH. Most likely any
assembly code used in C++ will be used for high efficiency and will not
generate any exceptions, so I feel the decision to write simpler assembly
code is useful in practice in addition to being far easier to understand.
1A switch was made in 2017 from yasm to nasm due to a .bss memory
reservation problem with yasm.
iv
Due to costs this book is printed in black and white. The pictures
captured from ebe would have been prettier and perhaps more useful in
color, but the cost of the book would have been roughly double the cost of
a black and white version. The added utility of color is certainly not worth
the extra cost. Generally the highlighted text in ebe is shown with a
colored background while the printed version presents this text with a
light gray background.
Most of the sample code execution in the first edition was illustrated
using gdb. This function has been superseded with screen captures from
ebe.
There are assignments using the computer from the very first chapter.
Not every statement will be fully understood at the start, but the
assignments are still possible.
The primary target for this book is beginning assembly language
programmers and for a gentle introduction to assembly programming,
students should study chapters 1, 2, 3, 5, 6, 7, 8, 9, 10 and 11. Chapter 4
on memory mapping is not critical to the rest of the book and can be
skipped if desired.
Chapters 12 through 15 are significantly more in depth. Chapter 15
is about data structures in assembly and is an excellent adjunct to
studying data structures in C/C++. The subject will be much clearer after
exposure to assembly language.
The final four chapters focus on high performance programming,
including discussion of SSE and AVX programming.
The author provides slides for classroom instruction along with
sample code and errata at http://rayseyfarth.com/asm.
If you find errors in the book or have suggestions for improvement,
please email the author as ray.seyfarth@gmail.com. Your
suggestions will help improve the book and are greatly appreciated.
You may also email me with questions or suggestions about ebe. Your
email will assist me with providing better on-line support and will help
improve the quality of the software.
Thank you for buying the book and I hope you find something
interesting and worthwhile inside.
v
Acknowledgements
No book is created in isolation. This book is certainly no exception. I am
indebted to numerous sources for information and assistance with this
book.
Dr. Paul Carter’s PC assembly language book was used by this author
to study 32 bit assembly language programming. His book is a free PDF
file downloadable from his web site. This is a 195 page book which covers
the basics of assembly language and is a great start at 32 bit assembly
language.
While working on this book, I discovered a treatise by Drs. Bryant and
O’Hallaron of Carnegie Mellon about how gcc takes advantage of the
features of the x86-64 architecture to produce efficient code. Some of their
observations have helped me understand the CPU better which assists
with writing better assembly code. Programmers interested in efficiency
should study their work.
I found the Intel manuals to be an invaluable resource. They provide
details on all the instructions of the CPU. Unfortunately the documents
cover 32 bit and 64 bit instructions together which, along with the huge
number of instructions, makes it difficult to learn assembly programming
from these manuals. I hope that reading this book will make a good
starting point, but a short book cannot cover many instructions. I have
selected what I consider the most important instructions for general use,
but an assembly programmer will need to study the Intel manuals (or
equivalent manuals from AMD).
I thank my friends Maggie and Tim Hampton for their editing
contributions to the book.
I am indebted to my CSC 203 - Assembly Language class at the
University of Southern Mississippi for their contributions to this book.
Teaching 64 bit assembly language has uncovered a few mistakes and
errors in the original Create Space book from July 2011. In particular I
wish to thank Isaac Askew, Evan Stuart, Brandon Wolfe and Zachary
Dillon for locating errors in the book.
Thanks to Ken O’Brien for helping locate mistakes in the book.
Thanks go to Christian Korn and Markus Bohm of Germany who have
vi
assisted with “debugging” this book. Thanks also to Francisco Perdomo of
the Canary Islands for assistance. Carsten Hansen of Denmark has also
assisted with debugging the book. David Langer has contributed some
code comment repairs.
Thanks to Quentin Gouchet for locating several typos which had
persisted for several years.
Thanks for Keiji Omori for pointing out that the stack size limits for
Linux processes are now quite generous. At some point there was a hard
kernel limit which could be changed by recompiling the kernel. Now it
can be changed in /etc/security/limits.conf.
Thanks to Wendell Xe for offering suggestions for improving the book
and also suggestions for ebe.
Last I thank my wife, Phyllis, and my sons, David and Adam, for their
encouragement and assistance. Phyllis and Adam are responsible for the
cover design for both this and the Create Space book.
vii
Contents
Preface .................................................................................................... iii
Acknowledgements ................................................................................ vi
Chapter 1 Introduction ........................................................................... 1
1.1 Why study assembly language?................................................... 2
So what is good about assembly language? ................................... 2
1.2 What is a computer? ..................................................................... 3
Bytes ................................................................................................. 4
Program execution ........................................................................... 4
1.3 Machine language ........................................................................ 5
1.4 Assembly language ....................................................................... 6
1.5 Assembling and linking ............................................................... 8
1.6 Using ebe to run the program ..................................................... 8
Chapter 2 Numbers .............................................................................. 12
2.1 Binary numbers .......................................................................... 12
2.2 Hexadecimal numbers ............................................................... 14
2.3 Integers ....................................................................................... 16
Binary addition .............................................................................. 18
Binary multiplication .................................................................... 19
2.4 Floating point numbers ............................................................. 19
Converting decimal numbers to floats ......................................... 22
Converting floats to decimal ......................................................... 23
Floating point addition .................................................................. 23
Floating point multiplication ........................................................ 24
2.5 Exploring with the bit bucket .................................................... 25
Chapter 3 Computer memory .............................................................. 28
3.1 Memory mapping ....................................................................... 28
3.2 Process memory model in Windows .......................................... 29
3.3 Memory example ........................................................................ 30
3.4 Examining memory with ebe ..................................................... 32
Setting a breakpoint ...................................................................... 33
Running a program and viewing a variable ................................. 33
Chapter 4 Memory mapping in 64 bit mode ........................................ 38
4.1 The memory mapping register ................................................... 38
4.2 Page Map Level 4 ........................................................................ 39
4.3 Page Directory Pointer Table ..................................................... 40
4.4 Page Directory Table .................................................................. 40
4.5 Page Table ................................................................................... 41
4.6 Large pages ................................................................................. 41
4.7 CPU Support for Fast Lookups .................................................. 41
Chapter 5 Registers ............................................................................... 44
5.1 Observing registers in ebe.......................................................... 46
5.2 Moving a constant into a register .............................................. 47
5.3 Moving values from memory to registers .................................. 49
5.4 Moving values from a register to memory ................................ 51
5.5 Moving data from one register to another ................................ 52
Chapter 6 A little bit of math ............................................................... 55
6.1 Negation ...................................................................................... 55
6.2 Addition ....................................................................................... 56
6.3 Subtraction .................................................................................. 58
6.4 Multiplication .............................................................................. 60
One operand imul .......................................................................... 60
Two and three operand imul ........................................................ 62
Testing for a Pythagorean triple ................................................... 62
6.5 Division ........................................................................................ 65
6.6 Conditional move instructions ................................................... 67
6.7 Why move to a register? ............................................................. 67
Chapter 7 Bit operations ....................................................................... 70
7.1 Not operation .............................................................................. 70
7.2 And operation .............................................................................. 71
7.3 Or operation ................................................................................ 72
7.4 Exclusive or operation ................................................................ 73
7.5 Shift operations ........................................................................... 74
7.6 Bit testing and setting ............................................................... 80
7.7 Extracting and filling a bit field ................................................ 84
Chapter 8 Branching and looping ........................................................ 88
8.1 Unconditional jump .................................................................... 88
8.2 Conditional jump ........................................................................ 90
Simple if statement ....................................................................... 91
If/else statement ............................................................................ 91
If/else-if/else statement ................................................................. 92
8.3 Looping with conditional jumps ................................................ 93
While loops ..................................................................................... 93
Counting 1 bits in a memory quad-word ...................................... 94
Do-while loops ................................................................................ 96
Counting loops ............................................................................... 98
8.4 Loop instructions ........................................................................ 99
8.5 Repeat string (array) instructions ............................................ 99
String instructions ....................................................................... 100
Chapter 9 Functions ........................................................................... 105
9.1 The stack ................................................................................... 105
9.2 Call instruction ......................................................................... 106
9.3 Linux Function calls ................................................................. 110
9.4 Return instruction .................................................................... 110
9.5 Function parameters and return value .................................. 112
9.6 Stack frames ............................................................................. 115
Function to print the maximum of 2 integers ............................ 119
9.7 Recursion .................................................................................. 122
Chapter 10 Arrays .............................................................................. 126
10.1 Array address computation ................................................... 126
10.2 General pattern for memory references................................ 127
10.3 Allocating arrays .................................................................... 130
10.4 Processing arrays ................................................................... 131
Creating the array ....................................................................... 132
Filling the array with random numbers .................................... 132
Printing the array ........................................................................ 133
Finding the minimum value ........................................................ 134
Main program for the array minimum ....................................... 134
10.5 Command line parameter array ............................................ 136
Chapter 11 Floating point instructions ............................................. 141
11.1 Floating point registers .......................................................... 141
11.2 Moving floating point data ..................................................... 143
Moving scalars .............................................................................. 143
Moving packed data ..................................................................... 143
11.3 Addition ................................................................................... 144
11.4 Subtraction .............................................................................. 144
11.5 Multiplication and division .................................................... 145
11.6 Conversion ............................................................................... 146
Converting to a different length floating point .......................... 146
Converting floating point to/from integer ................................... 147
11.7 Floating point comparison ..................................................... 147
11.8 Mathematical functions.......................................................... 148
Minimum and maximum ............................................................. 149
Rounding ....................................................................................... 149
Square roots .................................................................................. 150
11.9 Sample code............................................................................. 150
Distance in 3D .............................................................................. 150
Dot product of 3D vectors ............................................................ 150
Polynomial evaluation ................................................................. 151
Chapter 12 Accessing Files ................................................................. 155
12.1 File access with the Windows API ......................................... 156
Creating a file ............................................................................... 156
Writing to a file ............................................................................ 157
Complete program to create a file ............................................... 158
Reading from a file ....................................................................... 160
Program to copy a file .................................................................. 160
12.2 Portable C file access functions ............................................. 164
open .............................................................................................. 165
read and write .............................................................................. 167
lseek .............................................................................................. 167
close .............................................................................................. 168
Chapter 13 Structs .............................................................................. 170
13.1 Symbolic names for offsets .................................................... 171
13.2 Allocating and using an array of structs .............................. 174
Chapter 14 Using the C stream I/O functions .................................. 177
14.1 Opening a file ......................................................................... 178
14.2 fscanf and fprintf .................................................................... 179
14.3 fgetc and fputc ........................................................................ 179
14.4 fgets and fputs ........................................................................ 180
14.5 fread ........................................................................................ 181
14.5 fseek and ftell ......................................................................... 182
14.6 fclose ........................................................................................ 183
Chapter 15 Data structures ............................................................... 185
15.1 Linked lists ............................................................................. 185
List node structure ...................................................................... 186
Creating an empty list................................................................. 186
Inserting a number into a list ..................................................... 186
Traversing the list ....................................................................... 187
15.2 Doubly-linked lists ................................................................. 189
Doubly-linked list node structure ............................................... 190
Creating a new list ...................................................................... 190
Inserting at the front of the list .................................................. 190
List traversal................................................................................ 191
15.3 Hash tables ............................................................................. 192
A good hash function for integers ............................................... 193
A good hash function for strings ................................................. 194
Hash table node structure and array ......................................... 194
Function to find a value in the hash table ................................. 194
Insertion code ............................................................................... 195
Printing the hash table ................................................................ 196
Testing the hash table ................................................................. 198
15.4 Binary trees............................................................................. 199
Binary tree node and tree structures .......................................... 199
Creating an empty tree ................................................................ 200
Finding a key in a tree ................................................................. 200
Inserting a key into the tree ........................................................ 201
Printing the keys in order ........................................................... 202
Chapter 16 High performance assembly............................................ 205
16.1 Efficient use of cache .............................................................. 205
16.2 Common subexpression elimination ...................................... 207
16.3 Strength reduction .................................................................. 207
16.4 Use registers efficiently .......................................................... 207
16.5 Use fewer branches ................................................................. 207
16.6 Convert loops to branch at the bottom .................................. 208
16.7 Unroll loops ............................................................................. 208
16.8 Merge loops ............................................................................. 210
16.9 Split loops ................................................................................ 210
16.10 Interchange loops .................................................................. 210
16.11 Move loop invariant code outside loops ............................... 211
16.12 Remove recursion.................................................................. 211
16.13 Eliminate stack frames ........................................................ 212
16.14 Inline functions ..................................................................... 212
16.15 Reduce dependencies to allow super-scalar execution ...... 212
16.16 Use specialized instructions ................................................. 212
Chapter 17 Counting bits in an array ................................................ 215
17.1 C function ................................................................................ 215
17.2 Counting 1 bits in assembly ................................................... 216
17.3 Precomputing the number of bits in each byte .................... 218
17.4 Using the popcnt instruction ................................................. 219
Chapter 18 Sobel filter ........................................................................ 222
18.1 Sobel in C ................................................................................ 222
18.2 Sobel computed using SSE instructions ............................... 223
Chapter 19 Computing Correlation ................................................... 230
19.1 C implementation ................................................................... 230
19.2 Implementation using SSE instructions .............................. 231
19.3 Implementation using AVX instructions .............................. 233
Appendix A Installing ebe .................................................................. 238
Installing from binary packages ..................................................... 238
Installing from source on Windows ................................................ 238
Installing Cygwin ........................................................................ 239
Installing Qt ................................................................................. 239
Downloading the source code.......................................................... 239
Compiling ebe and installing .......................................................... 240
Appendix B Using ebe ........................................................................ 241
Major features ................................................................................. 241
Tooltips ......................................................................................... 241
Help .............................................................................................. 241
Menu ............................................................................................. 242
Movable toolbars .......................................................................... 242
Movable subwindows ................................................................... 242
Editing ............................................................................................. 244
Navigation .................................................................................... 245
Cut, copy and paste ..................................................................... 245
Undo/redo ..................................................................................... 246
Find and replace .......................................................................... 246
Deleting text................................................................................. 246
Using tabs .................................................................................... 246
Auto-indent .................................................................................. 246
Prettify ......................................................................................... 247
Indent/unindent ........................................................................... 247
Comment/uncomment ................................................................. 247
Word/number completion ............................................................ 247
Editing multiple files ................................................................... 247
Debugging ........................................................................................ 248
Breakpoints .................................................................................. 248
Running a program ...................................................................... 248
Terminal window ......................................................................... 249
Next and step ............................................................................... 250
Continue ....................................................................................... 250
Assembly Data window ................................................................ 250
Register window ........................................................................... 250
Floating point register window ................................................... 251
Projects ............................................................................................. 251
Viewing the project window ........................................................ 252
Creating a new project ................................................................. 252
Opening a project ......................................................................... 253
Adding files to a project ............................................................... 253
Closing a project ........................................................................... 253
Toy box.............................................................................................. 253
Bit bucket ......................................................................................... 254
Backtrace window ............................................................................ 255
Console ............................................................................................. 255
Ebe settings ...................................................................................... 256
Ebe Register Alias Macros .............................................................. 256
alias ............................................................................................... 257
fpalias ............................................................................................ 257
Appendix C Using scanf and printf .................................................... 258
scanf .................................................................................................. 258
printf ................................................................................................. 259
Appendix D Using macros in nasm .................................................... 261
Single line macros ............................................................................ 261
Multi-line macros ............................................................................. 262
Preprocessor variables ..................................................................... 263
Appendix E Sources for more information ......................................... 264
nasm user manual ........................................................................... 264
Stephen Morse’s 8086/8088 primer ................................................ 264
Dr. Paul Carter’s free assembly book ............................................. 264
64 bit machine level programming ................................................. 264
GDB manual .................................................................................... 265
Intel documentation ........................................................................ 265
Index .................................................................................................... 266
Chapter 1
Introduction
This book is an introduction to assembly language programming for the
x86-64 architecture of CPUs like the Intel Core processors and the AMD
Athlon, Zen and Opteron processors. While assembly language is no
longer widely used in general purpose programming, it is still used to
produce maximum efficiency in core functions in scientific computing and
in other applications where maximum efficiency is needed. It is also used
to perform some functions which cannot be handled in a high-level
language.
The goal of this book is to teach general principles of assembly
language programming. It targets people with some experience in
programming in a high level language (ideally C or C++), but with no prior
exposure to assembly language.
Assembly language is inherently non-portable and this text focuses on
writing code for the Windows operating system, taking advantage of the
free availability of excellent compilers, assemblers and debuggers. There
is a companion book for Linux and OS X which both use the same function
call ABI (application binary interface) which differs substantially from the
Windows function call ABI. Differences between assembly programming
for Linux and OS X systems will be detailed as the work unfolds
The primary goal of this text is to learn how to write functions callable
from C or C++ programs. This focus should give the reader an increased
understanding of how a compiler implements a high level language. This
understanding will be of lasting benefit in using high level languages.
A secondary goal of this text is to introduce the reader to using SSE
and AVX instructions. The coming trend is for the size of SIMD (Single
Instruction Multiple Data) registers to increase and it generally requires
assembly language to take maximum advantage of the SIMD capabilities.
1
1.1 Why study assembly language?
In a time when the latest fads in programming tend to be object-oriented
high-level languages implemented using byte-code interpreters, the trend
is clearly to learn to write portable programs with high reliability in
record time. It seems that worrying about memory usage and CPU cycles
is a relic from a by-gone era. So why would anyone want to learn assembly
language programming?
Assembly language programming has some of the worst “features”
known in computing. First, assembly language is the poster child for non-
portable code. Certainly every CPU has its own assembly language and
many of them have more than one. The most common example is the Intel
CPU family along with the quite similar AMD CPU collection. The latest
versions of these chips can operate in 16 bit, 32 bit and 64 bit modes. In
each of these modes there are differences in the assembly language. In
addition the operating system imposes additional differences. Further the
function call interface (ABI – application binary interface) employed in
x86-64 Linux and OS X systems differs from that used in Microsoft
Windows systems. Portability is difficult if not impossible in assembly
language.
An even worse issue with assembly language programming is
reliability. In modern languages like Java the programmer is protected
from many possible problems like pointer errors. Pointers exist in Java,
but the programmer can be blissfully unaware of them. Contrast this to
assembly language where every variable access is essentially a pointer
access. Furthermore high level language syntax resembles mathematical
syntax, while assembly language is a sequence of individual machine
instructions which bears no syntactic resemblance to the problem being
solved.
Assembly language is generally accepted to be much slower to write
than higher level languages. While experience can increase one’s speed, it
is probably twice as slow even for experts. This makes it more expensive
to write assembly code and adds to the cost of maintenance.
2
other hand an assembly programmer with similar skills can achieve
remarkable results. A good example is the Atlas (Automatically Tuned
Linear Algebra Software) library which can achieve over 95% of the
possible CPU performance. The Atlas matrix multiplication function is
probably at least 4 times as efficient as similar code written well in C. So,
while it is true that assembly language can offer performance benefits, it
is unlikely to outperform C/C++ for most general purpose tasks.
Furthermore it takes intimate knowledge of the CPU to achieve these
gains. In this book we will point out some general strategies for writing
efficient assembly programs.
One advantage of assembly language is that it can do things not
possible in high level languages. Examples of this include handling
hardware interrupts and managing memory mapping features of a CPU.
These features are essential in an operating system, though not required
for application programming.
So far we have seen that assembly language is much more difficult to
use than higher level languages and only offers benefits in special cases
to well-trained programmers. What benefit is there for most people?
The primary reason to study assembly language is to learn how a CPU
works. This helps when programming in high level languages.
Understanding how the compiler implements the features of a high level
language can aid in selecting features for efficiency. More importantly
understanding the translation from high level language to machine
language is fundamental in understanding why bugs behave the way they
do. Without studying assembly language, a programming language is
primarily a mathematical concept obeying mathematical laws.
Underneath this mathematical exterior the computer executes machine
instructions which have limits and can have unexpected behavior.
Assembly language skills can help in understanding this unexpected
behavior and improve one’s debugging skills.
Bytes
Modern computers access memory in 8 bit chunks. Each 8 bit quantity is
called a “byte”. The main memory of a computer is effectively an array of
bytes with each byte having a separate memory address. The first byte
address is 0 and the last address depends on the hardware and software
in use.
A byte can be interpreted as a binary number. The binary number
01010101 equals the decimal number 85 (64+16+4+1). If this number is
interpreted as a machine instruction the computer will push the value of
the rbp register onto the run-time stack. The number 85 can also be
interpreted as the upper case letter “U”. The number 85 could be part of a
larger number in the computer. The letter “U” could be part of a string in
memory. It’s all a matter of interpretation.
Program execution
A program in execution occupies a range of addresses for the instructions
of the program. The following 18 bytes constitute a very simple program
which simply exits (with status 5):
4
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER III
CHRISTMAS was approaching, and so far, Miss Glyn’s acquaintance
was confined to the village of Thornby. Now and then her aunt and
uncle went from home for a dine and a shoot, and on these
occasions, Mrs. Hesketh took charge of the young lady, who was
delighted to be her guest. At Oldcourt the atmosphere was
reposeful, the surroundings subdued and luxurious, and life was
leisured. Here it was seemingly ‘always afternoon.’ Letty was not
sure that she would enjoy it as a permanence; perhaps there was
too much of the hothouse in the air, but it was an agreeable change
from The Holt, where it was figuratively a perpetual Monday, with a
large washing on hand!
Cousin Maudie, an accomplished musician, encouraged her guest to
practise, played her accompaniments, and delighted in her voice.
Now Mrs. Fenchurch hated ‘squalling,’ had no ear, and was actually
proud of the fact, that she only knew “God Save the King” by seeing
people rise to their feet! Mrs. Hesketh also loved books, and the
tables at Oldcourt were loaded with the newest and best
publications, whether in magazine, pamphlet, or book form. Letty
laid greedy hands on these, but her hostess prudently withdrew a
certain amount—sociological and theological works—which were not
suitable reading for Sweet Seventeen.
Letty admired—and loved—her beautiful (if rather faded) hostess,
and the love and admiration were mutual. The new-comer had also
made friends with the Vicar and his wife. Mr. Denton, a hale, active
man of fifty, much praised by his own flock, and respected by
others. Mrs. Denton, though she had lost the use of her limbs
through sleeping in a damp bed, was her husband’s helper in the
parish, and it was surprising what an amount of work,
correspondence, and interviews centred round her sofa. She was a
frail, delicate Irishwoman, with a sense of humour, a cheerful
disposition, and a warm heart. Both she and her husband had taken
a fancy to the ‘little girl at The Holt,’ as they called her. She reminded
them of their own little girl, who had married and gone to India; to
see Letty flitting about the drawing-room, or seated in Mabel’s chair,
was a sight that gave them sincere pleasure. And the child was so
simple and unaffected, she looked into one’s face with such sweet
candid eyes, and was ever ready and glad to carry a message, sing,
play, or read, to the invalid, keenly interested in little village events,
and the weekly Madras letter—all she asked for in return, was to be
liked!
In a surprisingly short time, this attractive stranger had entirely
wound herself into the affections of the Dentons; her visits were not
frequent, but on hunting days, after she had exercised the dogs, she
would turn into the Rectory drawing-room, and pour out tea.
Immediately before Christmas, Mrs. Fenchurch, who was absorbed in
her correspondence, sent Letty down to the Rectory with a note.
When she arrived there it was still teatime, and she was surprised to
find that Mrs. Denton had a guest, a good-looking young man, who
appeared to find himself completely at home, since he was sitting on
the end of the sofa, nursing the Rectory cat.
“Oh, Letty, so there you are!” said Mrs. Denton. “Let me introduce
my nephew, Lancelot Lumley. He has come to spend Christmas with
us. Lancelot, this is Miss Glyn—you have heard of her?”
“We have met before,” he said eagerly; “a couple of months ago, I
think, in that railway shake-up?”
“Yes,” she assented, for here was the very travelling companion, who
had worn the buffer coat, “in the train.”
“It might have been a bad business,” he continued, and described
the incident to his aunt.
“I suppose it happened when you were on your way home?”
“Yes, I took first leave this year, and I’m sorry to say I have nearly
come to the end of it.”
“And give us only two days, Lance—you ought to be ashamed of
yourself!”
“The fact is, Frances wouldn’t let me off, and Colonel Kingsnorth lent
me a hunter; we have had some ripping good runs.”
“Ah!” said his aunt, “I think it was the hunter that wouldn’t let you
off.” Then, turning to Letty, she explained, “My brother-in-law,
Lancelot’s father, has a living twenty miles from here, at a place
called Sharsley; but he might as well be in London, for it’s so
dreadfully out of the way. We don’t see one another half a dozen
times in the year. This note,” holding it up to Letty, “is from your
aunt; she says she is so desperately busy, that she can’t help with
the church decorations. You know she has always undertaken the
pulpit, she sends you as her deputy, and will supply the usual pots of
palms and chrysanthemums. Lancelot,” looking over at her nephew,
“I intend to make use of you—you and Miss Glyn must do the pulpit
between you.”
“All right,” he answered, “I am agreeable, if Miss Glyn is; but let me
warn you that I have no more idea of decorating than I have of
making a watch.”
“I am afraid I am not much good either,” supplemented the girl; “I’ve
had no practice.”
“Miss Glyn left school two months ago,” explained Mrs. Denton.
“Were you sorry?” enquired the young man, looking over at her.
“Yes,” then with a burst of artless honesty—“I have been to school
nearly all my life.”
“She is coming out at the Hunt Ball early in January,” announced
Mrs. Denton.
“Yes, and I won’t know a single creature at it!”
“Oh, your aunt will find you plenty of partners. You could not be in
better hands. I feel sure she will make a most capable chaperon. It
is miraculous how she manages to get rid of the most hopeless
articles at bazaars. No one can resist her!”
“And you think she will get me off!” Letty laughed, and her laugh
was joyous.
“Not a doubt of it! Sooner than see you sitting out, she’d dance with
you herself. And about her note—so it is all settled, Letty. You will be
down here at eleven o’clock to-morrow; bring a large ball of twine,
and a pair of scissors, and Miss Hoare, the schoolmistress, will start
you. Remember I shall expect you and Lancelot to turn out the most
beautiful pulpit that has ever been seen in Thornby.”
“I can only say that I will do my best,” said Letty, rising.
“What! you are not going yet?”
“I am afraid I must. Aunt Dorothy has quantities of things she wants
me to do this evening—there’s the ticketing for the Christmas Tree.”
“Oh, poor child, I don’t envy you,” said Mrs. Denton with upraised
hands. “Well, in that case, I won’t detain you—Lancelot will escort
you home,” and subsequently he and the young lady left the room
together; she protesting, he assuring her that if she didn’t mind, he
would be glad to make the stroll an excuse for a pipe. Strange to
record, until that evening, Letty had never realised how short was
the distance between the Rectory and The Holt! Here in the
entrance hall she encountered her aunt; Mrs. Fen, who was
overwhelmed with affairs, wore a frowning brow, and carried half a
dozen parcels and a Directory.
“Who was that I heard speaking just now?” she enquired sharply; “it
sounded like a man’s voice?”
“It was only Mr. Lumley, Mrs. Denton’s nephew; he walked home
with me.”
“Oh, so he is here, is he?” she remarked over her shoulder, as she
swept into the smoking-room.
“Is that Lancelot Lumley you are talking of?” enquired Colonel
Fenchurch, who was reading. “I suppose he bicycled over to spend
Christmas—they find it hatefully dull without Mabel. You’d better ask
him up to lunch, or something.”
“I think at this time of the year, when one has so much to do,” and
Mrs. Fenchurch shot a glance at her husband, and then at Letty,
“people don’t expect to be entertained.”
“Of course not,” agreed the Colonel; “I expect Lumley to entertain
me—you forget that he is in my old regiment. I want to hear how
the old corps is getting along. To think that a boy who joined a few
years before I left, is commanding them now!”
“Oh, very well, Tom, then do as you like—ask him up to lunch or
dinner.”
“He is an awfully good sort,” Colonel Fenchurch explained to Letty;
“one of my favourites—none of your ‘haw-haw’ chaps. His father is a
poor parson, and this boy has worked himself on—getting
scholarships; he passed first out of Sandhurst. I believe he scarcely
cost old Lumley a ten-pound note—he’s the hope of the family—such
a good——”
“There—there, Tom,” interrupted his wife, “that’s quite enough about
young Lumley! He doesn’t interest Letty, or me. Now, Letty, I can’t
have you standing idle, run away, take off your things, and go out
into the laundry and help Fletcher to ticket the things for the
Christmas Tree.”
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com