Forum > Other
assembler
Weiss:
where would you use assembler, in your Pascal code? Which compiler to download? I understand there are different flavors of assembler, thus the next question is - which assembler works in conjunction with Pascal? I have a book and this itch to start learning away, but it would help if there are some pointers. What tasks are better implemented in assembler. Please share your thoughts, folks.
Curt Carpenter:
Chapter Three of the Free Pascal Programmers Manual is titled "Using Assembly Language." Find it here:
http://downloads.freepascal.org/fpc/docs-pdf/user.pdf or
https://sourceforge.net/projects/freepascal/files/Documentation/3.2.2/
I came across a few examples of its use in the rtl today I think (using asm to speed up some string operations) but I don't remember exactly where.
The best place to enjoy ASM anymore, in my opinion, is in a microcomputer environment. And even MCUs are getting so big and complex that learning to use their ASM is a major commitment to studying a chip's docs . Lots of fun though in the old days with 8-bit devices like the Z80.
TRon:
--- Quote from: Weiss on July 17, 2024, 04:39:49 am ---where would you use assembler, in your Pascal code?
--- End quote ---
Personally nowhere.
The compiler is pretty good at optimizing generated code and while it might have been fruitful to count cycles for old processors it is pretty much undoable to optimize for modern processors to such an extent that is becomes noticeable. Ofc for your particular use-case and setup you might be able to optimize the crap out of things but that doesn't guarantee for the same code to run as smooth on another setup or other use-case.
That is besides the usual suspects such as cross-platform compatibility.
--- Quote ---Which compiler to download?
--- End quote ---
The ones supported by FPC for a particular platform ?
--- Quote ---I understand there are different flavors of assembler, thus the next question is - which assembler works in conjunction with Pascal?
--- End quote ---
Depends on the target.
--- Quote ---I have a book and this itch to start learning away, but it would help if there are some pointers. What tasks are better implemented in assembler. Please share your thoughts, folks.
--- End quote ---
You might perhaps also want to have a look at this and this
440bx:
--- Quote from: Weiss on July 17, 2024, 04:39:49 am ---where would you use assembler, in your Pascal code?
--- End quote ---
Only in extremely rare cases where implementing the task in Pascal is very inefficient and the task is repeated hundreds of thousand of times (if not millions.)
I strongly encourage you and anyone to learn assembler but, not for the purpose of using it in your Pascal code but, for the purpose of having a better understanding of how things work. For instance, to be reasonably proficient in assembler you must know how the CPU works and also, very often, many details about how the O/S works. Writing a reasonably large program in assembler also forces you to think about program structure and to make things simple because, otherwise the code becomes unmanageable. That focus on simplicity is an asset when using a high level language such as Pascal, the code is simpler, easier to maintain and usually (but not always) much faster than convoluted, tricky code.
For instance, if you know assembler and some Pascal code you've written isn't working as expected, you can inspect the assembly code generated by the compiler. Occasionally, that will reveal a bug in the compiler and, more often than not, it will reveal that what the compiler "understood" you wanted isn't what you really wanted, IOW, there is no compiler bug, you didn't tell the compiler what you wanted clearly or exactly enough.
Back some time ago, Iczelion had a website with good assembly tutorials. I believe the web site is no longer available but the tutorials are still around in various web sites. That and choosing an assembler (MASM, NASM, FASM, other) with a user forum would be a good staring point.
One thing you should be aware of is that, you'll very likely have to read the intel/AMD reference manuals. Assembler requires having reasonable knowledge about the CPU, something which high level languages make mostly unnecessary. In assembly, it is most definitely necessary. You'll also need to learn quite a bit about the O/S in order to produce assembly programs that the O/S will load and run.
HTH.
TRon:
All true 440bx but I believe the original question was "in your Pascal code"
Though you can link the objects together to make the assembler generated object "part" of your Pascal code I have the notion that that is not what TS had in mind.
Perhaps Weiss is able to elaborate on that and his (specific) use case in case there is any.
Navigation
[0] Message Index
[#] Next page