Skip to content
/ asm-serve Public

A synchronous HTTP server that serves static files from the local directory.

Notifications You must be signed in to change notification settings

bjn7/asm-serve

Repository files navigation

Serve

The serve is a synchronous HTTP server that serves static files from the local directory. It is written in x86_64 assembly language, and its system calls follow the Linux x86_64 ABI.

Special fiiles:

  • index.html : This will be served when the root path i.e "/" is requested.

  • 404.html : This will be served when the requested file isn't found on the server.

Routing

Eg. Typical structure of a standalone React compiled project:

build/
├── index.html
└── static/
    ├── css/
    │   └── main.f6a2b3.css
    ├── js/
    │   ├── main.a1b2c3.js
    │   ├── vendor.d4e5f6.js
    │   └── main.123.js.map
    └── media/
        └── logo.123.svg

In this case, suppose the current working directory is build. When . is passed as an argument (serve .), the following paths are served:

  • localhost:3009 serves build/index.html

  • localhost:3009/static/css/main.f6a2b3.css serves build/static/css/main.f6a2b3.css

  • localhost:3009/static/js/main.a1b2c3.js serves build/static/js/main.a1b2c3.js

  • localhost:3009/static/js/vendor.d4e5f6.js serves build/static/js/vendor.d4e5f6.js

  • localhost:3009/static/js/main.123.js.map serves build/static/js/main.123.js.map

  • localhost:3009/static/media/logo.123.svg serves build/static/media/logo.123.svg

Installing

  • Clone the repository and navigate to the project folder

    git clone https://github.com/bjn7/asm-serve.git && cd asm-serve
    
  • Compile the main.asm file into an object file

    nasm -f elf64 main.asm -o main.o
    
  • Link the object file to create the executable:

    ld -s main.o -o serve
    
  • Grant execute permissions:

    chmod +x serve
    
  • Move it to the executable directory:

    sudo mv serve /usr/bin
    

    Alternatively, you can add it to an environment variable.

  • Delete the object file after linking(optional)

    rm main.o
    

Or, simply

git clone https://github.com/bjn7/asm-serve.git && cd asm-serve && nasm -f elf64 main.asm -o main.o && ld -s main.o -o serve && chmod +x serve && sudo mv serve /usr/bin

Executing

It takes one parameter which is a directory

serve example

Code Convention

In every subroutine, there is a signature that follows the format: params <> return <> registers where:

  • params expands as data_type -> description, where data_type is a pseudo type.

    • data_type include:
      • int -> any valid integer
      • * -> pointer
      • *string -> a pointer to string
      • string -> a series of continuous characters with ASCII encoding and null termination at the end.
  • return expands as register/stack/excalmation -> description

    • register -> any valid register in a 64-bit architecture
    • exclamation -> used to denote that the function doesn't return anything.
  • registers expands as list of register separated by commas, or as register -> description where:

    • The description includes what the register is holding, when it is changed, or any relavant information about the register.

eg.

hset: *string->Hash key, *->file start pointer, int->file bytes <> !->stores pointers in hash table <> rbx, rdi, rax, rdx, rcx

hget: *string->Hash key <> r12->file start pointer, r14->file bytes <> rbx, rdi, rax -> receive hash index from the hash call, rdx, r12, r14

Each argument is passed in chronological order following the Linux x86_64 ABI convention, i.e., rdi, rsi, rdx, r10, r8, and r9.

Why was it written asmebly? Once upon a time Carl Sagan said, "If you wish to make an apple pie from scratch, you must first create the universe"

About

A synchronous HTTP server that serves static files from the local directory.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published