Learning Assembly and computer architecture for x86

Click For Summary
Learning assembly and computer architecture for x86 involves understanding the differences between CISC (Complex Instruction Set Computing) and RISC (Reduced Instruction Set Computing) architectures. The discussion emphasizes starting with a C compiler to generate assembly code, which aids in understanding the underlying processes. It is noted that modern x86 assembly is complex and rarely used for full programs, with high-level languages being more effective for most applications. Resources like Intel's programmer's reference manual and various assembly programming books are recommended, but the importance of practical experience is highlighted. Ultimately, gaining foundational knowledge through existing systems and gradually expanding one's understanding is advised.
elias001
Messages
389
Reaction score
30
Dear Peeps

I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are

Computer Organization and Design ARM Edition: The Hardware Software Interface

Computer Architecture: A Quantitative Approach

Digital Design and Computer Architecture

Computer systems architecture

Computer Architecture: Pipelined And Parallel Processor Design

Computer Systems a programmers perspective.

For assembly, I have

ARM assembly Fundamentals and techniques

A few books on IBM pc & XT assembly

Introduction to 8080/8085 Assembly language

books onIBM PC 8088 assembly

...

The IBM PC ones are from the 1980s.

For both sets of books, what do i have to keep in mind if none of them covers modern x86. OK for the computer architecture books that concentrates on ARM/RISC V and for the IBM PC assembly books, that covers 8085/8080, in both of these cases, how are they different for x86 assembly programming and architecture. What are the differences i should keep in mind when i picked up a book on x86 for either assembly programming or computer architecture. I keep seeing online from books where it mention that x86 architecture is part of the complex instruction set computers compare to say ARM or RISC. Is that similar to learning about industrial engineering versus learning aerospace engineering/engineering physics, where the former have to do with mathematical programming galore and the later two has do with the nonlinear section of the eighteenth level of differential equations hell?

Thank you in advance.
 
Last edited:
Technology news on Phys.org
The easiest way to learn is to work within an existing system.

Start with your friendly C compiler, one that allows you to examine the assembly code generated by the compiler, and also allows insertion of inline assembly language blocks into the source code, using something like; ASM and END ASM.

Get a copy of the intel 80x86 programmer's reference manual, with the instruction set, or whatever assembly code your machine runs.

Next, you can write a simple one line program and see what the compiler generates. Work out what it does and how it works. Notice the addressing modes being used. Start and end your inserted code blocks with three NOP instructions, so you can quickly find your code in the assembled source.

You can then start to insert and test the code you write.
 
  • Like
Likes phinds, Klystron, berkeman and 1 other person
@Baluncore what about when i read the computer architecture books, does it matter whether I choose RISC or ARM edition. But what about if I just want to know about intel architecture first.

For the assembly programming, can I use an online simulator/emulator for the old ibm pc to learn assembly? How would that be different than learning to decipher it through C?
 
Last edited:
Stop trying to do it the hard way, by considering too many things.

Do you have an old PC that runs C ?
Download the free x86 pdf manuals from intel.
Most PCs are intel x86 compatible, new platforms are starting to appear.

It is difficult to make a complete system from scratch that works.
It is easier to take something apart, to see how it works on the inside.

You need to see and use the conventional solutions, the ones used by compiler writers.
 
  • Like
Likes sbrothy and jedishrfu
@Baluncore I am on a Toshiba Satellite L500D -00F, and another toshiba running i7 3667U running at 2.00 Ghz 64 bit machine. Are they consider old machines? HackerGPT literally told me that my L500D-00F is an old clanker when I asked how to get the latest version of python 3 running on it.
 
X86 instruction set is a moving target. As suggested by others, start off with what a C compiler generates. Advanced stuff like AVX512 + GFNI (Galois Field New Instructions) isn't something most programmers will ever get involved with.
 
