100% found this document useful (3 votes)
13 views

Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture Zhirkov pdf download

The document is a promotional overview of the book 'Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture' by Igor Zhirkov, which covers fundamental concepts in assembly language and computer architecture. It includes detailed chapters on various topics such as basic computer architecture, assembly language, and the C programming language. Additionally, it provides links to other related educational resources and ebooks.

Uploaded by

websjwaho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
13 views

Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture Zhirkov pdf download

The document is a promotional overview of the book 'Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture' by Igor Zhirkov, which covers fundamental concepts in assembly language and computer architecture. It includes detailed chapters on various topics such as basic computer architecture, assembly language, and the C programming language. Additionally, it provides links to other related educational resources and ebooks.

Uploaded by

websjwaho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Low-Level Programming: C, Assembly, and Program

Execution on Intel® 64 Architecture Zhirkov pdf


download

https://ebookmeta.com/product/low-level-programming-c-assembly-
and-program-execution-on-intel-64-architecture-zhirkov/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Low-Level Programming Igor Zhirkov

https://ebookmeta.com/product/low-level-programming-igor-zhirkov/

x86 64 Assembly Language Programming with Ubuntu Ed


Jorgensen

https://ebookmeta.com/product/x86-64-assembly-language-
programming-with-ubuntu-ed-jorgensen/

Cambridge IGCSE and O Level History Workbook 2C - Depth


Study: the United States, 1919-41 2nd Edition Benjamin
Harrison

https://ebookmeta.com/product/cambridge-igcse-and-o-level-
history-workbook-2c-depth-study-the-united-states-1919-41-2nd-
edition-benjamin-harrison/

The Bad Sister 1st Edition J A Corrigan

https://ebookmeta.com/product/the-bad-sister-1st-edition-j-a-
corrigan/
Restoring Reefs 2nd Edition The Scientist

https://ebookmeta.com/product/restoring-reefs-2nd-edition-the-
scientist/

Paediatrics for the FRCS (Tr and Orth) Examination


First Edition. Edition (Consultant Paediatric
Orthopaedic Surgeon) Karen Daly (Editor)

https://ebookmeta.com/product/paediatrics-for-the-frcs-tr-and-
orth-examination-first-edition-edition-consultant-paediatric-
orthopaedic-surgeon-karen-daly-editor/

Aesthetics in Digital Photography 1st Edition Henri


Maître

https://ebookmeta.com/product/aesthetics-in-digital-
photography-1st-edition-henri-maitre/

Analysis and Synthesis of Singular Systems Emerging


Methodologies and Applications in Modelling
Identification and Control 1st Edition Zhiguang Feng
Jiangrong Li Peng Shi Haiping Du Zhengyi Jiang
https://ebookmeta.com/product/analysis-and-synthesis-of-singular-
systems-emerging-methodologies-and-applications-in-modelling-
identification-and-control-1st-edition-zhiguang-feng-jiangrong-
li-peng-shi-haiping-du-zhengyi-jiang/

The Paris Maid Totally heartbreaking and gripping World


War Two historical fiction 1st Edition Ella Carey

https://ebookmeta.com/product/the-paris-maid-totally-
heartbreaking-and-gripping-world-war-two-historical-fiction-1st-
edition-ella-carey/
Witch s Dawn 1st Edition Crystal Ash

https://ebookmeta.com/product/witch-s-dawn-1st-edition-crystal-
ash/
Low-Level

Programming

C, Assembly, and Program Execution on

Intel® 64 Architecture


Igor Zhirkov

Low-Level Programming

C, Assembly, and Program Execution on

Intel® 64 Architecture

Igor Zhirkov

Low-Level Programming: C, Assembly, and Program


Execution on Intel® 64 Architecture

Igor

Zhirkov

Saint Petersburg, Russia

ISBN-13 (pbk): 978-1-4842-2402-1

ISBN-13 (electronic): 978-1-4842-2403-8

DOI 10.1007/978-1-4842-2403-8

Library of Congress Control Number: 2017945327

Copyright © 2017 by Igor Zhirkov

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book.
Rather than use a trademark symbol with every occurrence of a
trademarked name, logo, or image we use the names, logos, and
images only in an editorial fashion and to the benefit of the
trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service


marks, and similar terms, even if they are not identified as such, is
not to be taken as an expression of opinion as to whether or not they
are subject to proprietary rights.

While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.

Cover image designed by Freepik

Managing Director: Welmoed Spahr

Editorial Director: Todd Green

Acquisitions Editor: Robert Hutchinson

Development Editor: Laura Berendson

Technical Reviewer: Ivan Loginov

Coordinating Editor: Rita Fernando

Copy Editor: Lori Jacobs

Compositor: SPi Global

Indexer: SPi Global


Distributed to the book trade worldwide by Springer
Science+Business Media New York,

233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-
SPRINGER, fax (201) 348-4505, e-mail

orders-ny@springer-sbm.com, or visit www.springeronline.com.


Apress Media, LLC is a California LLC

and the sole member (owner) is Springer Science + Business Media


Finance Inc (SSBM Finance Inc).

SSBM Finance Inc is a Delaware corporation.

For information on translations, please e-mail rights@apress.com, or


visit http://www.apress.com/

rights-permissions.

Apress titles may be purchased in bulk for academic, corporate, or


promotional use. eBook versions and licenses are also available for
most titles. For more information, reference our Print and eBook Bulk
Sales web page at http://www.apress.com/bulk-sales.

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.apress.com/9781484224021. For more
detailed information, please visit http://www.apress.com/source-
code.

Printed on acid-free paper

Contents at a Glance

About the Author


