Introduction to Programming

(HLA Edition)


Volume One: Programming in Assembly

I.             Introduction

               A.           Introduction

               B.           The Audience

               C.           My Goal

               D.           Programming Language Overview

               E.           Why Assembly?

               F.           Why HLA?

               G.           This Book’s Layout

               H.           Conclusion

II.           Installing HLA

               A.           Introduction

               B.           HLA, FHLA, KHLA, or HIDE?

               C.           The Easy Way

               D.           The Hard Way

               E.           RadAsm

III.          Number Systems in a Nutshell

               A.           Introduction

               B.           Decimal

               C.           Octal

               D.           Hexadecimal

               E.           Binary

               F.           There’s more out there, it’s just not covered here

IV.          Basic Computer Architecture

               A.           [ Don’t Know or Care Much About Here ]

V.           Memory: Location, Interpretation, and Access

               A.           Introduction

               B.           Memory at a Glance

                              1.           Bits

                              2.           Nibbles

                              3.           Bytes

                              4.           Words

                              5.           Double Words (Long Words)

                              6.           Quad Words

                              7.           ... and yet there’s more?

               C.           Kinds of Memory

                              1.           Registers

                                             a.           Four General Purpose Registers

                                                            (1)          EAX

                                                            (2)          EBX

                                                            (3)          ECX

                                                            (4)          EDX

                                             b.           Index Registers

                                                            (1)          ESI

                                                            (2)          EDI

                                             c.            Stack Registers

                                                            (1)          ESP

                                                            (2)          EBP

                                             d.           Segment Registers

                                                            (1)          Segmentation

                                                            (2)          CS

                                                            (3)          DS

                                                            (4)          SS

                                                            (5)          ES, FS, and GS

                                             e.           Flag Register

                              2.           The Cache

                              3.           The Second Level Cache

                              4.           Main Memory

                                             a.           Flat Programming

                                             b.           The Stack

                                             c.            The Heap

                                             d.           Program Sections

                                                            (1)          Code

                                                            (2)          Data and BSS

                                                            (3)          The Stack and Heap

                              5.           Virtual Memory

                              6.           Disks

               D.           Memory Access Modes

                              1.           Immediate

                              2.           Memory Direct

                              3.           Register Direct

                              4.           Register Indirect

                              5.           Register Indirect with Displacement

                              6.           Register Indirect with Index and Displacement

               E.           Interpreting Memory

                              1.           Unsigned Values

                              2.           Signed Values

                              3.           Floating-Point Values

                              4.           Arrays

                              5.           Structures

                              6.           Strings

                                             a.           HLA Strings

VI.          Basic x86 Instructions

               A.           Introduction

               B.           Simple MOV

               C.           ADD

               D.           SUB

               E.           INTMUL

               F.           Stack Instructions

                              1.           PUSH

                              2.           POP

                              3.           CALL

                              4.           RET

VII.         First Programs

               A.           Introduction

               B.           Simplest HLA Program

               C.           “Hello, World!”, atom by atom

                              1.           “stdout.puts”

               D.           The Second Program: “What’s you name?”

                              1.           What’s new in “What’s your name?”

                              2.           ‘a_gets’ and ‘str.free’

               E.           The Third Program: Adding Two Numbers Together

                              1.           What’s new

                              2.           ‘geti32’ and ‘puti32’

VIII.        The HLA Standard Library

               A.           Introduction

               B.           [...]

IX.          More Basic x86 Instructions

               A.           Introduction

               B.           The Great MOV

               C.           Math Instruction

                              1.           MUL/IMUL

                              2.           DIV/IDIV

               D.           Bitwise Instructions

                              1.           AND

                              2.           OR

                              3.           XOR

               E.           CMP, SETcc, and Jcc Instructions

                              1.           CMP

                              2.           SETcc

                                             a.           Table of Conditions

                              3.           Jcc

X.           Control Structures

               A.           Introduction

               B.           Notes

               C.           “If”

               D.           “If/Else”

               E.           “While”

               F.           “Do While”

               G.           Nesting

               H.           Spaghetti Code

               I.             Final Words

XI.          Arrays, Pointers, and Strings

               A.           Introduction

               B.           Pointers

                              1.           What are Pointers?

                              2.           Declaring Pointers

                              3.           Using Pointers

               C.           Arrays

                              1.           What are Arrays?

                              2.           Declaring Arrays

                              3.           Accessing Arrays

                              4.           Using Arrays

               D.           Pointers and Arrays

               E.           Strings

                              1.           What is a String?

                              2.           Declaring Strings

                              3.           Using Strings

               F.           Buffer Overflow Errors and Exploits