Last edited:
1) You seem to have a fascination with assembly language. What types of applications are you interested in? On another thread, you were interested in data structures. I would not advise learning data structures using assembly language. It would make it harder.
2) Programming RISC processors is a specialized skill. It is not like programming CISC processors. It is more difficult.
 
@rcgldr and @Baluncore another reason I am asking is i have seen a modern/recent (published in the last 15 years or so) about a book on x86 64 bit assembly, where the author states that many people don't write complete program in assembly but it is good to know how to read it whenever it comes up. So once upon a time, people did picked up a book on assembly programming the way people picked up a book on how to program in Java/C++? How would that be any different than learning assembly via deciphering through C? Also, is it true people don't code an entire programming in assembly anymore nowadays?
 
@FactChecker isn't the learning of assembly the same studying pure math for engineers? Engineers are happy with their advanced math for engineers, but if they really want to know how all of those math really works, i mean the nitty gritty details, they take courses in pure math.

Also, i have seen someone coding a neural network on youtube. I don't know if that is anymore difficult in learning data structures and algorithms in assembly.
 
  • #10
elias001 said:
... , where the author states that many people don't write complete program in assembly but it is good to know how to read it whenever it comes up.
I write a high level language package, then optimise it by hand assembling, only the critical inner loops that are intimately coupled to the hardware. I let the compiler sort out the system interfaces and data allocation.

There are so many texts, with so much useless code that you do not need. I don't know anyone who benefits from reading an entire text, before getting into the field. When something goes astray, and you have to fix it, you will have no time to read, you must get in there, and look up only what you need to know, when you need to know it.

I told you how to do it, but you seem more interested in the philosophy of procrastination than getting to understand assembly.
 
  • Like
Likes sbrothy, berkeman and jedishrfu
  • #11
elias001 said:
@FactChecker isn't the learning of assembly the same studying pure math for engineers? Engineers are happy with their advanced math for engineers, but if they really want to know how all of those math really works, i mean the nitty gritty details, they take courses in pure math.
No. Neither engineering nor pure math is like that. The first thing to learn in pure math is to use the tools (already proven theorems) to think at a higher, more abstract, level. When a pure mathematician wants to prove something new using an already-proven theorem, he does not rework all the tedious details of the theorem; he just invokes it.
elias001 said:
Also, i have seen someone coding a neural network on youtube. I don't know if that is anymore difficult in learning data structures and algorithms in assembly.
IMO, you have not worked enough with database languages or neural networks to appreciate the advantage that the higher-level languages (or libraries) offer.
 
  • #12
elias001 said:
what about when i read the computer architecture books, does it matter whether I choose RISC or ARM edition. But what about if I just want to know about intel architecture first.
The Intel architecture (limited to x86 and x64) is a CISC architecture (complex instruction set architecture) has nothing to do with RISC (reduced instruction set architecture) or ARM, which is a RISC architecture.
elias001 said:
@FactChecker isn't the learning of assembly the same studying pure math for engineers?
No, they are quite different.
 
  • #13
@FactChecker if someone learns to understand assembly language through looking understand the hood of a C program, then take away their C programming, can they write a program from scratch in assembly? There are heaps of books on assembly for the ibm pc family of computers even before x86 architecture arrived on the scene. Can they program in assembly and know assembly better than someone who is learning it through how assembly language codes the syntax of a C program?
 
  • #14
Every computer architecture is different. I started out on a mainframe. The core instruction set was general purpose but tended to slowdown COBOL.

The solution was to add the extended instruction set which used packed decimal format which improved COBOL’s math processing dramatically.

It worked by converting punch card numbers into packed decimal and then doing the adding, subtracting, multiplying and dividing with them.

From there it was relatively easy to get back to printable numbers for a business report.

The old way was to convert the input numbers into integer or floating point to do the math as was done in fortran. This is a more costly solution processing wise than packed decimal especially in a COBOL business oriented application.

At the time, I was fascinated by the extended instruction set because of its novelty. But the only way to really learn it was to get an assembly listing of your COBOL program. After that I stuck with the core set with A, Q, and index registers.

