x64 Architecture and Programming Class

I promised this class a while back, and now it is happening. This is a brand new, 3 day class, split into 6 half-days, that covers the x64 processor architecture, programming in general, and programming in the context of Windows. The syllabus can be found here. It may change a bit, but should mostly be stable.

Dates are listed below. The times are 12pm-4pm EST (9am-1pm PST) (5pm-9pm UT)
January: 15, 17, 22, 24, 29, 31.

Cost: 750 USD (if paid by an individual), 1400 USD if paid by a company.

Registration

If you’d like to register, please send me an email to zodiacon@live.com and provide your full name, company (if any), preferred contact email, and your time zone. Previous participants in my classes get 10% off.

The sessions will be recorded, so you can watch any part you may be missing, or that may be somewhat overwhelming in “real time”.

As usual, if you have any questions, feel free to send me an email, or DM on X (twitter) or Linkedin.

Published by

Unknown's avatar

Pavel Yosifovich

Developer, trainer, author and speaker. Loves all things software

8 thoughts on “x64 Architecture and Programming Class”

    1. Unfortunately, it’s not covered in any of my books at this time. That said, there are quite a few books that cover at least some of these topics.

      Liked by 1 person

    1. There are a few the have titles like “Modern x86 assembly…” or “The art of 64-bit assembly…”. These should get you started in the right direction.

      Like

  1. I figured I would add a bit to the this conversation. One of the best books I have found that is specific to intel MASM programming is Kip Irvine’s Assembly for x86 Processors. I have the 7th and 4th editions and they are very direct reading. The new copies cost a bit but some time you can find used copies on amazon or thriftbooks.com. I would say if you really want to know masm assembly and you don’t know much at this point, I would go with this for sure. Another book that is a good intro is the “The Assembly Programming Master Book” by Vlad Pirogov. I knew about this book for a long time before I found a copy that was affordable. For some reason there was a time this was hundreds of dollars on amazon for a used copy. I didn’t not understand that. It looks like a current copy is about $22 for used on amazon. I would say if you had to choose between this and Kip’s book, go with Kip’s. Another book that I have not bought yet but has been in my amazon wish list for a very long time is “Guide to Assembly Language: A Concise Introduction”. Don’t personally own this book and it likely just covers the same as Kip’s book, but if you can getting both can not hurt. Looks like you can get a used copy for $30. Another book that is very cheap but does not teach assembly, but rather tests it is xchg rax, rax. It is simply a book of assembly snippets that you can try and figure out what they do. This is not something I have had tons of luck with, but I did go through and write down each of the intrusions I did not know, so that I could do some plain simple memorization at a latter time. The author does have a fairly good course on Udemy. I really know think his udemy course is a good as Pavel will be just based on the richness and quality of Pavel’s other work, but if you can catch a Udemy sale and grab it is for $20, I would say it would be helpful, but still defiantly get Pavel’s when it is available, much richer work. Another piece of work that is old, but still some what useful is the is Iczelion tutorials. These seem hard to find today, and seem to live on websites that are on death’s doorstep. What I have is a chm style help file. Modern Windows I don’t think always opens these, but sumatra pdf will open this file format and that is what I use. You can also get a copy of the the intel software developers manual which are free, but I don’t think of these as good for a first steps in learning assembly. I would think these would be more of a reference for a programmer doing assembly after that have a solid foundation.

    https://www.udemy.com/course/x86-asm-foundations/ ← not as good as Pavel’s work, so I would get on sale. Still worth a look if new to Asm programming.

    Iczelion Tutorial file, could not find a good link.

    Another useful resource is the wonderful ChatGPT Here is a conversation I had with that as an example:

    me:
    in the most fundamental way, when programming a generic von Neumann computer, what be the most essential assembly instructions?

    ChatGPT:
    When programming a computer based on the von Neumann architecture, the most fundamental assembly instructions, which are often found across various instruction sets, typically include:

    1. **Load and Store**: These instructions move data between the CPU and memory. `LOAD` transfers data from memory to a register, and `STORE` moves data from a register to memory.

    2. **Arithmetic Operations**: Basic arithmetic operations like `ADD` (addition), `SUB` (subtraction), `MUL` (multiplication), and `DIV` (division) are essential for performing calculations.

    3. **Bitwise Operations**: These include instructions like `AND`, `OR`, `XOR`, and `NOT`, which perform logical operations on bits.

    4. **Branching**: Branching instructions alter the flow of execution. `JMP` (jump) is used to jump to a different instruction. Conditional branches like `JE` (jump if equal) or `JNE` (jump if not equal) are used to implement decision-making.

    5. **Comparison**: Instructions such as `CMP` (compare) are used to compare two values and set the appropriate flags in the status register based on the result.

    6. **Shift and Rotate**: These instructions shift or rotate bits within a register, such as `SHL` (shift left), `SHR` (shift right), `ROL` (rotate left), and `ROR` (rotate right).

    7. **Data Movement**: Instructions like `MOV` transfer data from one register to another without any alteration.

    8. **Subroutine Calls and Return**: Instructions like `CALL` are used to jump to a subroutine and `RET` to return from it.

    9. **Stack Operations**: Instructions for pushing (`PUSH`) onto and popping (`POP`) from the stack are fundamental for function calls and local variable storage.

    These instructions form the basis of the assembly language programming for a von Neumann computer, allowing a programmer to control the flow of execution, manipulate data, and interact with the system’s memory. They are considered the building blocks for writing more complex programs.

    Me:
    Do most microprocessor have string instructions? What would the generic string instructions be? If these instructions do exist, could they be described more generically?

    ChatGPT:
    Many microprocessors have specialized string instructions designed to operate on sequences of characters or arrays of data. These string operations are often used to move blocks of data, set memory, compare strings, or search within strings, and they can significantly speed up the performance of certain operations by reducing the number of instructions needed.

    Here are some generic string instructions that are commonly found in various instruction sets:

    1. **Move String**: An instruction like `MOVS` (move string) or `MOVSB`/`MOVSW`/`MOVSD` depending on the operand size (byte/word/doubleword) is used to copy data from a source string to a destination string.

    2. **Compare String**: Instructions like `CMPS` (compare string) or `CMPSB`/`CMPSW`/`CMPSD` perform a comparison between two strings and set the flags accordingly.

    3. **Scan String**: Instructions such as `SCAS` (scan string) or `SCASB`/`SCASW`/`SCASD` are used to scan a string for a specific character or set of characters.

    4. **Load String**: Instructions like `LODS` (load string) or `LODSB`/`LODSW`/`LODSD` load a string from memory into a register.

    5. **Store String**: Instructions such as `STOS` (store string) or `STOSB`/`STOSW`/`STOSD` are used to store a string from a register to memory.

    These instructions often work in conjunction with index and/or base registers and can auto-increment or auto-decrement pointers, allowing for operations on entire strings of data with a single instruction. Additionally, these operations can typically be set to repeat based on a counter or until a condition flag is set, through the use of a prefix such as `REP` (repeat) or `REPE`/`REPZ` (repeat while equal/zero flag is set), and `REPNE`/`REPNZ` (repeat while not equal/non-zero flag is set).

    To describe these instructions more generically, they can be thought of as operations that handle data sequences or arrays en bloc rather than element by element, often optimized for common string-related operations such as copying, setting, comparing, or searching through data. The exact names and behaviors of these instructions can vary between different microprocessor architectures, but the high-level functionality tends to be similar.

    Me:
    If string instructions are not available, could the string instructions be created from the more generic instructions?

    ChatGPT:
    Yes, if string instructions are not available in a microprocessor’s instruction set, their functionality can be replicated using more generic instructions. This process would require a combination of basic assembly instructions to manually iterate over the elements of a string and perform the desired operation. Here’s how you could create the functionality of common string instructions with more generic assembly instructions:

    1. **Move String (`MOVS`)**:
    – Use a loop with a counter to iterate over the string.
    – In each iteration, `LOAD` a byte/word from the source address into a register.
    – `STORE` the byte/word from the register to the destination address.
    – Increment (or decrement) the source and destination addresses.
    – Repeat the loop until the entire string has been moved.

    2. **Compare String (`CMPS`)**:
    – Initialize a counter for the loop.
    – `LOAD` bytes/words from both source and destination addresses into separate registers.
    – `CMP` the values in the registers to set the flags for conditional branching.
    – If a discrepancy is found, exit the loop.
    – Otherwise, increment the source and destination pointers and continue until the end of the string.

    3. **Scan String (`SCAS`)**:
    – Load the character to scan for into a register.
    – Iterate over the string with a loop, `LOAD`ing each character into another register.
    – `CMP`are the loaded character with the one in the register.
    – If they match, exit the loop.
    – Increment the string pointer and continue until the end of the string or a match is found.

    4. **Load String (`LODS`)**:
    – `LOAD` the value from the string address into a register.
    – Increment the string pointer to the next element.
    – This process would be repeated for the length of the string or until a certain condition is met.

    5. **Store String (`STOS`)**:
    – Place the value to store into a register.
    – `STORE` the value from the register into the destination address.
    – Increment the destination address.
    – Repeat for the entire length of the string or until a condition is satisfied.

    In each case, you may also need to manage loop control and address incrementation or decrementation manually. Also, for some operations, you would need to manage the CPU flags directly for proper conditional branching.

    This manual method is typically more verbose and less efficient than using dedicated string instructions because it requires more instructions to accomplish the same task, and each instruction may involve additional overhead in terms of execution cycles. However, it provides a good understanding of how higher-level operations are broken down into their fundamental components at the machine level.

    Me:
    What would be the fundamental flags that are important in computer operations?

    ChatGPT:
    In computer architecture, particularly within the context of the processor’s status register, flags play a crucial role in controlling the flow of operations and signaling the state of the processor after arithmetic and logical operations. Here are the most fundamental flags that are universally important in computer operations:

    1. **Zero Flag (ZF)**: Indicates whether the result of an operation is zero. This is commonly used for equality checks and branching decisions.

    2. **Carry Flag (CF)**: Used to indicate an overflow from the most significant bit in arithmetic operations. It’s also used for carry-in and carry-out in multi-precision arithmetic.

    3. **Sign Flag (SF)**: Reflects the sign of the result of an operation. If the most significant bit of the result is set (in a two’s complement system), the sign flag is set, indicating a negative result.

    4. **Overflow Flag (OF)**: Indicates when there is an arithmetic overflow, meaning the result was too large to fit in the designated number of bits.

    5. **Parity Flag (PF)**: Indicates if the number of set bits is even or odd in the binary representation of the result.

    6. **Auxiliary Carry Flag (AC or AF)**: Used in binary-coded decimal (BCD) arithmetic, this flag indicates an overflow out of the least significant four bits.

    7. **Direction Flag (DF)**: Used by string operations to process strings from high memory to low memory (when set) or low to high (when clear).

    These flags are often set or cleared as a result of executing instructions and are used by subsequent conditional branch instructions to decide the flow of control in programs. For instance, a `JE` (jump if equal) instruction would check if the zero flag is set and branch if the previous comparison result was equal (i.e., zero). The exact set of flags and their use may vary slightly between different processor architectures, but these fundamental flags are a common feature.

    Like

Leave a comment