🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.programming
2 messages
2 total messages Started by fir Sun, 29 Dec 2019 02:06
back to assembly
#216736
Author: fir
Date: Sun, 29 Dec 2019 02:06
206 lines
5258 bytes
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 
Re: back to assembly
#216737
Author: fir
Date: Thu, 02 Jan 2020 20:39
415 lines
9975 bytes
W dniu niedziela, 29 grudnia 2019 03:06:34 UTC+1 użytkownik fir napisał:
> 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

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 

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



calc_mandelbtot_for_esi_edi: 


           >> 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 

               >> title: "exampla app" 

    push 420, push 500, 
       push 20, push 20, 
          push title, call green_fire.SetupWindow2 
           add esp 20 

    mov eax 0 
    ret 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads