It is currently Fri Apr 10, 2020 10:46 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 4:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 10, 2011 8:25 pm
Posts: 212
Location: Slovenia
I want to know the reasons why wouldi want to learn it, cause im already trying to learn it, but im not really finding examples i need... but i do want to know what all could it be used for big stuff for example a large 3D game, or a 2D game like terraria that uses much computer resources etc... ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 4:37 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1626
It is pretty much only useful when the PB code is too slow. For instance, in loops that are repeated numerous times, you can save time by converting the bas to asm. IIRC, Peek and Poke are slow compared to asm.

I think there are a few features that pb just does not offer that requires asm, but can't think of one off hand. They are certainly not beginner features...


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 4:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 10, 2011 8:25 pm
Posts: 212
Location: Slovenia
Who cares begginer not begginer, i been coding for 3 years why not jump advanced :O ?
I also used OllyDbg for dissasembling quite some tiem but never learned a lot of it... i don't understand the flags...


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 5:52 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1626
Primoz128 wrote:
Who cares begginer not begginer, i been coding for 3 years why not jump advanced :O ?

When I say not for beginners, I mean that it is unlikely a beginner will find they are required to use asm, rather than they are not prepared to use it.

Quote:
I also used OllyDbg for dissasembling quite some tiem but never learned a lot of it... i don't understand the flags...


Install one of the asm viewer tools in this thread:
viewtopic.php?f=35&t=48298#p367475

That will let you see the direct translation of pb to asm commands.


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 6:04 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 10, 2011 8:25 pm
Posts: 212
Location: Slovenia
Ye well i get an error.


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Thu Jun 28, 2012 8:00 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
Primoz128 wrote:
i don't understand the flags...

How do you learn ASM?
If you dont understand the flags register it sounds like you are just reading some tutorials or small articles about ASM. I recommend you to read a good book about it. Understanding the flags register is essential for understanding ASM.

You need it mostly for speed improvements. PB does not use any instruction set extension, so in many cases you can get extremly high performance boosts by using SSE with ASM. Something like 10 times faster is realistic in many cases.

You need ASM for a few very advanced technics like detouring.


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Fri Jun 29, 2012 12:47 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 10, 2011 8:25 pm
Posts: 212
Location: Slovenia
Answer me this: Is memory library still faster than PB ? So if it is and i suppose it is how much faster is it ? And those who don't know assembly should use it right ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Fri Jun 29, 2012 12:56 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
Primoz128 wrote:
Answer me this: Is memory library still faster than PB ? So if it is and i suppose it is how much faster is it ? And those who don't know assembly should use it right ?

I dont know what you mean.
What memory library? The PB memory library?

The speed of ASM does not comes from simply the fact that it is ASM but from the way you can design and specialise your code with it. Using some other memory library should not make a big difference.


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Sat Jun 30, 2012 3:53 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8049
Location: Fort Nelson, BC, Canada
Last year I tackled SHA256 and SHA512 hashing, resulting in a program in the announcements forum called HashSlinger. I wrote the routines in all PB code and was happy with the result until I found a similar program on the internet called HashSlash that was faster than mine by a factor of ten. I knew nothing of assembly programming but I realized that if my program was ever going to get any respect I was going to have to learn some. Guys here such as Wilbert, Thorium, Danilo, infratec, Idle, Helle and some others took me under their wing and saw me through it. Within about three weeks my program was beating the competition by a significant margin. Overall the experience was instructive, productive and a hell of a lot of fun. I'd recommend to anyone that the best approach is to do some study of examples found online, pick a project and dive in. Ask for help here when you need it (and you will, guaranteed) and you'll get hours of free instruction right here on this forum.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Sun Jul 01, 2012 10:23 am 
Offline
User
User

Joined: Wed Jun 13, 2012 7:43 pm
Posts: 45
Primoz128 wrote:
I want to know the reasons why wouldi want to learn it, cause im already trying to learn it, but im not really finding examples i need... but i do want to know what all could it be used for big stuff for example a large 3D game, or a 2D game like terraria that uses much computer resources etc... ?


Here are a some reasons taken from the wikipedia entry on assembly language:

Quote:
There are some situations in which developers might choose to use assembly language:

*A stand-alone executable of compact size is required that must execute without recourse to the run-time components or libraries associated with a high-level language; this is perhaps the most common situation. For example, firmware for telephones, automobile fuel and ignition systems, air-conditioning control systems, security systems, and sensors.

*Code that must interact directly with the hardware, for example in device drivers and interrupt handlers.

* Programs that need to use processor-specific instructions not implemented in a compiler. A common example is the bitwise rotation instruction at the core of many encryption algorithms.

* Programs that create vectorized functions for programs in higher-level languages such as C. In the higher-level language this is sometimes aided by compiler intrinsic functions which map directly to SIMD mnemonics, but nevertheless result in a one-to-one assembly conversion specific for the given vector processor.

*Programs requiring extreme optimization, for example an inner loop in a processor-intensive algorithm. Game programmers take advantage of the abilities of hardware features in systems, enabling games to run faster. Also large scientific simulations require highly optimized algorithms, e.g. linear algebra with BLAS[18][23] or discrete cosine transformation (e.g. SIMD assembly version from x264[24])

*Situations where no high-level language exists, on a new or specialized processor, for example. Programs need precise timing such as
real-time programs such as simulations, flight navigation systems, and medical equipment. For example, in a fly-by-wire system, telemetry must be interpreted and acted upon within strict time constraints. Such systems must eliminate sources of unpredictable delays, which may be created by (some) interpreted languages, automatic garbage collection, paging operations, or preemptive multitasking. However, some higher-level languages incorporate run-time components and operating system interfaces that can introduce such delays. Choosing assembly or lower-level languages for such systems gives programmers greater visibility and control over processing details.

*cryptographic algorithms that must always take strictly the same time to execute, preventing timing attacks.

*Situations where complete control over the environment is required, in extremely high security situations where nothing can be taken for granted.

*Computer viruses, bootloaders, certain device drivers, or other items very close to the hardware or low-level operating system.

*Instruction set simulators for monitoring, tracing and debugging where additional overhead is kept to a minimum

* Reverse-engineering and modifying program files such as existing binaries that may or may not have originally been written in a high-level language, for example when trying to recreate programs for which source code is not available or has been lost, or cracking copy protection of proprietary software.

* Video games (also termed ROM hacking), which is possible via several methods. The most widely employed is altering program code at the assembly language level.

*Self modifying code, to which assembly language lends itself well.

*Games and other software for graphing calculators.[25]



Top
 Profile  
Reply with quote  
 Post subject: Re: Usefulness of In line assembly for Pure Basic ?
PostPosted: Sun Jul 01, 2012 2:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 10, 2011 8:25 pm
Posts: 212
Location: Slovenia
Good answer... i just wish a had a friend who programmed in Pure Basic or in ANY language ... or someone to teach me some more... im such a unmotivated garbage... only 2 times for 2 months in a row on holidays i could program a lot , but only cause i had satisfaction from doing stuff i never though i could or were simply too hard... but now im beyond that... though i still struggle making some simple stuff... mainly cause i never got good motivation or a coding friend to support me a little...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye