Learning Assembly and computer architecture for x86

elias001
Messages
365
Reaction score
24
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 (Galios Field New Instructions) isn't something most programmers will ever get involved with.
 
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.
 
  • #31
elias001 said:
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.
If you go back far enough, IBM dominated. I "learned" assembly language in a college class that was 75% IBM employees. There was no real variety. The latest IBM development was all that mattered.
(I quoted the "learned" because I was too immature and lazy at that time to really learn it.)
 
  • #32
@FactChecker so what was it like wearing your own assembly programming? I mean you has Basic, Fortran and Pascal. Did you find it tedious or was it something you just did and thought nothing much of it.
 
  • #33
elias001 said:
i want to know what it felt like to at least write a program in the x86 architecture in assembly.
It's just assembly these days is not used for general programming on x86.
It'll be very hard to get any real, useful, relevant experience apart from some variations of 'hello world'.

That's why I recommended starting with microcontrollers. There, it's still possible to get the full experience.
 
  • #34
@Rive is programming microcontrollers the same as programming embedded systems? Also for assembly language, do each iterations of an architecture in the same family require one to learn a new version of assembly language. What i mean is say for the x86 family, there were pentium 2, then 3, 4. Now they have the ix family of chips. For each of these do people have to learn assembly language over again? I am guessing same question applies to diffferent iterations of Adruino and Raspberry Pis.

Sorry if I hope I am not asking something naive. But i keep hearing assembly is a bit different depending on which hardware architecture. But then my understanding is that there is a connection between Arm and RISC which i am not sure what it is.

Also if I want to use inline assembly in C, do I have to look up what cpu chip set my laptop is running on in order to be specific how to write my assembly code?
 
  • #35
elias001 said:
@Rive is programming microcontrollers the same as programming embedded systems?
Kind of. The term 'embedded system' usually hints a more complex environment, often with some kind of OS: while the term 'microcontroller' can be just some minimalistic setup - the smallest devkit with minimal addons.

elias001 said:
for the x86 family, there were pentium 2, then 3, 4.
As a beginner, what you will likely need is the IA32 as basis, from 1985... Everything can run that today.
Above that, it'll be about the interaction with the OS.

elias001 said:
I am guessing same question applies to diffferent iterations of Adruino and Raspberry Pis.
Yep. Usually there is a common basis for every family, with type-specific additional extras.

elias001 said:
Also if I want to use inline assembly in C, do I have to look up what cpu chip set my laptop is running on in order to be specific how to write my assembly code?
No. The OS (Windows?) you are using will severely limit the direct interaction with the hardware. When you have an OS then it's more about the interaction with the OS which is providing the necessary services to access what the hardware can offer.
 
  • #36
@Rive yes I am running windows. I have two books on advanced assembly, but most of the topics are about how to interact with a computer mouse, keyboard, etc. I am not interested in those topics yet at this point.

There are some basic things that are applicable to assembly programming regardless of which architecture one is writing it for? I wish there are books that has that.
 
  • #37
elias001 said:
There are some basic things that are applicable to assembly programming regardless of which architecture one is writing it for?
It is all about learning to dissect the problem to lot finer steps than usual, while creating your own levels of abstraction from scratch fitting with the limited (CPU) resources while minding the environment you are working with.

My humble opinion is, that it is kind of hard to get what assembly is really good for in such a resource-rich environment as a highly advanced CPU and OS.

elias001 said:
how to interact with a computer mouse, keyboard, etc.
What kind of environment (OS) is used in those books?
 
  • #38
@Rice the advanced assembly language books are all for the ibm pc, one of them uses the old Microsoft marco assembler. Both books were written in the late 80s and early 90s. Both books assumed the reader knows already know how to code in assembly language.
 
  • #39
elias001 said:
Both books were written in the late 80s and early 90s.
Then for practice you better get a PC from that era. Highly likely won't work on modern PC, with modern OS - but even if you manage to make it work, it won't give you much useful knowledge.

...I may suggest to get 'Peter Norton's Assembly Language Book for the IBM PC' too from that era (a scan may be downloadable, I think).
Very good resource - for assembly programming for 8086 under MSDOS up to 6.22, that is...

But honestly, I really recommend to start with a PIC12 or PIC16 devboard instead.
 
  • #40
