printf@plt-0x10: push QWORD PTR [rip+0x2fe2] # 404008 <_GLOBAL_OFFSET_TABLE_+0x8> jmp QWORD PTR [rip+0x2fe4] # 404010 <_GLOBAL_OFFSET_TABLE_+0x10> nop DWORD PTR [rax+0x0] function1(int, int): push rbp mov rbp,rsp mov DWORD PTR [rbp-0x34],edi mov DWORD PTR [rbp-0x38],esi mov DWORD PTR [rbp-0x8],0x0 mov DWORD PTR [rbp-0x4],0x0 jmp 401170 <function1(int, int)+0x4a> mov edx,DWORD PTR [rbp-0x4] mov eax,edx shl eax,0x2 add eax,edx add eax,eax mov edx,eax mov eax,DWORD PTR [rbp-0x34] imul eax,DWORD PTR [rbp-0x38] add edx,eax mov eax,DWORD PTR [rbp-0x4] cdqe mov DWORD PTR [rbp+rax*4-0x30],edx mov eax,DWORD PTR [rbp-0x4] cdqe mov eax,DWORD PTR [rbp+rax*4-0x30] add DWORD PTR [rbp-0x8],eax add DWORD PTR [rbp-0x4],0x1 cmp DWORD PTR [rbp-0x4],0x9 jle 401140 <function1(int, int)+0x1a> mov eax,DWORD PTR [rbp-0x8] pop rbp ret function2(int*, int): push rbp mov rbp,rsp mov QWORD PTR [rbp-0x18],rdi mov DWORD PTR [rbp-0x1c],esi mov DWORD PTR [rbp-0x8],0x0 mov DWORD PTR [rbp-0x4],0x0 jmp 4011b3 <function2(int*, int)+0x38> mov eax,DWORD PTR [rbp-0x4] cdqe lea rdx,[rax*4+0x0] mov rax,QWORD PTR [rbp-0x18] add rax,rdx mov eax,DWORD PTR [rax] add DWORD PTR [rbp-0x8],eax add DWORD PTR [rbp-0x4],0x1 mov eax,DWORD PTR [rbp-0x4] cmp eax,DWORD PTR [rbp-0x1c] jl 401196 <function2(int*, int)+0x1b> mov eax,DWORD PTR [rbp-0x8] pop rbp ret function3(int): push rbp mov rbp,rsp mov DWORD PTR [rbp-0x14],edi mov eax,DWORD PTR [rbp-0x14] movsxd rdx,eax imul rdx,rdx,0x66666667 shr rdx,0x20 mov ecx,edx sar ecx,0x2 cdq mov eax,ecx sub eax,edx mov DWORD PTR [rbp-0x4],eax mov eax,DWORD PTR [rbp-0x4] pop rbp ret function4(int, int, int, int): push rbp mov rbp,rsp mov DWORD PTR [rbp-0x14],edi mov DWORD PTR [rbp-0x18],esi mov DWORD PTR [rbp-0x1c],edx mov DWORD PTR [rbp-0x20],ecx mov eax,DWORD PTR [rbp-0x14] cmp eax,DWORD PTR [rbp-0x18] jle 40120a <function4(int, int, int, int)+0x20> mov eax,DWORD PTR [rbp-0x14] mov DWORD PTR [rbp-0x4],eax jmp 401239 <function4(int, int, int, int)+0x4f> mov eax,DWORD PTR [rbp-0x14] cmp eax,DWORD PTR [rbp-0x1c] jle 40121c <function4(int, int, int, int)+0x32> mov eax,DWORD PTR [rbp-0x14] add eax,eax mov DWORD PTR [rbp-0x4],eax jmp 401239 <function4(int, int, int, int)+0x4f> mov eax,DWORD PTR [rbp-0x14] cmp eax,DWORD PTR [rbp-0x20] jle 401232 <function4(int, int, int, int)+0x48> mov edx,DWORD PTR [rbp-0x14] mov eax,edx add eax,eax add eax,edx mov DWORD PTR [rbp-0x4],eax jmp 401239 <function4(int, int, int, int)+0x4f> mov DWORD PTR [rbp-0x4],0xffffffff mov eax,DWORD PTR [rbp-0x4] pop rbp ret main: push rbp mov rbp,rsp sub rsp,0x50 mov DWORD PTR [rbp-0x44],edi mov QWORD PTR [rbp-0x50],rsi mov DWORD PTR [rbp-0x4],0x1 mov DWORD PTR [rbp-0x8],0x2 mov edx,DWORD PTR [rbp-0x8] mov eax,DWORD PTR [rbp-0x4] mov esi,edx mov edi,eax call 401126 <function1(int, int)> mov DWORD PTR [rbp-0xc],eax mov ecx,DWORD PTR [rbp-0xc] mov edx,DWORD PTR [rbp-0x8] mov eax,DWORD PTR [rbp-0x4] mov esi,eax mov edi,0x402008 mov eax,0x0 call 401030 <printf@plt> mov DWORD PTR [rbp-0x4],0x0 jmp 4012a0 <main+0x62> mov eax,DWORD PTR [rbp-0x4] cdqe mov edx,DWORD PTR [rbp-0x4] mov DWORD PTR [rbp+rax*4-0x40],edx add DWORD PTR [rbp-0x4],0x1 cmp DWORD PTR [rbp-0x4],0x9 jle 401290 <main+0x52> lea rax,[rbp-0x40] mov esi,0xa mov rdi,rax call 40117b <function2(int*, int)> mov DWORD PTR [rbp-0xc],eax mov eax,DWORD PTR [rbp-0xc] mov esi,eax mov edi,0x40202b mov eax,0x0 call 401030 <printf@plt> mov edi,0x64 call 4011c0 <function3(int)> mov DWORD PTR [rbp-0xc],eax mov eax,DWORD PTR [rbp-0xc] mov esi,eax mov edi,0x40203e mov eax,0x0 call 401030 <printf@plt> mov ecx,0x4 mov edx,0x3 mov esi,0x2 mov edi,0x1 call 4011ea <function4(int, int, int, int)> mov DWORD PTR [rbp-0xc],eax mov eax,DWORD PTR [rbp-0xc] mov esi,eax mov edi,0x402051 mov eax,0x0 call 401030 <printf@plt> mov eax,0x0 leave ret cs nop WORD PTR [rax+rax*1+0x0]
Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly
and start coding.
Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.
Every assembler may have it's own assembly language designed for a specific computers or an operating system.
Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.
Assembly language usually consists of three sections,
Data section
To initialize variables and constants, buffer size these values doesn't change at runtime.
bss section
To declare variables
text section
_start
specifies the starting of this section where the actually code is written.
There are various define directives to allocate space for variables for both initialized and uninitialized data.
variable-name define-directive initial-value
Define Directive | Description | Allocated Space |
---|---|---|
DB | Define Byte | 1 byte |
DW | Define Word | 2 bytes |
DD | Define Doubleword | 4 bytes |
DQ | Define Quadword | 8 bytes |
DT | Define Ten Bytes | 10 bytes |
Define Directive | Description |
---|---|
RESB | Reserve a Byte |
RESW | Reserve a Word |
RESD | Reserve a Doubleword |
RESQ | Reserve a Quadword |
REST | Reserve a Ten Bytes |
Constants can be defined using
CONSTANT_NAME EQU regular-exp or value
%assign constant_name value
%define constant_name value
Loops are used to iterate a set of statements for a specific number of times.
mov ECX,n
L1:
;<loop body>
loop L1
where n specifies the no of times loops should iterate.
Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
procedure_name:
;procedure body
ret