News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Simple example of rdrand

Started by hutch--, June 07, 2019, 05:08:29 AM

Previous topic - Next topic

hutch--


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    USING r12,r13,r14,r15                       ; save non volatile registers
    LOCAL bwrt :QWORD

    SaveRegs

    mov r13, 1024*1024*256                      ; set pad size here
    mov r14, alloc(r13)                         ; allocate memory
    mov r12, r14                                ; copy memory address to r12
    xor r15, r15                                ; zero counter

  @@:
    rdrand rax                                  ; generate random QWORD
    mov [r12], rax                              ; write random value to memory
    add r12, 8                                  ; set next write position
    add r15, 8                                  ; add 8 to counter
    cmp r15, r13                                ; cmp counter to buffer length
    jb @B

    mov bwrt, savefile("random.pad",r14,r13)    ; write result to disk

    mfree r14                                   ; release memory
    exec "ent random.pad"                       ; analyse result with ENT
    waitkey                                     ; pause to see results

    RestoreRegs                                 ; restore non volatile registers
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end