�������������������������������
�������������������������������
�������������������������������
�������xix About the Technical Reviewer
�������������������������������
�������������������������������
������������������xxi Acknowledgments
�������������������������������
�������������������������������
�������������������������������
���xxiii Introduction
�������������������������������
�������������������������������
�������������������������������
�������������xxv

■Part I: Assembly Language and Computer Architecture


��������������������� 1

■Chapter 1: Basic Computer Architecture


�������������������������������
�������������������������������
�3

■Chapter 2: Assembly Language


�������������������������������
�������������������������������
������������� 17

■Chapter 3: Legacy
�������������������������������
�������������������������������
�������������������������������
��� 39

■Chapter 4: Virtual Memory


�������������������������������
�������������������������������
�������������������� 47
■Chapter 5: Compilation Pipeline
�������������������������������
�������������������������������
������������ 63

■Chapter 6: Interrupts and System


Calls�����������������������������
�������������������������������
��� 91

■Chapter 7: Models of Computation


�������������������������������
�������������������������������
������ 101

■Part II: The C Programming Language


�������������������������������
������������� 127

■Chapter 8: Basics
�������������������������������
�������������������������������
�������������������������������
� 129

■Chapter 9: Type System


�������������������������������
�������������������������������
����������������������� 147

■Chapter 10: Code Structure


�������������������������������
�������������������������������
����������������� 181

■Chapter 11: Memory


�������������������������������
�������������������������������
���������������������������� 201

■Chapter 12: Syntax, Semantics, and Pragmatics


�������������������������������
��������������� 221

■Chapter 13: Good Code Practices


�������������������������������
�������������������������������
�������� 241

iii

■ Contents at a GlanCe

■Part III: Between C and Assembly


�������������������������������
������������������� 263

■Chapter 14: Translation Details


�������������������������������
�������������������������������
����������� 265

■Chapter 15: Shared Objects and Code Models


�������������������������������
�������������������� 291

■Chapter 16: Performance


�������������������������������
�������������������������������
��������������������� 327

■Chapter 17: Multithreading


�������������������������������
�������������������������������
����������������� 357

■Part IV: Appendices


�������������������������������
�������������������������������
���������� 397

■Chapter 18: Appendix A� Using gdb


�������������������������������
�������������������������������
����� 399

■Chapter 19: Appendix B� Using Make


�������������������������������
�������������������������������
�� 409

■Chapter 20: Appendix C� System Calls


�������������������������������
�������������������������������
� 415

■Chapter 21: Appendix D� Performance Tests Information


�������������������������������
��� 421

■Chapter 22: Bibliography


�������������������������������
�������������������������������
��������������������� 425

Index
�������������������������������
�������������������������������
�������������������������������
������������������������ 429
iv

Contents

About the Author


�������������������������������
�������������������������������
�������������������������������
�������xix About the Technical Reviewer
�������������������������������
�������������������������������
������������������xxi Acknowledgments
�������������������������������
�������������������������������
�������������������������������
���xxiii Introduction
�������������������������������
�������������������������������
�������������������������������
�������������xxv

■Part I: Assembly Language and Computer Architecture


��������������������� 1

■Chapter 1: Basic Computer Architecture


�������������������������������
�������������������������������
�3

1.1 The Core Architecture


....................................................................................................
3

1.1.1 Model of Computation


......................................................................................................
....................... 3
1.1.2 von Neumann Architecture
......................................................................................................
................ 3

1.2 Evolution
......................................................................................................
.................. 5

1.2.1 Drawbacks of von Neumann Architecture


............................................................................................... 5

1.2.2 Intel 64 Architecture


......................................................................................................
.......................... 6

1.2.3 Architecture Extensions


......................................................................................................
..................... 6

1.3 Registers
......................................................................................................
................. 7

1.3.1 General Purpose Registers


......................................................................................................
................ 8

1.3.2 Other Registers


......................................................................................................
................................ 11

1.3.3 System Registers


......................................................................................................
............................. 12

1.4 Protection Rings


......................................................................................................
.... 14

1.5 Hardware Stack


......................................................................................................
..... 14

1.6 Summary
......................................................................................................
............... 16

■ Contents

■Chapter 2: Assembly Language


�������������������������������
�������������������������������
������������� 17

2.1 Setting Up the Environment


......................................................................................... 17

2.1.1 Working with Code Examples


......................................................................................................
.......... 18

2.2 Writing “Hello, world”


..................................................................................................
18

2.2.1 Basic Input and Output


......................................................................................................
.................... 18

2.2.2 Program Structure


......................................................................................................
........................... 19
2.2.3 Basic Instructions
......................................................................................................
............................ 20

2.3 Example: Output Register Contents


............................................................................. 22

2.3.1 Local Labels


......................................................................................................
..................................... 23

2.3.2 Relative Addressing


......................................................................................................
......................... 23

2.3.3 Order of Execution


......................................................................................................
........................... 24

2.4 Function Calls


......................................................................................................
........ 25

2.5 Working with Data


......................................................................................................
. 28

2.5.1 Endianness
......................................................................................................
...................................... 28

2.5.2 Strings
......................................................................................................
............................................. 29

2.5.3 Constant Precomputation


......................................................................................................
................ 30

2.5.4 Pointers and Different Addressing Types


............................................................................................... 30

2.6 Example: Calculating String Length


............................................................................. 32

2.7 Assignment: Input/Output Library


................................................................................ 34

2.7.1 Self-Evaluation
......................................................................................................
................................ 35

2.8 Summary
......................................................................................................
............... 36

■Chapter 3: Legacy
�������������������������������
�������������������������������
�������������������������������
��� 39

3.1 Real mode


......................................................................................................
.............. 39

3.2 Protected Mode


......................................................................................................
..... 40

3.3 Minimal Segmentation in Long Mode


.......................................................................... 44

3.4 Accessing Parts of Registers


