Sunday, March 21, 2021

x86 Architecture and Instruction Set Overview

Basic Info

  • 16-bit (need to clock cycles to transfer alll 32 bits) or 32-bit
  • Data types based on size
    • Byte: 8 bits
    • Word: 16 bits
    • Doubleword: 32 bits
    • Quadword: 64 bits
    • Double quadword: 128 bits

Internal Achitecture

Instruction Categories

  • Data movement
  • Stack manipulation
  • Arithmetic and logic
  • Conversions
  • Control flows
  • String and flag manipulation
  • Input/Output
  • Protected mode

Other instruction categories

  • Floating-point instructions
  • SIMD instructions
  • SSE3 (Streaming SIMD Extension 3)
  • AES instructions - for AES encryption
  • MPX instructions - for memory protection
  • SMX instructions - safer mode
  • TSX instructions - for transactional synchronization extensions
  • VMX instructions - virtual machine extensions

Common instruction patterns

xor reg, reg ; Set reg to zero
test reg, reg ; Test if reg contains zero
add reg, reg ; Shift reg left by one bit


Instruction formats

  • Individual instruction size = 1 to 15 bytes

x86 Assembly Language

Here is an example assembly code that prints a string and exits in Windows console.


.386
.model FLAT,C
.stack 400h
.code
includelib libcmt.lib
includelib legacy_stdio_definitions.lib extern printf:near
extern exit:near
public main
main proc
; Print the message
push offset message
call printf
; Exit the program with status 0
push 0
call exit
main endp
.data
message db "Hello, Computer Architect!",0 end


To run it:

ml /Fl /Zi /Zd hello_x86.asm

No comments:

Post a Comment