Skip to content

Tusharinvincible/Assembly_Codes

 
 

Repository files navigation

Assembly_Codes

The following codes are of Linux OS

Codes differ for Windows and Linux.

Run Assembly on Windows:-

  1. Get 'nasm' assembler.

  2. Set nasm to path variable for accessing it everywhere in the directories.

  3. Get C compiler ( Clang , GCC , etc.)

  4. Compile the assembly language file using the nasm assembler. Command => nasm -f {system type} -o {object file name} {input assembly file} Returns => Object file.

  5. Compile the object file using the c compiler. Command => {compiler name} {object file name} -o {executable file}

  6. Execute the file.

Important Note: Why do we need C compiler ?

The Linux interrupt code (syscall) 0x80, doesn’t exist in Windows like many other functions. In Windows (or rather, DOS), the correct interrupt function would be 0x21 (or 21h), but that would mean you’re forced to write in 16-bit. Either way, calling the kernel directly in Windows seems to be not the way forward. If we cannot directly call the kernel, then what options are available to us? The obvious choice is C runtime libraries.

Run Assembly on Windows 10 64-bit example (Clang compiler used)

  1. Download nasm and clang.

  2. Set nasm as path variable.

  3. Write assembly code specific for Windows 10 64-bit.

  4. nasm -f win64 -o example.win64 example.asm

  5. clang example.win64 -o example.exe

  6. example.exe.

Run Assembly on Linux :-

  1. Get 'nasm' assembler.

  2. Use nasm to compile down the code to generate .o (object file). command => nasm -f {system format} -o {output object file name} {input .asm file}

  3. Convert object file (.o file) to executable file using linker. command => ld {input file name} -o {output file name}

  4. Run the executable file:- command => ./{output file in step3}

On Arch Linux x64 :-

sudo pacman -S nasm

nasm -f elf64 -o example.o example.asm

ld example.o -o example

example

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Assembly 100.0%