....................................................................................... 45
3.4.1 An Unexpected Behavior
......................................................................................................
.................. 45

3.4.2 CISC and RISC


......................................................................................................
.................................. 45

3.4.3 Explanation
......................................................................................................
...................................... 46

3.5 Summary
......................................................................................................
............... 46

vi

■ Contents

■Chapter 4: Virtual Memory


�������������������������������
�������������������������������
�������������������� 47

4.1 Caching
......................................................................................................
.................. 47

4.2 Motivation
......................................................................................................
.............. 47

4.3 Address Spaces


......................................................................................................
..... 48
Another Random Scribd Document
with Unrelated Content
health, and Lieutenant-Colonel Macdonell having been taken
prisoner on his passage from America, where he had been serving
with Fraser’s Highlanders, the command of the regiment devolved on
Major Lord Berridale.
The transports, with the 76th on board, touched at Portsmouth,
and while lying at Spithead, the regiment was ordered to the relief of
Jersey, which the enemy had attacked; but before reaching the
island the French had been repulsed. They then proceeded on the
voyage, and landed at New York in August. The flank companies
were then attached to the battalion, composed of the flank
companies of the other regiments, and the battalion companies were
quartered between New York and Staten Island. In February 1781,
these companies embarked for Virginia with a detachment of the
army, commanded by Major-General Phillips. The light company,
being in the second battalion of light infantry, also formed a part of
the expedition.
Lord Berridale, who had, by the death of his father this year,
become Earl of Caithness, having been severely wounded at the
siege of Charlestown, returned to Scotland, and was succeeded in
the command of the regiment by the Hon. Major Needham,
afterwards Earl of Kilmorey, who had purchased Major Donaldson’s
commission.
General Phillips landed at Portsmouth, Virginia, in March, and
having joined the detachment under General Arnold, the united
detachments formed a junction with the army of Lord Cornwallis in
May. The Macdonald Highlanders, on meeting with men who had
braved the dangers of the field, considered themselves as an inferior
race, and sighed for an opportunity of putting themselves on an
equality with their companions in arms, and they did not wait long.
The celebrated Marquis de la Fayette, anxious to distinguish
himself in the cause which he had espoused, determined to attack
Lord Cornwallis’s army, and in pursuance of this intention pushed
forward a strong corps, which forced the British picquets. He then
formed his line, and a warm contest immediately began, the weight
of which, on the side of the British, was sustained by the brigade of
Colonel Thomas Dundas, consisting of the 76th and 80th regiments.
These corps, which were on the left, were drawn up on an open
field, while the right of the line was covered by woods. Coming up in
the rear of the 76th, Lord Cornwallis gave the word to charge, which
being responded to by the Highlanders, they rushed forward with
great impetuosity upon the enemy, who, unable to stand the shock,
turned their backs and fled, leaving their cannon and 300 men, killed
and wounded, behind them.[420]
After the surrender of Lord Cornwallis’s army, the 76th was
marched in detachments as prisoners to different parts of Virginia.
During their confinement, many attempts were made by their
emigrant countrymen, as well as by the Americans, to induce them
to join the cause of American independence; but not one of them
could be induced by any consideration to renounce his allegiance.
The regiment, on its return to Scotland, was disbanded in March
1784 at Stirling Castle.
F O OT N OT E S :
[418] Stewart.
[419] Ibid.
[420] “At the moment Lord Cornwallis was giving the orders to charge,
a Highland soldier rushed forward and placed himself in front of his
officer, Lieutenant Simon Macdonald of Morar, afterwards major of the
92d regiment. Lieutenant Macdonald having asked what brought him
there, the soldier answered, ‘You know that when I engaged to be a
soldier, I promised to be faithful to the king and to you. The French
are coming, and while I stand here, neither bullet nor bayonet shall
touch you, except through my body!’
“Major Macdonald had no particular claim to the generous devotion of
this trusty follower, further than that which never failed to be binding
on the true Highlander,—he was born on his officer’s estate, where he
and his forefathers had been treated with kindness,—he was
descended of the same family (Clanranald),—and when he enlisted he
promised to be a faithful soldier. He was of the branch of the
Clanranald family, whose patronymic is Maceachen, or the sons of
Hector; the same branch of which Marshal Macdonald, Duke of
Tarentum, is descended.”—Stewart.
AT H O L E H I G H L A N D E R S ,
OR
OLD SEVENTY-SEVENTH HIGHLAND REGIMENT.
1778–1783.
Raising of the Regiment—Ireland—Mutiny—Disbanded.

On the application of the young Duke of Athole, government granted


