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 " 

Assembly Online Compiler

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.

About Assembly

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.

Syntax help

Assembly language usually consists of three sections,

  1. Data section

    To initialize variables and constants, buffer size these values doesn't change at runtime.

  2. bss section

    To declare variables

  3. text section

    _start specifies the starting of this section where the actually code is written.

Variables

There are various define directives to allocate space for variables for both initialized and uninitialized data.

1. To allocate storage space to Initialized data

Syntax

variable-name    define-directive    initial-value 
Define DirectiveDescriptionAllocated Space
DBDefine Byte1 byte
DWDefine Word2 bytes
DDDefine Doubleword4 bytes
DQDefine Quadword8 bytes
DTDefine Ten Bytes10 bytes

2. To allocate storage space to un-initialized data

Define DirectiveDescription
RESBReserve a Byte
RESWReserve a Word
RESDReserve a Doubleword
RESQReserve a Quadword
RESTReserve a Ten Bytes

Constants

Constants can be defined using

1. equ

  • To define numeric constants
CONSTANT_NAME EQU regular-exp or value

2. %assign

  • To define numeric constants.
%assign constant_name value

3. %define

  • To define numeric or string constants.
%define constant_name value

Loops

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.

Procedures

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