x86 64 Assembly Language Programming with Ubuntu Ed Jorgensen pdf download
x86 64 Assembly Language Programming with Ubuntu Ed Jorgensen pdf download
Ed Jorgensen download
https://ebookmeta.com/product/x86-64-assembly-language-
programming-with-ubuntu-ed-jorgensen/
https://ebookmeta.com/product/modern-x86-assembly-language-
programming-covers-x86-64-bit-avx-avx2-and-avx-512-3rd-edition-
daniel-kusswurm/
https://ebookmeta.com/product/modern-x86-assembly-language-
programming-covers-x86-64-bit-avx-avx2-and-avx-512-2nd-edition-
daniel-kusswurm/
https://ebookmeta.com/product/assembly-language-
for-x86-processors-6th-edition-kip-irvine/
https://ebookmeta.com/product/axonal-transport-alessio-vagnoni/
Pick Your Poison 1st Edition Emma Nichole
https://ebookmeta.com/product/pick-your-poison-1st-edition-emma-
nichole/
https://ebookmeta.com/product/m-a-entrance-exams-in-english-
literature-precise-answers-accurate-sources-and-online-exams-1st-
edition-mahdi-javidshad-amirhossein-nemati/
https://ebookmeta.com/product/introduction-to-electrochemical-
science-and-engineering-2nd-edition-lvov-serguei-n/
https://ebookmeta.com/product/cambridge-international-as-a-level-
chemistry-study-and-revision-guide-third-edition-david-bevan/
https://ebookmeta.com/product/street-culture-50-years-of-
subculture-style-1st-edition-gavin-baddeley/
Evangelicals on the Canterbury Trail Why Evangelicals
Are Attracted to the Liturgical Church Revised Edition
Robert Webber Lester Ruth
https://ebookmeta.com/product/evangelicals-on-the-canterbury-
trail-why-evangelicals-are-attracted-to-the-liturgical-church-
revised-edition-robert-webber-lester-ruth/
x86-64
Assembly Language
Programming
with
Ubuntu
Ed Jorgensen, Ph.D.
Version 1.1.40
January 2020
Cover image:
Top view of an Intel central processing unit Core i7 Skylake type core,
model 6700K, released in June 2015.
Source: Eric Gaba, https://commons.wikimedia.org/wiki/File:
Intel_CPU_Core_i7_6700K_Skylake_top.jpg
Cover background:
By Benjamint444 (Own work)
Source: http://commons.wikimedia.org/wiki/File%3ASwirly_belt444.jpg
Table of Contents
1.0 Introduction...........................................................................................................1
1.1 Prerequisites........................................................................................................1
1.2 What is Assembly Language...............................................................................2
1.3 Why Learn Assembly Language.........................................................................2
1.3.1 Gain a Better Understanding of Architecture Issues...................................3
1.3.2 Understanding the Tool Chain.....................................................................3
1.3.3 Improve Algorithm Development Skills.....................................................3
1.3.4 Improve Understanding of Functions/Procedures.......................................3
1.3.5 Gain an Understanding of I/O Buffering.....................................................4
1.3.6 Understand Compiler Scope........................................................................4
1.3.7 Introduction Multi-processing Concepts.....................................................4
1.3.8 Introduction Interrupt Processing Concepts................................................4
1.4 Additional References.........................................................................................4
1.4.1 Ubuntu References......................................................................................5
1.4.2 BASH Command Line References..............................................................5
1.4.3 Architecture References..............................................................................5
1.4.4 Tool Chain References................................................................................5
1.4.4.1 YASM References...............................................................................6
1.4.4.2 DDD Debugger References.................................................................6
2.0 Architecture Overview.........................................................................................7
2.1 Architecture Overview........................................................................................7
2.2 Data Storage Sizes...............................................................................................8
2.3 Central Processing Unit.......................................................................................9
2.3.1 CPU Registers...........................................................................................10
2.3.1.1 General Purpose Registers (GPRs)....................................................10
2.3.1.2 Stack Pointer Register (RSP).............................................................12
2.3.1.3 Base Pointer Register (RBP)..............................................................12
2.3.1.4 Instruction Pointer Register (RIP).....................................................12
2.3.1.5 Flag Register (rFlags)........................................................................12
2.3.1.6 XMM Registers..................................................................................13
2.3.2 Cache Memory..........................................................................................14
2.4 Main Memory....................................................................................................15
2.5 Memory Layout.................................................................................................17
Page iii
Table of Contents
Page iv
Table of Contents
Page v
Table of Contents
Page vi
Table of Contents
Page vii
Table of Contents
Page viii
Table of Contents
Page ix
Table of Contents
Page x
Table of Contents
Page xi
Table of Contents
Page xii
Table of Contents
Illustration Index
Illustration 1: Computer Architecture................................................................................7
Illustration 2: CPU Block Diagram..................................................................................15
Illustration 3: Little-Endian Data Layout.........................................................................16
Illustration 4: General Memory Layout...........................................................................17
Illustration 5: Memory Hierarchy....................................................................................18
Illustration 6: Overview: Assemble, Link, Load.............................................................42
Illustration 7: Little-Endian, Multiple Variable Data Layout..........................................44
Illustration 8: Linking Multiple Files...............................................................................49
Illustration 9: Initial Debugger Screen.............................................................................56
Illustration 10: Debugger Screen with Breakpoint Set....................................................58
Illustration 11: Debugger Screen with Green Arrow.......................................................59
Illustration 12: DDD Command Bar................................................................................60
Illustration 13: Register Window.....................................................................................61
Illustration 14: MOV Instruction Overview....................................................................71
Illustration 15: Integer Multiplication Overview.............................................................88
Illustration 16: Integer Division Overview......................................................................96
Illustration 17: Logical Operations................................................................................102
Illustration 18: Logical Shift Overview.........................................................................104
Illustration 19: Logical Shift Operations.......................................................................104
Illustration 20: Arithmetic Left Shift.............................................................................106
Illustration 21: Arithmetic Right Shift...........................................................................106
Illustration 22: Process Memory Layout........................................................................144
Illustration 23: Process Memory Layout Example........................................................145
Illustration 24: Stack Frame Layout..............................................................................175
Illustration 25: Stack Frame Layout with Red Zone......................................................176
Illustration 26: Stack Call Frame Example....................................................................230
Illustration 27: Stack Call Frame Corruption.................................................................235
Illustration 28: Argument Vector Layout......................................................................242
Illustration 29: Privilege Levels.....................................................................................291
Illustration 30: Interrupt Processing Overview..............................................................294
Page xiii
Table of Contents
Page xiv
If you give someone a program, you will Chapter
frustrate them for a day; if you teach them 1
to program, you will frustrate them for a
lifetime.
1.0 Introduction
The purpose of this text is to provide a reference for University level assembly language
and systems programming courses. Specifically, this text addresses the x86-64 1
instruction set for the popular x86-64 class of processors using the Ubuntu 64-bit
Operating System (OS). While the provided code and various examples should work
under any Linux-based 64-bit OS, they have only been tested under Ubuntu 14.04 LTS
(64-bit).
The x86-64 is a Complex Instruction Set Computing (CISC2) CPU design. This refers
to the internal processor design philosophy. CISC processors typically include a wide
variety of instructions (sometimes overlapping), varying instructions sizes, and a wide
range of addressing modes. The term was retroactively coined in contrast to Reduced
Instruction Set Computer (RISC3).
1.1 Prerequisites
It must be noted that the text is not geared toward learning how to program. It is
assumed that the reader has already become proficient in a high-level programming
language. Specifically, the text is generally geared toward a compiled, C-based high-
level language such as C, C++, or Java. Many of the explanations and examples assume
the reader is already familiar with programming concepts such as declarations,
arithmetic operations, control structures, iteration, function calls, functions, indirection
(i.e., pointers), and variable scoping issues.
Additionally, the reader should be comfortable using a Linux-based operating system
including using the command line. If the reader is new to Linux, the Additional
References section has links to some useful documentation.
Page 1
Other documents randomly have
different content
*D-39 Telegrams relating to activities
against partisans in Italy. (GB 275) VI 1023
*D-569 File of circulars from Reichsfuehrer
SS, the OKW, Inspector of
Concentration Camps, Chief of
Security Police and SD, dating from
29 October 1941 through 22
February 1944, relative to
procedure in cases of unnatural
death of Soviet PW, execution of
Soviet PW, etc. (GB 277) VII 74
D-730 Statement of PW Walther Grosche,
11 December 1945. (GB 279) VII 177
*D-731 Statement of PW Ernst Walde, 13
December 1945. (GB 278) VII 183
*D-735 Memorandum of conference
between German Foreign Minister
and Count Ciano in presence of
Keitel and Marshal Cavallero, 19
December 1942. (GB 295) VII 190
*D-763 Circular of OKW, 18 August 1944,
regarding penal jurisdiction of non-
German civilians in Occupied
Territories. (GB 300) VII 222
*D-764 Circular of OKW, 18 August 1944,
concerning combatting of
“terrorists” and “saboteurs” in
Occupied Territories and
jurisdiction relative thereto. (GB
299) VII 223
*D-765 Directives of OKW, 2 September
1944, regarding offenses by non-
German civilians in Occupied
Territories. (GB 302) VII 225
*D-766 Circular of OKW, 4 September
1944, regarding offenses by non-
German civilians in Occupied
Territories. (GB 301) VII 226
*D-767 Memorandum, 13 September
1944, on offenses by non-German
civilians in Occupied Territories.
(GB 303) VII 228
*D-769 Telegram signed by Gen.
Christiansen, 21 September 1940,
relative to application of capital
punishment in connection with
Railway strike in Holland. (GB 304) VII 229
D-770 Circular, 24 September 1944, on
offenses of non-German civilians in
Occupied Territories. (GB 305) VII 229
*D-774 Directive of Chief of OKW to
German Foreign Office at Salzburg,
on treatment of Allied “Terrorist”-
flyers 14 June 1944. (GB 307) VII 231
*D-775 Draft of directive, 14 June 1944,
from OKW to Supreme
Commander of “Luftwaffe”,
regarding treatment of Allied
“Terrorist”-flyers. (GB 308) VII 232
*D-776 Draft of directive of Chief of OKW,
15 June 1944, to German Foreign
Office at Salzburg, concerning
treatment of Allied “Terrorist”-
flyers. (GB 309) VII 233
*D-777 Draft of directive, 15 June 1944, VII 234
from OKW to Supreme
Commander of “Luftwaffe”
concerning treatment of Allied
“Terrorist”-flyers. (GB 310)
*D-779 Letter from Reichsmarshal to Chief
of OKW, 19 August 1944,
regarding treatment of Allied
“Terrorist”-flyers. (GB 312) VII 235
*D-780 Draft of communication from
Ambassador Ritter, Salzburg, to
Chief of OKW, 20 June 1944, on
treatment of Allied “Terrorist”-
flyers. (GB 313) VII 236
*D-781 Note of OKW to Supreme
Commander of “Luftwaffe”, 23
June 1944, regarding treatment of
Allied “Terrorist”-flyers. (GB 314) VII 239
*D-782 Note from German Foreign Office,
Salzburg, 25 June 1944, to OKW.
(GB 315) VII 239
D-783 Note of a telephone
communication, 26 June 1944,
with regard to treatment of
“Terrorist”-aviators. (GB 316) VII 240
*D-784 Note from Operation Staff of OKW
signed Warlimont, 30 June 1944,
concerning treatment of Allied
“Terrorist”-flyers. (GB 317) VII 240
*D-785 Note from OKW to Supreme
Commander of “Luftwaffe”, 4 July
1944, concerning “Terror”-flyers.
(GB 318) VII 241
*D-786 Note, 5 July 1944, on “Terror”-
flyers. (GB 319) VII 242
*EC-177 Minutes of second session of VII 328
Working Committee of the Reich
Defense held on 26 April 1933.
(USA 390)
*EC-194 Secret memorandum of Keitel
concerning use of prisoners of war
in the war industry, 31 October
1941. (USA 214) VII 336
*EC-286 Correspondence between Schacht
and Goering, March-April 1937,
concerning price control. (USA
833) VII 380
EC-338 Memorandum of 15 September
1941 from Canaris to Keitel
concerning an OKW Order
regulating the treatment of Soviet
prisoners of war. VII 411
*EC-406 Minutes of Eleventh Meeting of
Reichs Defense Council, 6
December 1935. (USA 772) VII 455
*EC-407 Minutes of Twelfth Meeting of
Reichs Defense Council, 14 May
1936. (GB 247) VII 462
L-3 Contents of Hitler’s talk to
Supreme Commander and
Commanding Generals,
Obersalzberg, 22 August 1939.
(USA 28) (Referred to but not
offered in evidence.) VII 752
*L-52 Memorandum and Directives for
conduct of war in the West, 9
October 1939. (USA 540) VII 800
*L-79 Minutes of conference, 23 May
1939, “Indoctrination on the
political situation and future aims”.
(USA 27) VII 847
*L-90 Fuehrer decree, February 1942,
concerning prosecution of offenses
in Occupied Territory; “First
Ordinance” signed by Keitel for
execution of the directive;
memorandum of 12 December
1941, signed by Keitel. (USA 503) VII 871
*L-158 Circular letter from SIPO and SD
Commander of Radom District, 28
March 1944, concerning measures
to be taken against escaped
officers and non-commissioned
officer PWs. (USA 514) VII 906
L-179 Letter from RSHA to police
officials, 5 November 1942,
concerning criminal procedure
against Poles and members of
Eastern people. VII 976
*L-211 OKW circular entitled Direction of
War as Problem of Organization,
19 April 1938. (GB 161) VII 1043
*L-221 Bormann report on conference of
16 July 1941, concerning
treatment of Eastern populations
and territories. (USA 317) VII 1086
*R-100 Minutes of instructions given by
Hitler to General von Brauchitsch
on 25 March 1939. (USA 121) VIII 83
UK-20 Keitel Order on treatment of
supporters of De Gaulle who fight
for Russians, 26 May 1943. (GB
163) VIII 538
*UK-57 Keitel directives, 4 January 1944 VIII 539
and 21 April 1944, concerning
counteraction to Kharkov show
trial. (GB 164)
*UK-66 Report of British War Crimes
Section of Allied Force
Headquarters on German reprisals
for partisan activity in Italy. (GB
274) VIII 572
Affidavit A Affidavit of Erwin Lahousen, 21
January 1946, substantially the
same as his testimony on direct
examination before the
International Military Tribunal at
Nurnberg 30 November and 1
December 1945. VIII 587
Affidavit I Affidavit of Leopold Buerkner, 22
January 1946. VIII 647
Statement III The Origin of the Directives of the
Supreme Command of the Armed
Forces, by Wilhelm Keitel,
Nurnberg, 15 September 1945. VIII 669
Statement IV The Position and Powers of the
Chief of the OKW, by Wilhelm
Keitel, Nurnberg, 9 October 1945. VIII 672
Statement V Notes Concerning Actions of
German Armed Forces During the
War and in Occupied Territory, by
Wilhelm Keitel, Nurnberg, 19
October 1945. VIII 678
Statement VI The Relationship Between Canaris
and Keitel, by Erwin Lahousen,
Nurnberg, 23 October 1945. VIII 682
Statement IX My Relationship to Adolf Hitler and
to the Party, by Erich Raeder,
Moscow, fall 1945. VIII 707
**Chart No. 7 Organization of the Wehrmacht
1938-1945. (Enlargement
displayed to Tribunal.) VIII 776
5. ALFRED JODL
Dates of Promotion:
6. ERNST KALTENBRUNNER