him authority to raise a regiment of 1000 men for the service of the
State, with power to appoint officers. The command of this corps
was given to Colonel James Murray, son of Lord George Murray.
The Athole Highlanders were embodied at Perth, and in June 1778
were marched to Port-Patrick, and embarked for Ireland, where they
remained during the war. They were thus deprived of an opportunity
of distinguishing themselves in the field; but their presence in
Ireland was attended with this advantage, that they supplied the
place of other troops, who would probably have been less exemplary
in their conduct amongst a people whose passions were excited by
misgovernment.
The terms on which the men had enlisted were to serve for three
years, or during the war. On the conclusion of hostilities, they, of
course, expected to be disbanded; but instead of this they were
transported to England, and marched to Portsmouth for embarkation
to the East Indies. On the march they were made acquainted with
the intentions of Government; and so far from objecting to a
continuance of their service, they showed no disinclination to
embark, and when they first saw the fleet at Spithead, as they
crossed Portsdown-hill, they pulled off their bonnets, and gave three
cheers for a brush with Hyder Ali. They had scarcely, however, taken
up their quarters at Portsmouth, when the face of matters changed.
The minds of the men, it is said, were wrought upon by emissaries
from London, who represented the unfaithfulness of Government in
sending them abroad after the term of their service had expired. It
was even insinuated that they had been sold to the East India
Company at a certain sum per man, and that the officers were to
divide the money amongst themselves. These base
misrepresentations had their intended effect, and the result was that
the soldiers resolved not to embark. The authority of the officers
was despised; and after a scene of uproar and confusion, which
lasted several days, during which the Highlanders attempted to
obtain possession of the main-guard and garrison parade, the order
to embark was countermanded by Government.
One account of this affair, dated at Portsmouth, and published in
February 1783, contains the following details:—“The Duke of Athole,
his uncle, Major-General Murray, and Lord George Lennox, have
been down here, but the Athole Highlanders are still determined not
to go to the East Indies. They have put up their arms and
ammunition into one of the magazines, and placed a very strong
guard over them, whilst the rest of the regiment sleep and refresh
themselves. They come regularly and quietly to the grand parade,
very cleanly dressed, twice a-day, their adjutant and other officers
parading with them. One day it was proposed to turn the great guns
of the rampart on the Highlanders; but this scheme was soon
overruled. Another time it was suggested to send for some marching
regiments quartered near the place, upon which the Highlanders
drew up the draw-bridges, and placed sentinels at them.”
“You may be assured,” says another account, “I have had my
perplexities since the mutiny commenced in the 77th regiment; but I
must do the men the justice to confess, that excepting three or four
drunken fellows, whose impudence to their officers could only be
equalled by their brutality, the whole regiment have conducted
themselves with a regularity that is surprising; for what might not
have been expected from upwards of one thousand men let loose
from all restraint? Matters would never have been carried to the
point they have, but for the interference of some busy people, who
love to be fishing in troubled waters. The men have opened a
subscription for the relief of the widow of the poor invalid,[421] for
whose death they express the greatest regret. On their being
informed that two or three regiments were coming to force them to
embark, they flew to their arms, and followed their comrade leaders
through the town, with a fixed determination to give them battle;
but on finding the report to be false, they returned in the same
order to their quarters. The regiment is not to go to the East Indies
contrary to their instructions, which has satisfied them, but will be
attended with disagreeable consequences to the service; and since
the debates in the House of Commons on the subject, I should not
wonder if every man intended for foreign service refused going, for
the reasons then given, which you may depend on it they are now
well acquainted with.”
Mr Eden, afterwards Lord Auckland, secretary for Ireland, in the
Parliamentary debates on the mutiny, bore honourable testimony to
the exemplary conduct of the regiment in Ireland:—“He had
happened,” he said, “to have the 77th regiment immediately under
his observation during sixteen months of their garrison duty in
Dublin, and though it was not the most agreeable duty in the
service, he must say that their conduct was most exemplary. Their
officers were not only men of gentlemanly character, but peculiarly
attentive to regimental discipline. He having once, upon the sudden
alarm of invasion, sent an order for the immediate march of this
regiment to Cork, they showed their alacrity by marching at an
hour’s notice, and completed their march with a despatch beyond
any instance in modern times, and this too without leaving a single
soldier behind.”
This unfair and unworthy attempt on the part of Government
created a just distrust of its integrity, and had a most pernicious
effect on its subsequent endeavours to raise men in the Highlands.
Alluding to this unfortunate affair, General Stewart observes, that “if
Government had offered a small bounty when the Athole
Highlanders were required to embark, there can be little doubt they
would have obeyed their orders, and embarked as cheerfully as they
marched into Portsmouth.”
The fault resting entirely with Government, it wisely abstained
from pushing matters further by bringing any of the men to trial.
The regiment was immediately marched to Berwick, where it was
disbanded in April 1783, in terms of the original agreement.
F O OT N OT E :
[421] He was killed when the Highlanders made the attempt to take
possession of the main-guard and garrison parade.
SEAFORTH’S HIGHLANDERS,
FORMERLY
THE SEVENTY-EIGHTH,
NOW
THE SEVENTY-SECOND REGIMENT,
OR DUKE OF ALBANY’S OWN HIGHLANDERS.
I.

1778–1858.
Raising the Regiment—First Officers—Disaffection at Leith—“The affair of the
Macraes”—Embarkation for India—Death of Lord Seaforth—Effects of scurvy—
Joining Sir Eyre Coote’s army—Joining Major-General James Stuart’s army—Led
by Colonel Fullarton against Tippoo Sahib—Palghatcherri—Number of the
Regiment changed to 72nd—Recruiting—War with Tippoo Sahib—Stuart’s
dilemma—Palghatcheri—Ordered home—Fort Dindigal—Stuart takes
Palghatcheri—Lord Cornwallis—Bangalore—Ootradroog—Forlorn hope of
Sergeant Williams—Valour of the 72nd—Siege of Seringapatam—Storming of
Savendroog—Ootradroog—Sailing for India—The Mauritius—Landing at the
Cape of Good Hope—Arrival at Calcutta—Lands again at Cape Town—Captain
Gethin’s death—Return home—Permitted to assume the name of the Duke of
Albany’s Own Highlanders—The Cape of Good Hope again—Graham’s Town—
The Kaffir War in 1835—The Governor-General at the camp—The Kaffirs attack
the Fingoes—End of the Kaffir War—Permitted to add “Cape of Good Hope” to
the colours—At Graham’s Town—At Cape Town—Home.

Kenneth Mackenzie, grandson


