Usefulness of In line assembly for Pure Basic ?

Bare metal programming in PureBasic, for experienced users
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Usefulness of In line assembly for Pure Basic ?

Post by Primoz128 »

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... ?
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Usefulness of In line assembly for Pure Basic ?

Post by Tenaja »

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...
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Re: Usefulness of In line assembly for Pure Basic ?

Post by Primoz128 »

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...
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Usefulness of In line assembly for Pure Basic ?

Post by Tenaja »

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.
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:
http://purebasic.fr/english/viewtopic.p ... 98#p367475

That will let you see the direct translation of pb to asm commands.
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Re: Usefulness of In line assembly for Pure Basic ?

Post by Primoz128 »

Ye well i get an error.
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: Usefulness of In line assembly for Pure Basic ?

Post by Thorium »

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.
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Re: Usefulness of In line assembly for Pure Basic ?

Post by Primoz128 »

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 ?
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: Usefulness of In line assembly for Pure Basic ?

Post by Thorium »

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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Usefulness of In line assembly for Pure Basic ?

Post by netmaestro »

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.
BERESHEIT
Davy
User
User
Posts: 45
Joined: Wed Jun 13, 2012 7:43 pm

Re: Usefulness of In line assembly for Pure Basic ?

Post by Davy »

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:
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]
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Re: Usefulness of In line assembly for Pure Basic ?

Post by Primoz128 »

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...
Post Reply