flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > FASM in Euphoria 4.0+

Author
Thread Post new topic Reply to topic
Hayden



Joined: 06 Oct 2005
Posts: 132
FASM in Euphoria 4.0+
I wrote this little wrapper for euphroia for win to allow assembler in eu.
Tested with Euphoria 4.1 32 bit and latest version of fasm.dll wich still returns version 1.67. Technicly it will work with EU-64 bit with 64-bit fasm.dll.

Euphoria can be found here www.rapideuphoria.com
install EU and uzip my wrapper to %euphoria directory%\includes


Description: TG's FASM Wrapper for Euphoria
Download
Filename: fasm4e.zip
Filesize: 68.8 KB
Downloaded: 163 Time(s)


_________________
New User.. Hayden McKay.
Post 08 Dec 2015, 09:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/╩╗Oumuamua
I am curious to know what does fasm.dll add to an interpreted language? Or does Euphoria pre-compile code or something?
Post 08 Dec 2015, 10:31
View user's profile Send private message Visit poster's website Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Code is executed with a backend. the euphoria bundle also comes with an E 2 C tranlator with your option of compilers to use eg; watcom, borland, gcc. Code is passed through the euphoria interpreter, any syntax checking, type checking is done here., if all ok the code is executed with euphoria backend (written in C) while codeing you can output to windows console like fasm's display directive. eu files can be bined together with the backend to create dll's, windows console apps or just a plain windows executable.

Euphoria has built in function to call machine code. the old way was to compile with fasm the open the binary file in binary mode use sprintf() to format byte sequence as hex output the to file the copy past into eu so you end up with something like this

integer mycode = allocate(CODE_SIZE)
poke(mycode,{90h, 90h, 90h})

to call it we use eu built in call()

call(mycode)

this way makes it hard to make adjustments and updates to code because it all lookes like hexidecimal. Now I can use FASM in euphoria by passing strings.

to get the frequency of CPU in euphoria using embeded fasm syntax lookes like this


-- 5 recomended. a longer reference period gives better accuracy

constant refperiod = 5
constant intervals = 18.2 -- number of bios intervals per second

puts(SCREEN,"please wait...")

constant lower = allocate(4)
constant upper = allocate(4)

Fasm_x86_Inline({"rdtsc",
sprintf("mov [%d], eax",lower), -- stores the tsc qword
sprintf("mov [%d], edx",upper)})

sleep(refperiod) -- wait refernce period

Fasm_x86_Inline({"rdtsc",
sprintf("sub eax, [%d]",lower), -- subtract saved qword
sprintf("sbb edx, [%d]",upper),
sprintf("mov [%d], eax",lower), -- store result
sprintf("mov [%d], edx",upper)})

constant mHz

= floor(
bits_to_int(or_bits(
int_to_bits(peek4u (lower),64),
int_to_bits(peek4u (upper)*power(2,32),64))) -- 64bit tsc result
/ (((1/intervals)*1000000)
* (intervals*refperiod))
+ .5) -- grab nearest mHz

clear_screen()
printf(1,"~ %dmHz",mHz) -- done!
while get_key() = -1 do
end while

_________________
New User.. Hayden McKay.
Post 08 Dec 2015, 11:54
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.