flat assembler
Message board for the users of flat assembler.

Index > Main > RDRAND problem

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
Hi,

from http://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide

Image

If I run the following

Code:
format PE64 console
entry start

include '%fasminc%\win64ax.inc'

;**************************************************************************************************
section '.text' code readable executable

    start:
        xor     eax, eax
        cpuid
        bt      ecx, 30
        jnc     .noGood
    .good:
        cinvoke printf, goodStr
        jmp     .finished
    .noGood:
        cinvoke printf, noGoodStr
    .finished:
        rdrand  eax
        invoke ExitProcess, 0


;**************************************************************************************************
section '.data' data readable writeable

goodStr         db "RDRAND available", 00
noGoodStr       db "RDRAND not available", 00

;**************************************************************************************************
section '.idata' import data readable writeable

library msvcrt, 'msvcrt.dll',\
        kernel32, 'kernel32.dll'

include '%fasminc%\api\Kernel32.inc'

import  msvcrt,\
        printf, 'printf'
    


I am told bit 30 is set so I have rdrand support but then the code crashes at the

Code:
rdrand  eax
    


Any ideas?

thx
Post 16 Dec 2012, 17:15
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Check the references, you are very likely to need EAX set to a value other than zero before issuing CPUID (if I remember right, EAX will only hold the maximum standard function supported and EBX, ECX and EDX will hold "GenuineIntel" or something like that)
Post 16 Dec 2012, 17:29
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
thx loco, that was the problem. I should have eax = 1.
Post 16 Dec 2012, 17:57
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:10; edited 1 time in total
Post 17 Dec 2012, 00:24
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
fyi: you're executing the RDRAND opcode when the processor detects that it isn't supported. it falls through:
Code:
    .noGood: 
        cinvoke printf, noGoodStr 
    .finished: 
        rdrand  eax     


use something like:
Code:
        bt      ecx, 30 
        jnc     .noGood 
        cinvoke printf, goodStr 
        rdrand  eax 
        invoke ExitProcess, 0 
.noGood: 
        cinvoke printf, noGoodStr 
        invoke ExitProcess, 0     

_________________
byte me.
Post 31 Dec 2012, 23:10
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Post 07 Feb 2013, 08:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.