Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: copy a 2d array to another Posted by _Atex_ on 26 Nov 2010 at 6:43 PM
: Ok, I am going to give it a try! Unfortunately I haven't still work
: with dynamic variables (pointers), and this and assembly code is
: difficult for me to understand...

That's OK if you don't understand those assembly routines, just use them as any other procedure on function, all pascal routines are written in asm by the way.

: its going to be 2x faster in 32bit?? How to do this (if use a 32bit
: pascal, right?) ? Anyway, thanks man! Once I put it in my program I
: am making,I am going to post again!

Borland Pascal is 16bit, if you use Free Pascal that's either 32 or 64bit. Like all Dos era programs BP is running on a virtual machine under Windows, because is emulated tends to run way slower than it would on a Dos machine. If you really looking for speed than upgrade to FP and watch the difference. How 32bit is faster, here's an example: for a 100 element array if you van to copy byte by byte to another array the it would loop 100 times. One byte is 8bit therefore if you do the copying by using words instead (16 bit) then it would loop 50 times (2 bytes at a time), so is 2x faster. Going up to 32bit you'd copy longwords so it would loop 25 times (4 bytes at a time), that's 2x faster than 16bit, 4x faster than the original 8bit operation. Is possible to do this with BP, using assembly:
procedure copyfaster(source,dest:pointer;count:word);assembler;
 asm
  mov dx,ds        { save data segment in dx }
  mov cx,count     { get count in cx         }
  les di,dest      { es:di <-- dest          }
  lds si,source    { ds:si <-- source        }
  mov bl,cl        { bl:=cl;                 }
  and bl,3         { bl:=bl mod 4            }
  shr cx,2         { cx:=cx div 4            }
  cld              { clear direction flag    }
  db $66;rep movsw { loop: copy one dword (32bit) from source to dest }
  mov cl,bl        { cl:=bl;                 }
  rep movsb        { leftover bytes ? 0..3   }
  mov ds,dx        { restore data segment    }
 end;



Thread Tree
Malekovits copy a 2d array to another on 24 Nov 2010 at 3:03 PM
_Atex_ Re: copy a 2d array to another on 25 Nov 2010 at 12:02 AM
Malekovits Re: copy a 2d array to another on 25 Nov 2010 at 4:07 AM
_Atex_ Re: copy a 2d array to another on 25 Nov 2010 at 10:08 PM
Malekovits Re: copy a 2d array to another on 26 Nov 2010 at 3:25 PM
_Atex_ Re: copy a 2d array to another on 26 Nov 2010 at 6:43 PM
Malekovits Re: copy a 2d array to another on 27 Nov 2010 at 3:25 AM
_Atex_ Re: copy a 2d array to another on 27 Nov 2010 at 5:25 PM
Malekovits Re: copy a 2d array to another on 28 Nov 2010 at 5:03 AM
_Atex_ Re: copy a 2d array to another on 28 Nov 2010 at 3:11 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.