main: # @main push RBP mov RBP, RSP sub RSP, 304 movabs RDI, 0 lea RAX, QWORD PTR [RBP - 96] mov DWORD PTR [RBP - 4], 0 mov QWORD PTR [RBP - 104], RAX call time mov ECX, EAX mov EDI, ECX call srand mov RAX, QWORD PTR [RBP - 104] mov QWORD PTR [RBP - 112], RAX .LBB0_1: # =>This Inner Loop Header: Depth=1 mov RAX, QWORD PTR [RBP - 112] mov RCX, QWORD PTR [RBP - 104] add RCX, 80 cmp RAX, RCX je .LBB0_4 call rand movsxd RCX, EAX imul RCX, RCX, 1717986919 mov RDX, RCX shr RDX, 63 mov ESI, EDX sar RCX, 35 mov EDI, ECX lea ESI, DWORD PTR [RDI + RSI] imul ESI, ESI, 20 mov EDI, EAX sub EDI, ESI mov ESI, 20 mov RCX, QWORD PTR [RBP - 112] mov DWORD PTR [RCX], EDI mov DWORD PTR [RBP - 260], EAX # 4-byte Spill mov DWORD PTR [RBP - 264], ESI # 4-byte Spill mov RAX, QWORD PTR [RBP - 112] add RAX, 4 mov QWORD PTR [RBP - 112], RAX jmp .LBB0_1 .LBB0_4: mov RAX, QWORD PTR [RBP - 104] mov QWORD PTR [RBP - 120], RAX .LBB0_5: # =>This Inner Loop Header: Depth=1 mov RAX, QWORD PTR [RBP - 120] mov RCX, QWORD PTR [RBP - 104] add RCX, 80 cmp RAX, RCX je .LBB0_8 lea RDI, QWORD PTR [.L.str] mov RAX, QWORD PTR [RBP - 120] mov ESI, DWORD PTR [RAX] mov AL, 0 call printf mov DWORD PTR [RBP - 268], EAX # 4-byte Spill mov RAX, QWORD PTR [RBP - 120] add RAX, 4 mov QWORD PTR [RBP - 120], RAX jmp .LBB0_5 .LBB0_8: mov EDI, 10 call putchar lea RCX, QWORD PTR [RBP - 96] lea RDX, QWORD PTR [RBP - 208] lea RSI, QWORD PTR [RBP - 160] mov QWORD PTR [RBP - 168], RSI mov QWORD PTR [RBP - 216], RDX mov RDX, QWORD PTR [RBP - 168] mov QWORD PTR [RBP - 224], RDX mov RDX, QWORD PTR [RBP - 216] mov QWORD PTR [RBP - 232], RDX mov QWORD PTR [RBP - 240], RCX mov DWORD PTR [RBP - 272], EAX # 4-byte Spill .LBB0_9: # =>This Inner Loop Header: Depth=1 mov RAX, QWORD PTR [RBP - 240] mov RCX, QWORD PTR [RBP - 104] add RCX, 80 cmp RAX, RCX je .LBB0_15 mov RAX, QWORD PTR [RBP - 240] mov ECX, DWORD PTR [RAX] mov EDX, ECX shr EDX, 31 add EDX, ECX and EDX, -2 sub ECX, EDX mov EDX, 2 cmp ECX, 0 mov DWORD PTR [RBP - 276], EDX # 4-byte Spill jne .LBB0_12 mov RAX, QWORD PTR [RBP - 240] mov ECX, DWORD PTR [RAX] mov RAX, QWORD PTR [RBP - 224] mov RDX, RAX add RDX, 4 mov QWORD PTR [RBP - 224], RDX mov DWORD PTR [RAX], ECX jmp .LBB0_13 .LBB0_12: # in Loop: Header=BB0_9 Depth=1 mov RAX, QWORD PTR [RBP - 240] mov ECX, DWORD PTR [RAX] mov RAX, QWORD PTR [RBP - 232] mov RDX, RAX add RDX, 4 mov QWORD PTR [RBP - 232], RDX mov DWORD PTR [RAX], ECX .LBB0_13: # in Loop: Header=BB0_9 Depth=1 mov RAX, QWORD PTR [RBP - 240] add RAX, 4 mov QWORD PTR [RBP - 240], RAX jmp .LBB0_9 .LBB0_15: mov RAX, QWORD PTR [RBP - 168] mov QWORD PTR [RBP - 248], RAX .LBB0_16: # =>This Inner Loop Header: Depth=1 mov RAX, QWORD PTR [RBP - 248] cmp RAX, QWORD PTR [RBP - 224] je .LBB0_19 lea RDI, QWORD PTR [.L.str1] mov RAX, QWORD PTR [RBP - 248] mov ESI, DWORD PTR [RAX] mov AL, 0 call printf mov DWORD PTR [RBP - 280], EAX # 4-byte Spill mov RAX, QWORD PTR [RBP - 248] add RAX, 4 mov QWORD PTR [RBP - 248], RAX jmp .LBB0_16 .LBB0_19: mov EDI, 10 call putchar mov RCX, QWORD PTR [RBP - 216] mov QWORD PTR [RBP - 256], RCX mov DWORD PTR [RBP - 284], EAX # 4-byte Spill .LBB0_20: # =>This Inner Loop Header: Depth=1 mov RAX, QWORD PTR [RBP - 256] cmp RAX, QWORD PTR [RBP - 232] je .LBB0_23 lea RDI, QWORD PTR [.L.str2] mov RAX, QWORD PTR [RBP - 256] mov ESI, DWORD PTR [RAX] mov AL, 0 call printf mov DWORD PTR [RBP - 288], EAX # 4-byte Spill mov RAX, QWORD PTR [RBP - 256] add RAX, 4 mov QWORD PTR [RBP - 256], RAX jmp .LBB0_20 .LBB0_23: mov EDI, 10 call putchar mov EDI, 0 mov DWORD PTR [RBP - 292], EAX # 4-byte Spill mov EAX, EDI add RSP, 304 pop RBP ret .L.str: .asciz "The randomly generated array %d " .L.str1: .asciz "Even numbers are %d " .L.str2: .asciz "Odd numbers are %d "
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