elias001 said:
Also if I want to use inline assembly in C, do I have to look up what cpu chip set my laptop is running on in order to be specific how to write my assembly code?
Assembly languages are very much specific to the CPU being used. Years ago, Apple Mac computers used Motorola M6800x processors, which were completely different from the Intel x86 processors used in PCs. Later, the Macs used a PowerPC processor, which again was different from the Intel (and AMD) processors used in PCs of that era. I haven't followed Macs lately, but I understand that they now use the same or similar processors as PCs.
elias001 said:
I have two books on advanced assembly, but most of the topics are about how to interact with a computer mouse, keyboard, etc. I am not interested in those topics yet at this point.
I'm not very interested in those low-level BIOS operations, either. I'm more interested in writing mixed-language programs in which part is written in C or C++ (the main() function), with calls to functions written in x86 or x64 assembly. Doing things this way gives you a solid understanding of how parameters are passed to a function (stack-based on x86 and in registers in x64), how values are returned from functions, how pointers work with arrays and structs, and lots more.
 
  • #41
Here's a simple example of what I mean by mixed-language programming.
Below is the high-level part in C.
C:
// Driver.cpp : Call an assembly routine to add two integers, returning their sum.

#include <stdio.h>
extern "C" int AddParams(int, int);

int main()
{
    int arg1 = 5, arg2 = 13;
    int result = AddParams(arg1, arg2);
    printf("The sum of %d and %d is %d", arg1, arg2, result);
}
Below is the x86 assembly part that implements AddParams(). In x86 assembly, arguments to assembly functions (PROCs) are pushed onto the stack. The assembly function needs to know where are the stack the parameters appear in order to access them, in this case at locations 4 bytes and 8 bytes above the current value of the stack pointer. After the first parameter is loaded into a register, the second parameter can be loaded and added to the first. When the routine returns, the sum is in the EAX register, which is where the C main() function expects it.
Code:
.model flat, c
; 32-bit code -- i.e., uses 32-bit registers eax, ebx, ecx, etc.

.code

;Equates
Param1    equ <[ebp + 8]>
Param2    equ Param1 + 4

; Add the two parameters, and return their sum.
; Prototype: extern "C" int AddParams(int a, int b);
; "C" tells the compiler not to "mangle" the routine name
; Returns the sum of Param1 and Param2 in eax

AddParams PROC C
    push ebp
    mov ebp, esp
    mov eax, [Param1]   ; Load first argument
    add eax, [Param2]   ; Add second argument
    pop ebp
    ret                    ; Sum is in eax
AddParams ENDP
END

The output is as follows:
Code:
The sum of 5 and 13 is 18
 
  • Like
Likes FactChecker and sbrothy
  • #42
Rive said:
Kind of. The term 'embedded system' usually hints a more complex environment, often with some kind of OS: while the term 'microcontroller' can be just some minimalistic setup - the smallest devkit with minimal addons.


As a beginner, what you will likely need is the IA32 as basis, from 1985... Everything can run that today.
Above that, it'll be about the interaction with the OS.


Yep. Usually there is a common basis for every family, with type-specific additional extras.


No. The OS (Windows?) you are using will severely limit the direct interaction with the hardware. When you have an OS then it's more about the interaction with the OS which is providing the necessary services to access what the hardware can offer.
Yeah. I was also gonna suggest “embedded systems” I coded a barcode scanner and that was low level C against it’s BIOS ROM. Not much fireworks there! :)

EDIT: I also coded dictaphones and set up the backend completely with RDBMS. They were sold to Chinese hospitals close to nationwide. Made my boss a wealthy man but all I got (besides a good salary for an autodidact) was an AUDI A3. After I installed Microsoft Outlook Server I was told what Microsoft takes for the same task. I refused to show up for a couple of days after that, driving around in my new car, seething! :woot:
 
Last edited:
  • #43
sbrothy said:
Yeah. I was also gonna suggest “embedded systems” I coded a barcode scanner and that was low level C against it’s BIOS ROM. Not much fireworks there! :)

EDIT: I also coded dictaphones and set up the backend completely with RDBMS. They were sold to Chinese hospitals close to nationwide. Made my boss a wealthy man but all I got (besides a good salary for an autodidact) was an AUDI A3. After I installed Microsoft Outlook Server I was told what Microsoft takes for the same task. I refused to show up for a couple of days after that, driving around in my new car, seething! :woot:
Though I guess the car made up for ir with Danish taxes in mind. I just felt cheated.
 
  • #44
Mark44 said:
Here's a simple example of what I mean by mixed-language programming.
Below is the high-level part in C.
C:
// Driver.cpp : Call an assembly routine to add two integers, returning their sum.

#include <stdio.h>
extern "C" int AddParams(int, int);

