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.
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:3009servesbuild/index.html -
localhost:3009/static/css/main.f6a2b3.cssservesbuild/static/css/main.f6a2b3.css -
localhost:3009/static/js/main.a1b2c3.jsservesbuild/static/js/main.a1b2c3.js -
localhost:3009/static/js/vendor.d4e5f6.jsservesbuild/static/js/vendor.d4e5f6.js -
localhost:3009/static/js/main.123.js.mapservesbuild/static/js/main.123.js.map -
localhost:3009/static/media/logo.123.svgservesbuild/static/media/logo.123.svg
-
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/binAlternatively, 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
It takes one parameter which is a directory
serve example
In every subroutine, there is a signature that follows the format: params <> return <> registers where:
-
params expands as
data_type -> description, wheredata_typeis apseudo type.data_typeinclude:int-> any valid integer*-> pointer*string-> a pointer to stringstring-> 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 architectureexclamation-> used to denote that the function doesn't return anything.
-
registers expands as list of register separated by commas, or as
register -> descriptionwhere:- 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.