of the Earl of Seaforth, whose
estate and title were forfeited
in consequence of his
concern in the rebellion of
1715, having purchased the
family property from the
Crown, was created an Irish
peer, by the title of Lord
Viscount Fortrose. In the year
1771, Government restored
The late Duke of York’s Cipher and Coronet.
Hindoostan. to him the family title of Earl
Cape of Good Hope. of Seaforth. To evince his
Sevastopol. gratitude for this
Central India.
magnanimous act, the Earl,
in the year 1778, offered to raise a regiment on his estate for
general service. This offer being accepted by his Majesty, a corps of
1130 men was speedily raised, principally by gentlemen of the name
of Mackenzie, his lordship’s clan.
Of these about 900 were Highlanders, 500 of whom were raised
upon Lord Seaforth’s own estate, and the remainder upon the
estates of the Mackenzies of Scatwell, Kilcoy, Applecross, and
Redcastle, all of whom had sons or brothers in the regiment. The
remainder were raised in the Lowlands, of whom 43 were English
and Irish.
The following is the first list of officers:—

Lieut.-Col.-Commandant—Kenneth, Earl of Seaforth.


Major—James Stuart (from Capt. 64th Regt.)
Captains.
T. F. M. Humberston. George Mackenzie.
Robert Lumsdaine. Hugh Frazer.
Peter Agnew. Hon. Thos. Maitland.
Kenneth Mackenzie.[422] Charles Halkett.[423]
Captain Lieutenant—Thomas Frazer.
Lieutenants.
Donald Moody. George Mackenzie.
William Sutherland. Charles Gladoning.
Colin Mackenzie. William Sinclair.
Kenneth Mackenzie. Charles Mackenzie.
Patrick Haggard. John Campbell.
Thomas Mackenzie. James Stewart.
George Innes. Robert Marshall.
Charles M’Gregor. Philip Anstruther.
David Melville. Kenneth Macrae.
George Gordon. John M’Innes.
James Gualie.
Ensigns.
James Stewart. Robert Gordon.
James Finney. John Mitchell.
Aulay M’Aulay. Ewen M’Lennan.
Malcolm M’Pherson. George Gordon.
Staff.
Chaplain.—Wm. Mackenzie.
Surgeon.—John Walters.
Adjutant.—James Finney.
Quarter-master.—George Gunn.
The regiment was embodied at Elgin, in May 1778, and was
inspected by General Skene, when it was found so effective that not
one man was rejected. In the month of August the regiment
marched to Leith for embarkation to the East Indies; but they had
not been quartered long in that town when symptoms of disaffection
began to appear among them. They complained of an infringement
of their engagements, and that part of their pay and bounty was in
arrear. Being wrought upon by some emissaries, the men refused to
embark, and, marching out of Leith with pipes playing, and two
plaids fixed on poles instead of colours, they took up a position in
the immediate vicinity of Edinburgh on Arthur’s Seat, on which they
remained several days. During this time they were amply supplied
with provisions and ammunition by the inhabitants of the capital,
who had espoused their quarrel. The causes of complaint having
been inquired into, after much negotiation, in which the Earls of
Dunmore and Seaforth, Sir James Grant of Grant, and other
gentlemen connected with the Highlands, took an active and
prominent part, the grievances were removed, and the soldiers
being satisfied, marched down the hill with pipes playing, with the
Earls of Seaforth and Dunmore, and General Skene at their head,
and returned to their quarters at Leith. From the great number of
the clan Macrae that were in the regiment, the mutiny was called
“The affair of the Macraes.”
At Leith the regiment embarked with the greatest cheerfulness,
accompanied by their colonel, the Earl of Seaforth. The intention of
sending them to India being for the present abandoned, one half of
the regiment was sent to Guernsey, and the other to Jersey. At the
end of April 1781, however, both divisions assembled at Portsmouth,
where, on the 12th of June, they embarked for the East Indies,
being then 973 strong, rank and file. Though the men were all in
excellent health, they suffered so severely from the effects of the
voyage and the change of food, that before reaching Madras on the
2nd of April 1782, 247 of them had died of scurvy, and out of all that
landed, only 369 were fit to carry arms. The death of Seaforth, their
chief, who expired before the regiment reached St Helena, threw a
damp over the spirits of the men, and it is said to have materially
contributed to that prostration of mind which made them more
readily the victims of disease.
As the service was pressing, such of the men as were able to
march were immediately sent up the country under Major James
Stuart; but many of them being still weak from the effects of scurvy,
suffered greatly on the march. The men were sinewy and robust,
and such as had escaped the scurvy were greatly injured by the
violence of the sun’s beams, the effects of which were not so
injurious to men of more slender habits. They joined the army of Sir
Eyre Coote at Chingleput in the beginning of May; but he found
them so unfit for service that he ordered the corps into quarters,
and put the few who remained healthy into the 73rd or Macleod’s
Highlanders, the only European corps then with the army.
The men gradually recovered, and in the month of October
upwards of 600 were fit for duty. The colours of the regiment were
again unfolded, and in April 1783 they joined the army destined to
attack Cuddalore, under Major-General James Stuart (of the family
of Torrance).
On the 25th of June, the enemy made a sally on the British lines,
but were repulsed at every point, losing 150 men in killed and
prisoners, including among the latter the Chevalier Dumas.
Notwithstanding the termination of hostilities with France in
January 1783, the war with Tippoo Sahib was continued. Colonel
Fullarton, who had marched on Cuddalore, finding he was no longer
needed in that quarter, retraced his steps southward, reinforced by
Seaforth’s Highlanders and other troops, thus augmenting his force
to upwards of 13,000 men. This army was employed several months
in keeping down some turbulent chiefs; and in October Colonel
Fullarton marched on Palghatcherri, after securing some
intermediate forts. Lieutenant-Colonel Humberston Mackenzie, of the
100th regiment, who succeeded about this time to the command of
the 78th, in consequence of the death of his cousin, the Earl of
Seaforth, as well as to his title and estates, had intended to attack
this place the preceding year, but he abandoned the attempt. After a
fatiguing march through thick woods and a broken country, Colonel
Fullarton reached the place early in November, and immediately laid
siege to it. The garrison might have made a long and vigorous
defence; but an event occurred which hastened the fall of
Palghatcherri. The enemy having taken shelter from a shower of
rain, the Hon. Captain Sir Thomas Maitland advanced unperceived
with his flank corps, and drove the enemy through the first gateway,
which he entered; but his progress was checked at the second,
which was shut. Being immediately reinforced, he prepared to force
an entrance; but the enemy, afraid of an assault, immediately
surrendered.
On the 30th of April this year the regiment lost their new colonel,
who died of wounds received on board the “Ranger” sloop of war on
the 7th of April 1783, in an action with a Mahratta fleet while on his
return from Bombay. He was succeeded in the command of the
regiment by Major-General James Murray, from the half-pay of the
77th regiment.
In consequence of the peace, Seaforth’s regiment having been
raised on the condition of serving for three years, or during the war,
—those of the men that adhered to this agreement were allowed to
embark for England; while those that preferred staying in the
country received the same bounty as other volunteers. The number
of men who claimed their discharge on the 10th of August 1784
reduced the regiment to 425 rank and file; but so many men
volunteered into the corps from the different regiments ordered
home (among whom was a considerable number of Highlanders who
had formerly enlisted into the 100th Regiment with Colonel
Humberston Mackenzie), that the strength was at once augmented
to 700 men. At the end of the next year the regiment received 423
men from various regiments.
On the 12th of September 1786 the number of the regiment was
changed to the 72nd, in consequence of the reduction of senior
regiments.
On the 25th of December 1787 the establishment was reduced to
the following numbers:—1 captain, 1 lieutenant-colonel and captain,
1 major and captain, 7 captains, 22 lieutenants, 8 ensigns, 1
chaplain, 1 adjutant, 1 quartermaster, 1 surgeon, 2 mates, 30
sergeants, 40 corporals, 20 drummers, 2 fifers, 710 privates,
including 40 contingent men.
It was soon found necessary, however, again to increase the
strength of the regiment, and recruiting was carried on with success.
A considerable detachment joined on the 18th of August 1789; so
that in the following year, when war commenced with Tippoo, the
72nd was nearly 800 strong, while the men were healthy, seasoned
to the climate, well-disciplined, and highly respectable in their moral
conduct. In this highly-efficient state they formed part of the army
under Major-General Meadows on the 23rd of July 1790.
The first service of the 72nd was under Colonel Stuart, being
ordered along with other troops to attack Palghatcheri, which on a
former occasion had been the scene of success to a corps now
destined to sustain a disappointment. The detachment being
overtaken by the rains which fell in almost unprecedented
abundance, Colonel Stuart got so beset with the mountain streams
that, for a short time, he could neither proceed nor retire; and when
the waters abated he returned to headquarters. In this enterprise
the 78th had Captain George Mackenzie and 23 rank and file killed,
and 3 sergeants and 44 rank and file wounded.
After a short rest, the same officer, with the same troops under his
command, was detached against Dindigul, before which he arrived
on the 16th of August 1790. This is one of those granite rocks so
common in that part of India. The fort on the summit had lately
been repaired, and mounted with 14 guns, the precipice allowing of
only one point of ascent. The means of attack, both in guns and
ammunition, were very deficient. A small breach, however, was
made on the 20th; and Colonel Stuart resolved to assault, small as
the breach was, judging that more loss would be sustained by delay
than by an immediate attack, since, in addition to other difficulties,
he was short of ammunition. Accordingly, on the evening of the 21st
of August, the attack was made. The defences were unusually
complete, and the resistance more determined than had been
experienced on any former occasion. Every man that reached the
summit of the breach was met and forced down by triple rows of
spikes from the interior of the rampart. After a bold but fruitless
effort, they were repulsed with loss. But the enemy was so
intimidated, and dreaded so much the consequence of a second and
perhaps successful attack, that he surrendered next morning,
ignorant of their opponent’s want of ammunition, the real cause of
the premature attack.
Colonel Stuart again proceeded against Palghatcherri, and on the
21st of September opened two batteries within five hundred yards of
the place; and though the fortification had been greatly
strengthened since the time the place was taken by Colonel
Fullarton, he succeeded the same day in making a practicable
breach. Preparations were made for an assault the following
morning; but before daylight the enemy offered to surrender on
terms which were acceded to. Leaving a garrison in the place,
Colonel Stuart joined the army in the neighbourhood of Coimbatore
on the 15th of October, after which the regiment followed all the
movements of the army till the 29th of January 1791, when Lord
Cornwallis arrived and assumed the command.
The 72nd was engaged along with the 71st in the second attack
on Bangalore, the first attack on Seringapatam, and the attack on
Savendroog and Ootradroog. On the evening of March 7, 1791, the
pettah of Bangalore was stormed, and the siege of the town was
immediately commenced. During the night, the 72nd Highlanders
were posted under the outer pettah wall, close to the gate. “The
enemy kept up a sharp fire; their shots, which were many of them
thirty-two pounders, came very close to the regiment, making a
great rattling in the trees and bamboo hedge, near the line; but no
casualties occurred.”[424]
At four o’clock on the afternoon of the 20th of March, six
companies of the regiment marched into the trenches; and on the
evening of the following day the regiment was ordered to prepare to
take part in storming the fortress. The grenadier company was to
join the storming party appointed to advance by the left approach;
the light company, that by the right approach; and the battalion
companies were formed on the right of the parallel, to support the
grenadiers. Three of the 72nd grenadiers joined the forlorn hope
under Sergeant Williams of the 76th regiment. Lieutenant Campbell
states in his Journal:—“The storming party primed and loaded, and
sat down on their arms. Our batteries, both gun and mortar, kept
firing frequently during the evening. At a quarter before eleven we
got into motion; an opening was made in the centre of the second
parallel; the signal for storming was given—three guns in quick
succession—and out we rushed. The covered way instantly appeared
as a sheet of fire, seconded from the fort, but with no aim or effect;
our batteries answered with blank cartridge; and we were in the
covered way in a moment, and on the breach as quick as thought. I
pushed on, carried forward by a powerful impulse, and found myself
at the top of the breach with the front files. The grenadiers
immediately turned off to the right with a huzza; their progress was
suddenly stopped by an opening; the fort was hung with blue lights;
a heavy fire was opened upon us, but with little effect; the difficulty
was overcome, and our troops ascended the ladders with every
possible expedition. The grandest and most striking sight I ever
beheld was the rushing up of the troops to the top of the breach,
and the ascent of the grenadiers in crowds by the scaling-ladders.
We now heard the grenadiers’ march beating in every quarter; our
soldiers shouted with joy, and we swept round the ramparts, with
scarce anything to oppose us. Every enemy that appeared had a
bayonet in him instantly. The regiments that supported us came in
by the gateway, and cleared the town below, where numbers were
killed. In two hours we were in thorough possession of the fort, and
Lieutenant Duncan, of the 71st regiment, pulled down the flag and
put his own sash in its place. The Union flag was afterwards hoisted,
and the troops gave three cheers.”
On this occasion the regiment had 6 rank and file killed, and 1
sergeant and 23 rank and file wounded. In the orders issued on the
following day by Lord Cornwallis, the following passage occurs:—
“The conduct of all the regiments which happened, in their tour, to
be on duty that evening did credit in every respect to their spirit and
discipline; but his Lordship desires to offer the tribute of his
particular and warmest praise to the European grenadiers and light
infantry of the army, and to the 36th, 72nd, and 76th regiments,
who led the attack and carried the fortress, and who by their
behaviour on that occasion furnished a conspicuous proof that
discipline and valour in soldiers, when directed by zeal and capacity
in officers, are irresistible.
“Lieut.-Colonel Stuart (72nd Regiment) may be assured that Lord
Cornwallis will ever retain the most grateful remembrance of the
valuable and steady support which that officer afforded him, by his
military experience and constant exertions to promote the public
service.”
The army advanced to the siege of Seringapatam on the 4th of
May, and on the 15th as it approached the place, the Sultan’s
position was attacked by the 72nd, with other regiments. The enemy
was driven from every post, and towards the close of the action the
72nd ascended an eminence and captured a round redoubt. The
regiment had about 20 men killed and wounded, among the latter
being Captain Braithwaite and Lieutenant Whitlie. The army, nearly
all its provisions and other stores being exhausted, retreated to the
vicinity of Bangalore.
On the morning of the 21st of December the 72nd took part in the
storm of the strong fortress of Savendroog. The right attack was
made by the light companies of the 71st and 72nd, supported by a
battalion company of the 72nd; the left attack by the two flank
companies of the 76th and grenadier company of the 52nd; the
centre attack under Major Fraser of the 72nd, by the grenadiers and
two battalion companies of the 72nd, two companies of the 52nd,
the grenadiers of the 71st, and four companies of sepoys, supported
by the sixth battalion of sepoys; the whole under Lieut.-Colonel
Nisbitt, of the 52nd regiment. The storming-parties proceeded to
their stations; the band of the 52nd took post near them, and
suddenly striking up the tune Britons, strike home, the whole rushed
forward with the most heroic ardour. The Mysoreans made a feeble
defence, and in less than two hours the British were in possession of
the fort, with the trifling loss of five men wounded. The troops were
thanked in General Orders, for their very gallant conduct.
Two days afterwards the troops advanced against Ootradroog. On
the 24th, two battalion companies of the 52nd and 72nd regiments,
supported by the 26th sepoys, attacked the pettah by escalade, and
were speedily in possession of the town. “Lieutenant M’Innes, senior
officer of the two 72nd companies, applied to Captain Scott for
liberty to follow the fugitives up the rock, saying he should be in
time to enter the first gateway with them. The captain thought the
enterprise impracticable. The soldiers of M’Innes’s company heard
the request made, and not doubting of consent being given, had
rushed towards the first wall, and were followed by M’Innes. The
gate was shut: but Lieutenant M’Pherson arrived with the pioneers
and ladders, which were instantly applied, and our people were
within the wall as quick as thought, when the gate was unbolted,
and the two companies entered. The enemy, astonished at so
unexpected an attempt, retreated with precipitation. M’Innes
advanced to the second wall, the men forced open the gate with
their shoulders, and not a moment was lost in pushing forward for
the third wall; but the road, leading between two rocks, was so
narrow that only two could advance abreast; the pathway was, in
consequence, soon choked up, and those who carried the ladders
were unable to proceed. At the same time, the enemy commenced
throwing huge stones in numbers upon the assailants, who
commenced a sharp fire of musketry, and Lieut.-Colonel Stuart, who
had observed from a distance this astonishing enterprise, sent
orders for the grenadiers not to attempt anything further. Lieutenant
M’Pherson forced his way through the crowd, causing the ladders to
be handed over the soldiers’ heads, from one to another, and before
the colonel’s orders could be delivered, the gallant Highlanders were
crowding over the third gateway. The enemy fled on all hands; the
foremost of our men pursued them closely, and gained the two last
walls without opposition—there were five walls to escalade. The
garrison escaped by the south-east side of the fort, over rocks and
precipices of immense depth and ruggedness, where many must
have lost their lives. By one o’clock, our two companies were in
possession of every part of the fort, and M’Innes had planted the
colours on the highest pinnacle, without the loss of a single man.
The Kiledar and two of his people were taken alive. Colonel Stuart
declared the business to be brilliant and successful, beyond his most
sanguine hopes.”[425] Thus was the important fortress of Outra-
Durgum captured by two companies of Highlanders (Major Petrie’s,
and Captain Hon. William M. Maitland’s) of the 72nd regiment; the
officers with the two companies were Lieutenants M’Innes, Robert
Gordon, —— Getty, and Ensign Andrew Coghlan. Lieutenant
M’Pherson conducted the pioneers. They all were thanked in General
Orders by Earl Cornwallis, who expressed his admiration of the
gallantry and steadiness of the officers and soldiers engaged in this
service.
The rainy season being over, it was resolved to make a second
attack on Seringapatam, to which place the army marched in the
beginning of February 1792. The sultan had taken up a formidable
position to cover his capital, and was attacked during the night of
the 6th of February. The regiment formed part of the left division
under Lieutenant-Colonel Maxwell, which advanced to the attack in
the following order:—Grenadier Company, 72nd; Light Company,
72nd, with scaling ladders; pioneers; 23rd Native Infantry; 72nd
regiment; 1st and 6th Native Infantry. The share taken by the 72nd
in the attack on the place we shall give in the words of the journal of
Lieutenant Campbell of the 72nd, quoted several times already:—
“We (the 72nd) moved from the left along the north side of the
ridge of hills extending from the Carrighaut pagoda to the Cappalair
rocks; by ten at night we found ourselves near the base of the hill,
where the officers were directed to dismount. When we were about
two hundred yards from the lower entrenchment, our grenadiers
filed off from the right with trailed arms, a serjeant and twelve men
forming the forlorn hope. When about fifty yards from the works, the
sentinel challenged us, and instantly fired his piece, which was
followed by a scattered fire from the rest of their party. We rushed
among them, and those who did not save themselves by immediate
flight were shot or bayoneted. The greatest number of them ran
down to the Carriagat pagoda, where they made a stand, and kept
up a smart fire until we were almost close to them; then retired
under our fire to the foot of the hill, where they were joined by a
strong body from the plain, and made a stand at a small choultry (or
caravanserai), from which a flight of steps led to the bridge across
the nulla. By this time the general attack on the enemy’s lines had
commenced, and there was an almost connected sheet of fire from
right to left—musketry, guns, and rockets rending the air with their
contending noise. We sat upon the brow of the hill a few minutes,
while our men were recovering their breath, and had a commanding
prospect of the whole attack, though nearly three miles in extent, as
we contemplated the scene before us, the grandest, I suppose, that
any person there had beheld. Being rested a little, Colonel Maxwell
led us down the hill under a smart fire. We rushed forward and
drove the enemy across the nulla in great haste, although they stood
our approach wonderfully. We crossed the bridge under a constant
fire, the enemy retreating as we advanced; we crossed the Lokany
river, the opposite bank of which was well covered by a bound-
hedge, and their fire did execution. A serjeant of grenadiers was
killed, Captain Mackenzie mortally wounded, Major Fraser and
Captain Maitland shot through their right arms, besides other
casualties. After we had penetrated the bound-hedge, the enemy
took post behind an extensive choultry; but nothing could stop the
ardour of our men: we charged without loss of time, and soon
dislodged the enemy, who retreated along the banks of the Cavery
to a second choultry, where their numbers were reinforced. We had
now got into their camp, upon the right flank of their lines; they
retreated steadily before us, and our fire and bayonets did great
execution among them, the road being strewed with their bodies.
We charged and dislodged them from the second choultry; here
Lieutenant M’Pherson of the grenadiers was wounded. We pursued
the enemy to a large pagoda; they attempted to cross the river, but
the place was so crowded with guns, tumbrils, bullocks, elephants,
camels, followers, and Heaven knows what, that we were in the
midst of them before they could escape, and for some minutes there
was nothing but shooting and bayoneting. Colonel Maxwell came up
with the 23rd Native Infantry; the sepoys of the 14th native
battalions advanced; they took us for the enemy, and fired, but their
officers suppressed the fire before much injury was done. The 71st
regiment also joined us, and preparations were made to cross the
river and force the lines on the opposite side. Colonel Baird
requested me to lead with twenty men; I instantly rushed into the
stream, followed by twenty grenadiers of the 72nd regiment; we
pushed on through holes, over rocks and stones, falling and
stumbling at every step, the enemy’s shot reducing our numbers;
and myself, with about half a dozen grenadiers, arrived at a smooth
part of the stream which proved beyond our depth; five of us,
however, got over; but the regiments did not venture to follow and
we returned with difficulty. An easy passage had been found out
lower down; the 71st and 72nd regiments had got into the island;
the flank companies of the 52nd, 71st, and 74th regiments forded
higher up, and the enemy, seeing our troops on all sides of them,
betook themselves to flight.
“About one o’clock in the
morning the 71st and 72nd
regiments advanced to the
pettah, from which the
inhabitants had fled, and we
released a number of
Europeans from prison. About
seven o’clock the 72nd
marched into the famous Llal
Baugh, or, as I heard it
translated, ‘garden of pearls,’
and were posted in one of the
walks during the day.”
From a Painting by Sir Thomas Lawrence. The loss of the regiment in
General James Stuart, who died in 1815,
this brilliant victory over Tippoo
after 54 years’ service.
Sahib was Captain Thomas
Mackenzie and 14 men killed; Major Hugh Fraser, Captain the
Honourable William Maitland, Lieutenants M’Pherson and Ward, 1
serjeant, and 42 men wounded. This victory was the means of
inducing the Sultan Tippoo to sue for peace, which he obtained on
ceding half of his dominions, and paying £3,500,000, part of which
was given as a gratuity to the troops, along with six months’ batta or
field allowance.
The 72nd returned to Wallahabad, where it remained till 1795,
with a brief absence in August 1793, when it took part in an

You might also like