int main()
{
    int arg1 = 5, arg2 = 13;
    int result = AddParams(arg1, arg2);
    printf("The sum of %d and %d is %d", arg1, arg2, result);
}
Below is the x86 assembly part that implements AddParams(). In x86 assembly, arguments to assembly functions (PROCs) are pushed onto the stack. The assembly function needs to know where are the stack the parameters appear in order to access them, in this case at locations 4 bytes and 8 bytes above the current value of the stack pointer. After the first parameter is loaded into a register, the second parameter can be loaded and added to the first. When the routine returns, the sum is in the EAX register, which is where the C main() function expects it.
Code:
.model flat, c
; 32-bit code -- i.e., uses 32-bit registers eax, ebx, ecx, etc.

.code

;Equates
Param1    equ <[ebp + 8]>
Param2    equ Param1 + 4

; Add the two parameters, and return their sum.
; Prototype: extern "C" int AddParams(int a, int b);
; "C" tells the compiler not to "mangle" the routine name
; Returns the sum of Param1 and Param2 in eax

AddParams PROC C
    push ebp
    mov ebp, esp
    mov eax, [Param1]   ; Load first argument
    add eax, [Param2]   ; Add second argument
    pop ebp
    ret                    ; Sum is in eax
AddParams ENDP
END

The output is as follows:
Code:
The sum of 5 and 13 is 18
I actually meant the asm keyword. Although nowadays, due to operating systems being paranoid about protecting their resources, it might be somewhat obsolete. Perhaps not on embedded systems and in low level OS code though.

Most compilers also have a switch for outputting your program as assembler (-S with GCC if I'm not mistaken). I'm sure Devstudio has something similar. It's been a while.

EDIT: Yeah:

MSVC does not support inline assembly on the ARM and x64 processors, and only support the form introduced by __asm on x86 processors.
 
  • #45
How much you will use assembly language depends on what type of work you do. If you get into real-time device handlers, you will see it a lot. In 37 years of programming, I have only been involved with assembly code a few times. Once was regarding device handlers. Once was in trying to speed up some real-time aerodynamic calculations (speed issues where memory access is involved is tricky and non-intuitive). And once was inserting assembly code to record test branch coverage of a test set.
That being said, if you are a good assembly language programmer the jobs will find you. The question will be whether you like those jobs.
 
  • Like
Likes Rive and sbrothy
  • #46
FactChecker said:
How much you will use assembly language depends on what type of work you do. If you get into real-time device handlers, you will see it a lot. In 37 years of programming, I have only been involved with assembly code a few times. Once was regarding device handlers. Once was in trying to speed up some real-time aerodynamic calculations (speed issues where memory access is involved is tricky and non-intuitive). And once was inserting assembly code to record test branch coverage of a test set.
That being said, if you are a good assembly language programmer the jobs will find you. The question will be whether you like those jobs.

Indeed, assembly language isn't known for being funny and a breeze to work with. And as for speeding things up in this day and age, throwing more hardware at the problem, fiddling with compiler flags, starting a concurrent process, or if push comes to shove, implementing multi-threading for the problem program is probably preferable 9 out of 10 times....

EDIT: Unless of course, as you describe, the problem being very specialized.
 
  • Like
Likes FactChecker
  • #47
sbrothy said:
I actually meant the asm keyword. Although nowadays, due to operating systems being paranoid about protecting their resources, it might be somewhat obsolete.
Visual Studio doesn't permit inline assembly (i.e., using the asm keyword) in 64-bit code. The example I showed was compiled as 32-bit code. The assembly code would look quite a bit different if I had done it as a 64-bit example, since the parameters would have been passed in specific registers rather than on the stack.
 
  • Informative
Likes FactChecker and sbrothy
  • #48
Mark44 said:
Visual Studio doesn't permit inline assembly (i.e., using the asm keyword) in 64-bit code. [...]
No. I wrote as much in my comment above. No harm in it getting chiseled in stone though. It's been that way for quite a while if I'm not mistaken.

EDIT: Your first comment obviously. Lemme edit that quote. There.
 
  • #49
@sbrothy, @Rive and @FactChecker I think all three of you recommended me to try out microcontrollers/embedded systems. So say I wrong an assembly program to control some tiny devices. Is that finished program call "firmware"?

Also the two advanced assembly language books that i have are:

Advanced Assembly Language on the IBM PC by Steven Holzner

and

Advanced Assembly Language by Allen L Wyatt

The two C books with assembly programming are:

C with Assembly Language by Steven Holzner

and

X86 Assembly Language and C fundamentals by Joseph J F Cavanagh.

I do also have that Peter Norton's book.


If I have any other questions about this topic, I will ask in a new post. I appreciate all of you explaining assembly language to me. I still feel weird about and uneasy about learning a programming language only for a specific architecture then knowing that on a different architecture the same programming language will have differences.
 
  • #50
I think firmware is more @FactChecker ‘s alley. I’d call a device driver firmware. Anything that interfaces to hardware.
 
  • Like
Likes FactChecker
Back
Top