XII.         Procedures

               A.           Introduction

               B.           The Old and Primitive Way

               C.           Using HLA in your favor

               D.           Parameters

                              1.           What’s a parameter?

                              2.           What happens during a CALL instruction

                              3.           Register Parameters

                              4.           Stack Parameters

                                             a.           The Hard Way

                                             b.           Text Variables

               E.           Local Variables

                              1.           What are Local Variables?

                              2.           Aren’t the registers enough?

                              3.           Creating Local Variables

                              4.           Accessing Local Variables

                                             a.           The Hard Way

                                             b.           Text Variables

               F.           Forward Declarations

XIII.        Multi-file Programming

               A.           Introduction

               B.           Include Files

               C.           External Functions and Units

               D.           Libraries

                              1.           LIB/POLIB/ar Librarians

               E.           Make Files

XIV.       Basic Algorithms

               A.           Introduction

               B.           Numbers to Strings

               C.           Strings to Numbers

               D.           ...

XV.         Structures/Unions/Namespaces

               A.           Introduction

               B.           Structures

                              1.           The Hard Way

                              2.           Declaring Types

                              3.           Structure Declarations

                              4.           Structure Usage

               C.           Unions

                              1.           The Hard Way

                              2.           Declaring Unions

                              3.           Accessing Unions

               D.           Using Structures and Unions Together

                              1.           Anonymous Structures and Unions

               E.           Namespaces

                              1.           Namespace Pollution

                              2.           Creating Namespaces

                              3.           Using Namespaces

                              4.           Namespaces in the Library

XVI.       File Operations

               A.           Introduction

               B.           Files in a Nutshell

               C.           fileio.open

               D.           fileio.close

               E.           File Output

               F.           File Input

XVII.      Dynamic Data Structures

               A.           Introduction

               B.           Self-Referential Structures

               C.           Lists

               D.           Dynamic Stacks

               E.           Queues

               F.           Trees

               G.           State Tables

XVIII.     Searching and Sorting Algorithms

               A.           Introduction

               B.           Searches

                              1.           Linear Search

                              2.           Binary Search

               C.           Sorting

                              1.           Bubble Sort

                              2.           Quick Sort

               D.           Binary Search Tree

               E.           The Hash Algorithms

XIX.       Macros

               A.           Introduction

               B.           What are Macros?

               C.           Declaring Macros

               D.           Local Labels

               E.           HLA Macro Evaluation

                              1.           Eager vs. Lazy Evaluation

                              2.           How can this affect me?

               F.           More is there, just not given here

XX.         Object Oriented Programming

               A.           Introduction

                              1.           Warning, Advanced Material Ahead!

               B.           Overview of Object Orientation

               C.           Inheritance Overview

               D.           Creating Classes

               E.           Inheritance

               F.           Inside the Black Box

               G.           Uses of Object Orientation and Classes

               H.           Using Inheritance

               I.             Multiple Inheritance

               J.            Conclusion

XXI.       Other Assemblers

               A.           Introduction

               B.           MASM

                              1.           MASM32

               C.           TASM

               D.           NASM

               E.           FASM

               F.           GoAsm

               G.           RosAsm

               H.           Gas

               I.             LuxAsm

               J.            BEA

XXII.      Other Programming Languages

               A.           Introduction

               B.           C

               C.           C++

               D.           Pascal/Delphi

               E.           Visual Basic

               F.           Perl

               G.           There’s more...

XXIII.     Conclusion

               A.           Congratulations

               B.           Volume Two: High Level Assembly





Volume Two: High Level Assembly

I.             Introduction

               A.           Intro

               B.           What is High Level Assembly?

               C.           How is High Level Assembly Useful?

               D.           HLA High Level Features at a Glance

               E.           Advanced Macros

II.           High Level Data Types

               A.           INTxx

               B.           UNSxx

               C.           REALxx

               D.           Other HL Data Types

III.          High Level Control Structures

               A.           Introduction

               B.           JT/JF

               C.           IF

               D.           WHILE

               E.           REPEAT-UNTIL

               F.           FOR

               G.           Self-Written Conditionals

IV.          High Level Procedures

               A.           Introduction

               B.           Argument Declaration

               C.           Local Variables

V.           Exception Handling

VI.          Advanced HLA Macros

               A.           Terminator Macros

               B.           Keyword Macros

VII.         The HLA CTL

               A.           Introduction

               B.           Compile Time Variables

               C.           Compile Time Expressions

                              1.           Assignment

                              2.           Operations

                                             a.           Addition and Subtraction

                                             b.           Multiplication and Division

                                             c.            Bitwise Operators

                                             d.           Parenthesis

                              3.           Compile Time Functions

               D.           The CTL and Macros

               E.           DSELs

               F.           Conclusion

VIII.        Conclusion