A = the accumulator register
Q = the quotient register
X0..X7 were the index registers used to hold addresses and array index values.

Every computer architecture is different so start with and learn how to load and store values, loop, doing conditionals and then expanding your horizons using the recipe approach.

Many schools teach MIPS assembler. It’s a RISC architecture used in IoT devices like routers…

https://learnxinyminutes.com/mips/

I would recommend MIPS for its RISC architecture and popularity in schools.
 
  • #15
elias001 said:
Can they program in assembly and know assembly better than someone who is learning it through how assembly language codes the syntax of a C program?
"Knowing assembly better" is an interesting concept. You only need sufficient knowledge of assembler to solve a problem today. You can look up the details when you need them. Next week you may be reading and writing a different processor code.

The C language is an envelope that you can use to investigate x86. If you need to read or write assembly code, then you will almost certainly be interfacing it to a HLL. The op codes you will encounter in C are the ones you will need most often.
 
  • #16
rcgldr said:
Galios Field New Instructions
Make that Galois Field New Instructions.
 
  • #17
elias001 said:
I want to ask you veterans how you folks learn program in assembly
Z80 and 6502... That also gave a very good example about what is RISC and CISC...o0)

elias001 said:
what do i have to keep in mind if none of them covers modern x86.
That 'modern x86 assembly' is a very special, barely existing niche. In general, by now x86 programming is such a monstrous and complex topic that assembly is very rarely used, and, to be honest: coding on and code generated based on high level languages is usually more effective.
Although the exceptions are a well paid an important segment, you need to invest a lot into this topic first to get something meaningful out of it.

If you are interested in the basics of assembly, then I suggest you to check some small microcontrollers. There are some which is simple enough to be used as a starting point.
 
  • #18
Baluncore said:
Stop trying to do it the hard way, by considering too many things.
[…]
I hate to be the one to point it out, but the OP’s questions feel a little like sealioning.

I know I can just choose not to engage, but in another thread the OP wanted to learn intermediate level programming, then got the idea that starting with electromagnetism and electronic circuits was a good idea.

Granted, I might have planted the idea of assembler in the OP’s mind, but now we have several books on assembler as opposed to the several books on basic programming concepts we started out with.

Maybe pick a place and start?

EDIT: and I admit “sealioning” is a little harsh.

EDIT2: and that being said: assembler is a good place to start if you want a good grip of the basics.
 
Last edited:
  • #19
Just my $0.02 but I wouldn't waste cycles (see what I did there) on learning x86 assembly. You're not going to out optimize the compiler. Learning assembly is a noble goal but I would focus on RISC such as ARM. Yes it's a little harder but may have more practical import. As some have said really learn C. C gets close to the metal so to speak. If feasible, get a microcontroller and learn to program on that. That will get you some real world type of experience in applying low level C and assembly.

Best of luck.
 
  • Like
Likes FactChecker and sbrothy
  • #20
bryantcl said:
Just my $0.02 but I wouldn't waste cycles (see what I did there) on learning x86 assembly. […]
Yes. Very funny. :smile:

Also why x86? Aren’t most cellphones 64bit by now?

You could get an emulator and learn to code for the 8bit C64. At least it’s a beginning. :smile:

No, sorry. Now I’m being cynical.
 
  • #21
If you really want to learn assembly code, then do it. Even for a high-level, professional programmer there are occasions to insert inline assembly code into general-purpose code. And there will be occasions to modify assembler code for special uses.
But do not think that it will compete with higher level code for most applications. You will still be working on your first large assembly code program when others have moved on to their tenth program. Those high level languages were not developed just for fun.
IMO, data structure and neural network applications like relational databases and image recognition are not the best places to use assembly code.
 
  • #22
I’m playing devil’s advocate for the OP here when I say that talking to the chip directly using assembler is a wonderful way to discover both the strengths and the weaknesses of programming.

Discovering that your most advanced GUI function is writing a single character to the screen has a sobering effect.
 
  • Like
