Git Product home page Git Product logo

hello-world-64's Introduction

hello-world-64

Build Status

The real programmers can write hello world in 64 bytes of machine code!

image

This repository contains code in assembly language targeting Windows x86_64.

Here is a list of things that are used to achieve this size:

  • undocumented PEB structure - https://en.wikipedia.org/wiki/Process_Environment_Block
  • syscall ABI on Windows
  • shadow space in stacks
  • a lot of hacks to reduce code size
    • push & pop compiles to 3 bytes of machine code (val < 128)
      ; reg = val
      push val ; 2 bytes
      pop reg ; 1 byte
    • hack that allows to push string address to the stack and pop it back
      ; reg = address of data, i.e. reg points to "my data goes here"
      call data_label
      data: db 'my data goes here'
      data_label: pop reg
    • xor of 32-bit registers allows us to zero out a 64-bit register in 2 bytes of code
      xor edx, edx ; 31 d2
      xor rdx, rdx ; 48 31 d2
      ; but it's same
    • if you want to set rdx to 0 you can use cdq to do it in 1 byte (bit 63 of rax should be 0)
      push 0x60 ; 6a 60
      pop rax ; 58 (rax = 0x60, bit 63 of rax = 0)
      cdq ; rdx = 0
  • see main.asm for better explanation

Building

You need to install NASM and unpack it into this directory or add to env variable PATH

hello-world-64's People

Contributors

stackoverflowexcept1on avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.