Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

1.9 KB
Raw Blame

Code

section .data

section .bss
    buffer resb 1  ; Allocate 1 byte for the buffer

section .text
    global _start

_start:
    nop  ; No operation (placeholder)

mov_immediate_data_to_register:
    mov eax, 100           ; Move immediate value 100 into the EAX register
    mov byte [buffer], 0x50 ; Move immediate value 0x50 into the memory location "buffer"

exit:
    mov eax, 1             ; syscall: exit
    mov ebx, 0             ; exit code 0
    int 0x80               ; Call Linux kernel to exit

Key Notes:

  1. resb Directive:

    • resb allocates uninitialized space in the .bss section.
    • In your code, buffer resb lacks a size. Specify the number of bytes needed (e.g., buffer resb 1 for 1 byte).
  2. Instruction Explanation:

    • mov eax, 100: Moves the immediate value 100 (decimal) into the EAX register.
    • mov byte [buffer], 0x50: Moves the immediate value 0x50 (hexadecimal) into the buffer memory location. The byte keyword specifies the size of the move (8-bit).
  3. Syscall:

    • The int 0x80 interrupt is used for system calls in Linux (deprecated in modern x86-64, but still functional in x86).
    • eax = 1: Indicates the sys_exit syscall.
    • ebx = 0: Specifies the exit code.
  4. NOP Instruction:

    • The nop instruction does nothing. It's typically used for alignment or as a placeholder during debugging.

Assembly Workflow:

  1. Assemble: Use nasm to assemble the code into an object file.

    nasm -f elf32 program.asm -o program.o
    
  2. Link: Use ld to link the object file into an executable.

    ld -m elf_i386 program.o -o program
    
  3. Run: Execute the program.

    ./program
    

Expected Behavior:

  • The program sets eax to 100 and stores 0x50 in the buffer location.
  • Afterward, it exits with code 0.