diff options
author | FreeArtMan <dos21h@gmail.com> | 2016-06-05 10:16:17 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2016-06-05 10:16:17 +0100 |
commit | cfacfaed3056e1f022d2b8fad9cdc206bfbd1108 (patch) | |
tree | 728f7acdede69097a1f088d8f40c9e4469e4a753 | |
parent | 3d72c232258632969c1f2d2797cbbdaff8720e24 (diff) | |
download | md-content-cfacfaed3056e1f022d2b8fad9cdc206bfbd1108.tar.gz md-content-cfacfaed3056e1f022d2b8fad9cdc206bfbd1108.zip |
Update gcc inline assembly
-rw-r--r-- | md/writeup/gcc_inline_assembly.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/md/writeup/gcc_inline_assembly.md b/md/writeup/gcc_inline_assembly.md index 6e9985a..eda7764 100644 --- a/md/writeup/gcc_inline_assembly.md +++ b/md/writeup/gcc_inline_assembly.md @@ -155,6 +155,25 @@ long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigne ``` Put result of execution to __ret__, all paramters in memory +### Intel random number with RDRAND + +``` +uint64_t get_hw_rand() +{ + uint64_t ret; + int i=0; + const int timeout = 10; + while (i<timeout) + { + asm("rdrand %0\n\t" + :"=a"(ret)::); + if (ret) break; + i++; + } + return ret; +} +``` + <!-- ### Intel i386 BSD @@ -166,6 +185,14 @@ Put result of execution to __ret__, all paramters in memory ## Switching on of intel/att syntax +Inline assembler for GCC by default uses AT&T syntax. There is possible to turn on/off intel syntax. + +``` +asm(".intel_syntax noprefix"); +asm("mov eax, 1"); +asm(".att_syntax prefix"); +``` + ## Asm goto |