ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Assembly language for what processor?
Have you an assembler for your processor?
Have you the machine language reference and register map for your processor?
Assembly language is rarely – if ever – used anymore, because modern microprocessors are engineered to be programmed by compilers, not people. CPU architects then work with compiler designers to cause the best object-code for that particular chip to be generated (and optimized).
So, not only is the procedure much more efficient for humans, but also it's much more efficient for the CPU.
A typical example of assembly code today is the /arch subdirectory of the Linux source-code tree. Even there, you'll notice that nearly all of the components are C modules with asm{...} blocks. In most cases, the architects minimized the use of conditional compilation throughout the source-tree and instead devised a set of functions which could then be implemented in appropriate ways (or be no-ops, as the case may be). They usually devised macros to invoke those functions so that the calls could be omitted entirely if this was appropriate, all without affecting the source code.
In fact, the ground-breaking feature of the original Unix® OS was that most of it was programmed in a high-level language that was basically invented for the purpose: "C." Prior to that time, most work was done in hand-written assembler, on the assumption – erroneous, as it turned out – that this was necessary.
(Although some of the very earliest compilers emitted assembly code that was subsequently assembled. Much like the earliest "C++" compiler emitted "C" source code. Back in the days when you had virtually nothing to work with, you did what you had to do ...)
Last edited by sundialsvcs; 03-05-2018 at 07:23 AM.
Some general rules of thumb when learning any new form of programming, as well as for this particular topic:
When you really look at it, nearly all instructions are in the forms of: move, test, or branch. So you are going to do any of:
Store or retrieve data and manipulate it
Compare data against a condition, either simple or complex
Make a next program direction decision based on the outcome
There are also many commands which are "in place", such as bit manipulations, including shifts, and rotates
It is helpful to learn the general things done to accomplish common thing, such as mathematical computations, how to do a loop, how to read input, how to produce output, how to manipulate an array or list, the various modes for referencing a location in memory, and understanding the CPU registers and what is available
Taking the registers as a leap into my next part, you should then learn what is, or is not special about the CPU you have. Well ... they're all special, however ones like DSPs or pipeline ones have some additional special properties and resources. Overall, you need to be versed in the specific CPU you are working with to understand what resources are available to you for your program actions, and also be aware of the instruction set, and finally the memory model(s) that the CPU is capable of working with.
As far as code, there's nothing saying you can't have functions, they just look far different. You also can separate you code logically into files, and sections and have far more control over what you do when you perform this. You also can get into deeper trouble, as well as write very confusing code. Documenting the code, using name references within the code is helpful, but also to note that if the main data register is named sr0 per the instruction set, then that is the name you have to use and you may find you need to add a lot of comments to aid you as your architecture grows.
A great recommendation is that you find a way to cause an output of the mixed source, assembler listing of C files. Do not use any library functions, turn of optimization, and do very simple actions. Then look at the assembly generated by your C code.
Thank you all, helpers,
just i am new and want to learn assembly:
1- ٍShould i learn Computer architecture before learn assembly? if yes which book is to start with?
2- Which book i should start with to learn assembly?
3- I want some advices in assembly field.
Thank you all, helpers,
just i am new and want to learn assembly:
1- ٍShould i learn Computer architecture before learn assembly? if yes which book is to start with?
2- Which book i should start with to learn assembly?
3- I want some advices in assembly field.
Have you searched for any resources on the web?
There are plenty of kits for simple CPUs where you can do assembly language programming.
I don't recommend you look at a book for assembly, with the exception of the programmer's manual and instruction set for the target CPUs you choose to try assembly programming for.
As far as computer architecture, it absolutely cannot hurt to be versed in how a CPU is formed out of logic. Recommend you also web search for basic computer architecture, there is plenty of information available. Find the wikipedia for computer architecture, review that and the topics recommended to also read, such as about Von Newmann and Harvard; probably most of that See Also section.
There is little people can offer here about this topic, with the exception of the opinions most of us have offered. This topic area is very large, and you really should research this, so as to determine what areas of concentration work best for you.
I would also look at micro controller programming in assembly (smaller instruction set, light program complexity) although C language is commonly used in this field too. Assembly code produces smaller program size to upload and a great control feeling, so I think its use is justified here
There are not expansive kits solutions to start with.
Assembly language for what processor?
Have you an assembler for your processor?
Have you the machine language reference and register map for your processor?
I just love it...
Why don't you just save yourself the time to write such garbage and me (us) the time to read it?
However...
To 'my time' I asked for a reference manual for the Intel 286 and 386DX40 Processor at Intel itself in England.
These days they send them free to my home in Germany but I doubt they still do it today.
Besides... I'd prefer now AMD processors.
Greetings by meltdown and spectre...
Assembler is totally useless to you if you don't know the internal processor structure you want to program for.
Ok, admitted... perhaps not totally useless but you won't understand Assembler if you don't understand microprocessors/controllers in detail.
Very important keywords are register, shift-left, shift-right, global-descriptor-table register, paging to name a few.
I just love it...
Why don't you just save yourself the time to write such garbage and me (us) the time to read it?
I do not understand why you consider my questions "garbage". They seem quite reasonable to me.
I started assembly programming Z-80 processors, then moved on to 6800 series processors before working on Intell 686. Discovering single board and embedded device with unique controllers to code for was wondeful. For each processor I started without an assembler, but obtained one as soon as I could. (You can code directly to machine, but an assemble makes life a LOT easier!) For each processor I had a limited reference, and obtained a complete reference or guide as soon as I could. I would like to know what resources the OP has already gathered, and what start he has made (if any), before adding advice of my own.
I notice that references (of a wide range of accuracy and value) are available on the internet these days. A quick search will turn up several examples.
And even the venerable CP/M® operating system was written in a high-level language, as was Unix®.
"Learning about the microprocessor" is actually quite a time-consuming task if you want to pore through the more than 7 thick manuals which describe the x86 family of chips. "Does this model or that model support this esoteric instruction?" Well, the compiler knows already – just name your target and pick your level of optimization.
As I've said, the extremely-disciplined way in which the Linux team (necessarily) uses assembler for "architecture-specific" pieces is very typical. You'll find pure-assembler in the so-called "trampoline" code (which "bounces" the chip into its final operating mode, never to return), but that's about it.
Last edited by sundialsvcs; 03-08-2018 at 06:37 AM.
Thank you all, helpers,
just i am new and want to learn assembly:
1- ٍShould i learn Computer architecture before learn assembly? if yes which book is to start with?
2- Which book i should start with to learn assembly?
3- I want some advices in assembly field.
Well, you can't do much without knowing the architecture of the CPU and its glue, so you need to pick a target CPU and/or single board computer, then gear your learning toward that device and board.
Quote:
Originally Posted by wpeckham
I do not understand why you consider my questions "garbage". They seem quite reasonable to me.
I started assembly programming Z-80 processors, then moved on to 6800 series processors before working on Intell 686. Discovering single board and embedded device with unique controllers to code for was wondeful.
Wonderful indeed!
@bluntroller: Please refrain from insults to other members.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by astrogeek
@bluntroller: Please refrain from insults to other members.
It is clear that this statement by bluntroller was totally joking. If you continue to read he also states he loves assembly and considers his own activities a waste of time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.