Likes FactChecker
  • #23
So learning knowing assembly language is a means to some other end nowadays? At my university, when I look at the list of courses that is listed in thr catalogue vs ones actually being given, computer architecture is not there. I know computer science has changed and is in the midst of changing again. I did managed to get a few books specifically having to do with C and assembly language together in one book. But those have to do with understanding assembly so that one can write better C code.

I also just found out that the course on compiler, LLVM is being taught.

Maybe one day people don't ever have to know assembly at all and knowing it would be the equivalent of programming using punch cards today, just like people don't start put with learning C, while it wasn't so long ago that everyone starts with learning C.
 
  • #24
If you dont have a basic grasp of assembler you might be stumped when you encounter an asm block in your C code. It’s all connected.

EDIT: but I agree you might have a point. Just like young people today have no idea what a “slide rule” is. The pre-computer tool that put us on the moon. But i’s probably not important.
 
  • #25
@sbrothy it doesn't matter whether I use Microsoft micro assembler or turbo assembler, if I want to really experience what is like to write a program in assembly, more than just understanding how a C program is written out in assembly code. Basically, i want to know how to write a program in assembly language to at least experience what programmers had to learn and go through before the melting of the last ice age or when still some of them were hanging out with the dinosaurs.
 
  • #26
elias001 said:
@sbrothy it doesn't matter whether I use Microsoft micro assembler or turbo assembler, if I want to really experience what is like to write a program in assembly, more than just understanding how a C program is written out in assembly code. Basically, i want to know how to write a program in assembly language to at least experience what programmers had to learn and go through before the melting of the last ice age or when still some of them were hanging out with the dinosaurs.
As part of the college CS education in Denmark (datalogi) you’re often required to develop your own operating system (or similar basic task). It’s something you’ll probably never use in real life hence students sometimes outsourcing it to people who enjoy the task, get payed, and end up with the education you use to bail them out of trouble later on in their “career”.

Good fun. :)
 
  • #27
But seriously, you’ve asked enough questions to get started. If you keep asking questions (sealioning), then it’s clear you don’t really mean it but just wanna talk about it (and waste everyones time in the process).
 
  • #28
@sbrothy I am installing macro assembler 6. I am hoping i won't run into any troubles.
 
  • #29
It is just that
sbrothy said:
I say that talking to the chip directly using assembler is a wonderful way to discover both the strengths and the weaknesses of programming.
But using assembly in a sophisticated OS environment or within a C code is more about interacting with the framework, not really about interacting with the CPU.

That's why I suggested to look for controllers first. There assembly code may run alone, and the project will still remain something acceptable in size while already producing a bit more than a 'hello world'.

PIC has some nice, exotic enough pieces for this, IMO.
 
  • Like
Likes sbrothy and FactChecker
  • #30
@Rive in my first post, i said I was going through the book From bits to Gates to C and Beyond. It uses the Lc3 assembly language. I said I found most of the computer architecture books, at the the well known ones only have either Arm or Risc edition while there are assembly language books for assembly language geared towards different architecture. I am aware of using C and assembly for programming microcontrollers, embedded systems, or how some of the hardware description languages syntax resembles Pascal, C and Scala. But i want to know what it felt like to at least write a program in the x86 architecture in assembly. I mean pick up a book on assembly language for the x86 architecture, learn it and then being able to write programs in it. I also did ask how programmers in the old days learn to weite in assembly. Did they learn it by picking up a book like how they learn to code in fortran, etc. I mean there were so many different versions of assembly language. I am guessing baxk then then might not be like now where people are expected to know multiple languages even within a single programming language paradigm.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
2K
Replies
5
Views
4K
  • · Replies 13 ·
Replies
13
Views
2K
Replies
14
Views
3K
  • · Replies 4 ·
Replies
4
Views
15K
  • · Replies 397 ·
14
Replies
397
Views
19K
Replies
6
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 8 ·
Replies
8
Views
5K