Discussion:
org-asm (new asembler for x86)
(too old to reply)
firr
2019-12-29 02:05:39 UTC
Permalink
i got so terrible problems last half of year i was like unable to concentrate on coding, still not feeling well to be honest but i think maybe i can back for a while

the idea is to maybe upbuild (build it up) my assembler (so called organic assembler) so maybe i will show that project and maybe some more specific questions/topics will appear

vurrent version to download:

http://minddetonator.htw.pl/org-asm.zip

(for windows32, i mean it runs as win32 console tool and assembles win32 executables)

i added some example pice of asm code in it
as sorta example how to use it



main:

call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop
call test_1M_loop


ret

////////////////////////



test_1M_loop:
nop
nop
mov esi 1000000
rdtsc
push edx
push eax
loop:
//==================

nop
nop
nop
// mov ebx esi
// add ebx 19
// mov edx 1000
// mov eax 1000
// div edax ebx

//=================
dec esi
jne loop
rdtsc
pop ebx
pop ecx
sub eax ebx
sbb edx ecx
call print_eax
ret

////////////////////////////


inner_test:

ret

//////////////////////////////

@ note_eax: "\x0d\x0a rdtsc eax = %d \x00"

print_eax:
push eax
push note_eax
call msvcrt.printf
pop eax
pop eax
ret



this pice of asm makes loop of 1M rolls and
measures how many cycles it takes by rtdsc command

this itself may be interesting for someone who would like to toy a bit and measure what amount of cycles given assembly comands and routines take on your cpu

for example gien loop with 3 nops gives that result (here on my old cpu)



rdtsc eax = 2000103

rdtsc eax = 2000117

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2000082

rdtsc eax = 2042404

rdtsc eax = 2415266

rdtsc eax = 2266271

if i delete that 3 nops it gives



rdtsc eax = 1000125

rdtsc eax = 1000111

rdtsc eax = 1000083

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000083

rdtsc eax = 1000083

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000076

rdtsc eax = 1000076

so it shows that 1 nop takes only like 0.33 cycle, and that dec esi and jne jump itself take only one cycle

if someone is interested how fast things execute that kind of tests may be usefull
(it could be done in more popular assemblers but the entry level of my own may be easier, for me its easier for sure)

things can be tested easily, for example if i want to test rand() i just put a line

call msvcrt.rand

instead of that 3 nops and i get the result



rdtsc eax = 28016989

rdtsc eax = 28000112

rdtsc eax = 28043897

rdtsc eax = 28001589

rdtsc eax = 28001498

rdtsc eax = 28105077

rdtsc eax = 28000161

rdtsc eax = 28001904

rdtsc eax = 28016415

rdtsc eax = 28024360

rdtsc eax = 28000084

rdtsc eax = 28012999

rdtsc eax = 28026061

rdtsc eax = 28002849

so its 27 cycles..and so on


if someone would like to toy with my assembler i could improve it (i not typed all possiblemnemonic register combinations yet as it seems to be posiibly thousands of them)

i need yet also make some improve,ments in syntax of that asm... im quite satisfied as to cyntax of code (which i a bit refreshed if compared to intel by rejecting periods and turning square brackets into round brackets but i quess i still need to work on data format and also repair some holes here
Terje Mathisen
2019-12-29 09:02:13 UTC
Permalink
Post by firr
i got so terrible problems last half of year i was like unable to
concentrate on coding, still not feeling well to be honest but i
think maybe i can back for a while
Hope you'll get better!
Post by firr
the idea is to maybe upbuild (build it up) my assembler (so called
organic assembler) so maybe i will show that project and maybe some
more specific questions/topics will appear
http://minddetonator.htw.pl/org-asm.zip
(for windows32, i mean it runs as win32 console tool and assembles win32 executables)
That is interesting, thanks for uploading.

Happy New Year everyone!

Terje
Post by firr
i added some example pice of asm code in it as sorta example how to
use it
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
ret
////////////////////////
//==================
nop nop nop // mov ebx esi // add ebx 19 // mov edx 1000 // mov
eax 1000 // div edax ebx
//================= dec esi jne loop rdtsc pop ebx pop ecx sub eax
ebx sbb edx ecx call print_eax ret
////////////////////////////
ret
//////////////////////////////
@ note_eax: "\x0d\x0a rdtsc eax = %d \x00"
print_eax: push eax push note_eax call msvcrt.printf pop eax pop eax
ret
this pice of asm makes loop of 1M rolls and measures how many cycles
it takes by rtdsc command
this itself may be interesting for someone who would like to toy a
bit and measure what amount of cycles given assembly comands and
routines take on your cpu
for example gien loop with 3 nops gives that result (here on my old cpu)
rdtsc eax = 2000103
rdtsc eax = 2000117
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2042404
rdtsc eax = 2415266
rdtsc eax = 2266271
if i delete that 3 nops it gives
rdtsc eax = 1000125
rdtsc eax = 1000111
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000083
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
so it shows that 1 nop takes only like 0.33 cycle, and that dec esi
and jne jump itself take only one cycle
if someone is interested how fast things execute that kind of tests
may be usefull (it could be done in more popular assemblers but the
entry level of my own may be easier, for me its easier for sure)
things can be tested easily, for example if i want to test rand() i just put a line
call msvcrt.rand
instead of that 3 nops and i get the result
rdtsc eax = 28016989
rdtsc eax = 28000112
rdtsc eax = 28043897
rdtsc eax = 28001589
rdtsc eax = 28001498
rdtsc eax = 28105077
rdtsc eax = 28000161
rdtsc eax = 28001904
rdtsc eax = 28016415
rdtsc eax = 28024360
rdtsc eax = 28000084
rdtsc eax = 28012999
rdtsc eax = 28026061
rdtsc eax = 28002849
so its 27 cycles..and so on
if someone would like to toy with my assembler i could improve it (i
not typed all possiblemnemonic register combinations yet as it seems
to be posiibly thousands of them)
i need yet also make some improve,ments in syntax of that asm... im
quite satisfied as to cyntax of code (which i a bit refreshed if
compared to intel by rejecting periods and turning square brackets
into round brackets but i quess i still need to work on data format
and also repair some holes here
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
firr
2020-01-01 20:19:42 UTC
Permalink
Post by Terje Mathisen
Post by firr
i got so terrible problems last half of year i was like unable to
concentrate on coding, still not feeling well to be honest but i
think maybe i can back for a while
Hope you'll get better!
Post by firr
the idea is to maybe upbuild (build it up) my assembler (so called
organic assembler) so maybe i will show that project and maybe some
more specific questions/topics will appear
http://minddetonator.htw.pl/org-asm.zip
(for windows32, i mean it runs as win32 console tool and assembles win32 executables)
That is interesting, thanks for uploading.
Happy New Year everyone!
Terje
Post by firr
i added some example pice of asm code in it as sorta example how to
use it
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
ret
////////////////////////
//==================
nop nop nop // mov ebx esi // add ebx 19 // mov edx 1000 // mov
eax 1000 // div edax ebx
//================= dec esi jne loop rdtsc pop ebx pop ecx sub eax
ebx sbb edx ecx call print_eax ret
////////////////////////////
ret
//////////////////////////////
@ note_eax: "\x0d\x0a rdtsc eax = %d \x00"
print_eax: push eax push note_eax call msvcrt.printf pop eax pop eax
ret
this pice of asm makes loop of 1M rolls and measures how many cycles
it takes by rtdsc command
this itself may be interesting for someone who would like to toy a
bit and measure what amount of cycles given assembly comands and
routines take on your cpu
for example gien loop with 3 nops gives that result (here on my old cpu)
rdtsc eax = 2000103
rdtsc eax = 2000117
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2042404
rdtsc eax = 2415266
rdtsc eax = 2266271
if i delete that 3 nops it gives
rdtsc eax = 1000125
rdtsc eax = 1000111
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000083
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
so it shows that 1 nop takes only like 0.33 cycle, and that dec esi
and jne jump itself take only one cycle
if someone is interested how fast things execute that kind of tests
may be usefull (it could be done in more popular assemblers but the
entry level of my own may be easier, for me its easier for sure)
things can be tested easily, for example if i want to test rand() i just put a line
call msvcrt.rand
instead of that 3 nops and i get the result
rdtsc eax = 28016989
rdtsc eax = 28000112
rdtsc eax = 28043897
rdtsc eax = 28001589
rdtsc eax = 28001498
rdtsc eax = 28105077
rdtsc eax = 28000161
rdtsc eax = 28001904
rdtsc eax = 28016415
rdtsc eax = 28024360
rdtsc eax = 28000084
rdtsc eax = 28012999
rdtsc eax = 28026061
rdtsc eax = 28002849
so its 27 cycles..and so on
if someone would like to toy with my assembler i could improve it (i
not typed all possiblemnemonic register combinations yet as it seems
to be posiibly thousands of them)
i need yet also make some improve,ments in syntax of that asm... im
quite satisfied as to cyntax of code (which i a bit refreshed if
compared to intel by rejecting periods and turning square brackets
into round brackets but i quess i still need to work on data format
and also repair some holes here
some a bit more new wersion

http://minddetonator.htw.pl/org-asm-3.zip

sadly nobody writes in it as it could help me to fopcus on typing in missed mnemonics and features
firr
2020-01-02 20:38:38 UTC
Permalink
Post by firr
Post by Terje Mathisen
Post by firr
i got so terrible problems last half of year i was like unable to
concentrate on coding, still not feeling well to be honest but i
think maybe i can back for a while
Hope you'll get better!
Post by firr
the idea is to maybe upbuild (build it up) my assembler (so called
organic assembler) so maybe i will show that project and maybe some
more specific questions/topics will appear
http://minddetonator.htw.pl/org-asm.zip
(for windows32, i mean it runs as win32 console tool and assembles
win32 executables)
That is interesting, thanks for uploading.
Happy New Year everyone!
Terje
Post by firr
i added some example pice of asm code in it as sorta example how to
use it
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
call test_1M_loop call test_1M_loop call test_1M_loop call
test_1M_loop call test_1M_loop call test_1M_loop call test_1M_loop
ret
////////////////////////
//==================
nop nop nop // mov ebx esi // add ebx 19 // mov edx 1000 // mov
eax 1000 // div edax ebx
//================= dec esi jne loop rdtsc pop ebx pop ecx sub eax
ebx sbb edx ecx call print_eax ret
////////////////////////////
ret
//////////////////////////////
@ note_eax: "\x0d\x0a rdtsc eax = %d \x00"
print_eax: push eax push note_eax call msvcrt.printf pop eax pop eax
ret
this pice of asm makes loop of 1M rolls and measures how many cycles
it takes by rtdsc command
this itself may be interesting for someone who would like to toy a
bit and measure what amount of cycles given assembly comands and
routines take on your cpu
for example gien loop with 3 nops gives that result (here on my old cpu)
rdtsc eax = 2000103
rdtsc eax = 2000117
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2000082
rdtsc eax = 2042404
rdtsc eax = 2415266
rdtsc eax = 2266271
if i delete that 3 nops it gives
rdtsc eax = 1000125
rdtsc eax = 1000111
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000083
rdtsc eax = 1000083
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
rdtsc eax = 1000076
so it shows that 1 nop takes only like 0.33 cycle, and that dec esi
and jne jump itself take only one cycle
if someone is interested how fast things execute that kind of tests
may be usefull (it could be done in more popular assemblers but the
entry level of my own may be easier, for me its easier for sure)
things can be tested easily, for example if i want to test rand() i just put a line
call msvcrt.rand
instead of that 3 nops and i get the result
rdtsc eax = 28016989
rdtsc eax = 28000112
rdtsc eax = 28043897
rdtsc eax = 28001589
rdtsc eax = 28001498
rdtsc eax = 28105077
rdtsc eax = 28000161
rdtsc eax = 28001904
rdtsc eax = 28016415
rdtsc eax = 28024360
rdtsc eax = 28000084
rdtsc eax = 28012999
rdtsc eax = 28026061
rdtsc eax = 28002849
so its 27 cycles..and so on
if someone would like to toy with my assembler i could improve it (i
not typed all possiblemnemonic register combinations yet as it seems
to be posiibly thousands of them)
i need yet also make some improve,ments in syntax of that asm... im
quite satisfied as to cyntax of code (which i a bit refreshed if
compared to intel by rejecting periods and turning square brackets
into round brackets but i quess i still need to work on data format
and also repair some holes here
some a bit more new wersion
http://minddetonator.htw.pl/org-asm-3.zip
sadly nobody writes in it as it could help me to fopcus on typing in missed mnemonics and features
http://minddetonator.htw.pl/org-asm-4.zip

i added some extremally lame asm code for drawing mandelbrot (temporarely becouse of laziness)

it may illustrate how you do float assembler today (you simply add ss to mnemonics and have 8 registers)

though honestly it is visible i need to rework some things in that assembly, like turning xmm1 into x1 to be shorter etc

but im tired and will do it later

//
// unsigned background_color = 0x0;
//
// void RunFrame(int advance)
// {
// ClearFrameData(background_color);
// }
//
//
// void ProcessMouseMove(int x, int y){}
// void ProcessKeyDown(int key){}
// void OnResize(){}
//
//
// int main(void)
// {
//
// RegisterMouseMove( ProcessMouseMove );
// RegisterKeyDown( ProcessKeyDown );
// RegisterOnResize( OnResize );
// RegisterRunFrame( RunFrame );
// SetSleepValue(10);
//
// SetupWindow2(" Example Green Fire App ", 20, 20, 560, 400 );
//
// return 0;
// }


jmp start

ProcessMouseMove: ret
ProcessKeyDown: ret
OnResize: ret

//////////////////////////////////////
Post by firr
Post by Terje Mathisen
minus2: -2.0f four: 4.0 dx: 0.01 dy: 0.01
c_re: 0.0 c_im: 0.0 res: 0
push eax


cvt si2ss xmm0 esi

mov ss xmm1 (dx)
mul ss xmm0 xmm1
add ss xmm0 (minus2)
mov ss (c_re) xmm0

cvt si2ss xmm0 edi

mov ss xmm1 (dy)
mul ss xmm0 xmm1
add ss xmm0 (minus2)
mov ss (c_im) xmm0


//////////////////////
mov ecx 0


mov ss xmm3 (c_re)
mov ss xmm4 (c_im)

mov ss xmm0 xmm3
mov ss xmm1 xmm4

mov ss xmm2 (four)

iterations:
//re
mov ss xmm5 xmm0
//im
mov ss xmm6 xmm1

//re * re
mul ss xmm0 xmm0
//im * im
mul ss xmm1 xmm1
// re*re + im*im
add ss xmm0 xmm1

mov ss xmm1 xmm0

cmple ss xmm1 xmm2

cvt ss2si eax xmm1

cmp eax 0
je out

mov ss xmm0 xmm5
mov ss xmm1 xmm6
//re * re
mul ss xmm0 xmm0
//im * im
mul ss xmm1 xmm1
sub ss xmm0 xmm1
add ss xmm0 xmm3
// re_n = re * re - im * im + cRe;
mov ss xmm7 xmm0

mov ss xmm0 xmm5
mul ss xmm0 xmm6
add ss xmm0 xmm0
add ss xmm0 xmm4

mov ss xmm1 xmm0
mov ss xmm0 xmm7


//
inc ecx
cmp ecx 100
jl iterations

mov ecx 0xff00ff
pop eax
ret
out:

mov ecx 0xffff00
pop eax
ret

// double re = cRe;
// double im = cIm;
//
// for(int n=1; n<man_maxiter; n++)
// {
// points_list[n].re = re;
// points_list[n].im = im;
//
// if( re * re + im * im > 4.0 ) return n;
//
// double re_n = re * re - im * im + cRe;
// double im_n = 2 * re * im + cIm;
//
// re = re_n;
// im = im_n;
//
// }






RunFrame:

push 0x007000, call green_fire.ClearFrameData, pop eax ;


/////////////////// loop on pixels
mov eax green_fire.frame_bitmap
mov ebp (eax)
mov eax green_fire.frame_size_x
mov ebx (eax)

mov edi 0
loop_y:
mov esi 0
loop_x:
mov eax edi, mul eax ebx, add eax esi, shl eax 2, add eax ebp
call calc_mandelbtot_for_esi_edi
mov (eax) ecx
inc esi , cmp esi 400, jl loop_x
inc edi , cmp edi 400, jl loop_y
//////////


ret


start:

push ProcessMouseMove, call green_fire.RegisterMouseMove, pop eax
push ProcessKeyDown, call green_fire.RegisterKeyDown, pop eax
push OnResize, call green_fire.RegisterOnResize, pop eax
push RunFrame, call green_fire.RegisterRunFrame, pop eax
push 10, call green_fire.SetSleepValue, pop eax
Post by firr
Post by Terje Mathisen
title: "exampla app"
push 420, push 500,
push 20, push 20,
push title, call green_fire.SetupWindow2
add esp 20

mov eax 0
ret

Loading...