Which resources are best for learning assembly language as a beginner?

In summary: After your first hour or two of learning assembly language, you will be able to code in a variety of languages including 6502 assembly language.In summary, it depends on your goals for learning assembly language which one you should start with. For beginners, I would recommend starting with simpler machines and then progressing to more complex ones.
  • #1
s00mb
33
10
TL;DR Summary
How much does the era of assembly language matter?
So I made it one of my projects to learn assembly language. Hoo boy. Started looking through online pdfs and some are extremely advanced jumping into like 5 different developing environments and others assume I'm dumb as a nut and don't even know binary representations of numbers or simple logic expressions. One of the other glaring things I noticed when I began my search for study material was that some assumed 32bit cpus or 64bit ones for the assembly language. Does it matter if I learn an out dated version of the assembly language for 32bit or less and then progress to higher systems? Many of the manuals I've found start out with 32 bit is why I am asking. I'm not too far into learning this but wouldn't there be different registries on 64bit? Would it be easy to transition? Should I just start with manuals assuming 64bit? I am in the phase where I am absorbing a lot of information so sorry if this is unclear or I am making mistakes. Also, does anyone know good sources to learn from for "newbies" at this? I like to look at 2-3 different references when learning. I am familiar with VB.NET and C++, and have a strong math background, know logic/discrete math etc.
 
Technology news on Phys.org
  • #2
s00mb said:
Does it matter if I learn an out dated version of the assembly language for 32bit or less and then progress to higher systems?

It depends on why you are learning assembly language. If you are going to actually write programs for some useful purpose in assembly language, then you should learn whatever assembly language applies to the system and microprocessor you are writing programs for. If you are just learning assembly language for fun and knowledge, then I don't think it matters much which one you start with, they all have the same basic structure and learning anyone will teach you valuable things about how computers work.

s00mb said:
wouldn't there be different registries on 64bit?

Details like this will depend on the microprocessor series. For 64-bit Intel and AMD x86 processors, the 64-bit registers are a superset of the 32-bit ones (which in turn are a superset of the 16-bit ones, which in turn are a superset of the 8-bit ones). For example, you have the 64-bit register rax; the first 32 bits of it can also be addressed as the 32-bit register eax; the first 16 bits can also be addressed as the 16-bit register ax; and the low and high bytes of ax can be addressed as the 8-bit registers al and ah. I don't know about other processor types, but I wouldn't be surprised if their registers worked similarly.
 
  • Like
  • Informative
Likes Klystron, sysprog, QuantumQuest and 1 other person
  • #3
Thanks this makes sense. I was trying to learn it on intel processors probably should have included that...
 
  • #4
PeterDonis said:
For 64-bit Intel and AMD x86 processors, the 64-bit registers are a superset of the 32-bit ones
But also include a number of brand-new registers, named R8, R9, ..., R15, that don't have counterparts in the earlier architectures.

If you want to learn assemly, x86 isn't the easiest to learn, due to its complexity. A better choice, IMO, is MIPS assembly language. There are at least two MIPS simulators that can be run on PCs or Macs. One is QtSpim (http://spimsimulator.sourceforge.net/ - get QtSpim, not PCSpim, and older version) and another is MARS (https://courses.missouristate.edu/KenVollmar/MARS/).
 
Last edited:
  • Like
Likes Wrichik Basu, sysprog and QuantumQuest
  • #5
@s00mb every processor has its own assembly language because assembly language is the fundamental language of the machine itself ("machine language") just using English (more or less) tokens in place of the 1's and 0's.

SO ... as Peter said, if you are learning to use a specific CPU then you have to learn THAT assembly language, otherwise it won't matter too much.

You might find it useful to read my Insights on computer languages https://www.physicsforums.com/insights/computer-language-primer-part-1/
 
  • #6
So, newbie question, does the amount of cores in a processor or even if it has hyper threading effect the assembly language?
 
  • #7
s00mb said:
So, newbie question, does the amount of cores in a processor or even if it has hyper threading effect the assembly language?
There would be particular commands to invoke a thread, and probably for the processor cores also.
Threading complicates things.
For a beginner, not necessary.
The computer itself has hardware threading, part of the operating system.
A software thread from the user - until you get more familiar with assembly, I would stay away from it.
 
  • Like
Likes sysprog and phinds
  • #8
If your goal is to get the feel for assembly language, as Peter said, then the fastest learning comes when you choose a simpler machine. The Mostek 6502 was the famous chip at the "sweet spot". It is very capable, yet simple enough that you can master its full complexity in an hour or two.

There are several 6502 emulators around, even Apple 2 simulators, so you could write an Apple Pong program as your first project.

After your first project, if you are still interested in assembler, then you can move to your target machine.
 
  • Like
Likes Asymptotic, QuantumQuest and hmmm27
  • #9
s00mb said:
Summary:: How much does the era of assembly language matter?
It matters in some very specific instances, the most important is when you are trying to debug an elusive hardware-related bug. I would advise you to learn C (not C++) and look at the assembler output of the compiler. C is very close to assembler and somewhat more readable.

Coming from hardware design, I have done my share of assembler programming. After discovering C, I have more or less dropped assembler (except when I need to see the exact interaction with hardware).
 
  • Like
Likes Klystron and sysprog
  • #10
s00mb said:
So I made it one of my projects to learn assembly language.
You should clarify first that why are you learning assembly. It is mostly used for:
- close-to-hardware level programming
- small CPU programming (closely related to the previous one, yet a bit different)
- performance optimization
- debugging

The focus of study (and the type of relevant sources) is really different. For the first, it is the 'https://www.amd.com/system/files/TechDocs/52740_16h_Models_30h-3Fh_BKDG.pdf' type documents: for the third, it is the 'software optimization guide'. Of course, both requires a strong basis in C and general/inline assembly.

The small CPU part is the most fun (at least, for me): among the still relevant CPUs I prefer to suggest the PIC family.

Debugging is a bit off, since that's more about reading the code than making it.
s00mb said:
Started looking through online pdfs and some are extremely advanced jumping into like 5 different developing environments and others assume I'm dumb as a nut and don't even know binary representations of numbers or simple logic expressions.
Yep. Assembly is not really mainstream anymore, so most people got scared away after the first glance: the relevant documents are usually for advanced users. That makes the medium level void.
 
  • #11
If you're serious about learning assembly language for Intel processors, you might want to look at MASM.

The 64-bit version is availble with a download of Visual Studio C++:
docs.microsoft.com/en-us/cpp/assembler/masm/masm-for-x64-ml64-exe?view=vs-2019

You can find an independently developed Visual MASM here: http://www.visualmasm.com/

And the now venerable MASM32 SDK can be accessed from here: https://www.masm32.com/
digression said:
For some reprobate reason, that site is backwards enough to use 'white on black' type. You can disabuse yourself of that eyestrain, and of the apparently-currently-trendy and to-me-annoying low-contrast 'gray' type or pastel-colored background, by using the following bookmarklet code (paste it into a bookmark): (copy as link ##\rightarrow##): zap colors
Code:
javascript: (function()
{
var newSS, styles = '*
{
  background: white ! important; color: black !important
}
:link, :link *
{
  color: #0000EE !important
}
  :visited, :visited *
{
  color: #551A8B !important
}';
if (document.createStyleSheet)
{
  document.createStyleSheet("javascript:'" + styles + "'");
}
else
{
  newSS = document.createElement('link');
  newSS.rel = 'stylesheet';
  newSS.href = 'data:text/css,' + escape(styles);
  document.getElementsByTagName("head")[0].appendChild(newSS);
}
})();
There is a wealth of documentation and tutorials for MASM, and a strong user community, supporting everyone from pristine beginners to world-class experts.
 
  • #12
Going back to when PC's were slow (original IBM PC) and the OS was primitive (MS-DOS 2.0), this is an example of what I wrote in assembly way back when:
Code:
;B
     Page    66,96
     Title     Character count program
;
; --------------------  SIZE  --------------------------
;
;  Format:     SIZE
;  Purpose:    To count the number of bytes in the
;        standard input file.
;  Parameters:    None.
;  Options:    None.
;  Examples:    To count the number of characters:
;                 size <innfile
;        To count the number of lines using TRANSLIT:
;                 translit ^@n | size <infile
;        To count the number of words using TRANSLIT:
;                 translit " "@t@n @n | translit ^@n | size
;  Written:    SvJo, 1/11 1984
;  Last change:    SvJo, 14/7 1985
;
; ------------------------------------------------------
;
;    Written in assembly to implement redirection
;    under DOS 2.0
;
CR    EQU    0DH
LF    EQU    0AH
TAB    EQU    09H
FF    EQU    0CH
EOF    EQU    1AH
;
COUNT    SEGMENT
;
     ORG    100H
;
     ASSUME    CS:COUNT
;
Start:    JMP    CNT1
;
;    Stack space
;
     DW    40 DUP (0)
SStk    LABEL    WORD
;
;    Some variables
;
Char    DB    ' '
;
Wrong    DB    CR,LF
     DB    'Sorry, you need DOS 2.0 or later '
     DB    'to run this program.'
     DB    CR,LF
;
WLen    EQU    $-Wrong
;
Fulld    DB    CR,LF
     DB    'Sorry, no more room on disk. '
     DB    CR,LF
;
FLen    EQU    $-Fulld
;
CntMsg    DB    CR,LF
     DB    'Size = '
CntBeg    DB    0,0,0,0,0,0
CntEnd    DB    0
CntDif    EQU    CntEnd-CntBeg
     DB    CR,LF
;
CntLen    EQU    $-CntMsg
;
CNT1:    MOV    AX,CS
     MOV    DS,AX
     MOV    ES,AX
     MOV    SS,AX
;
     ASSUME    DS: COUNT
     ASSUME    ES: COUNT
     ASSUME    SS: COUNT
;
     MOV    SP,Offset SStk
;
;    Check that operating system version is compatible
;
     MOV    AH,30H
     INT    21H
     CMP    AL,2         ;Version must be at least 2.0
     JGE    CNT2
;
;    Wrong version DOS, send message and abort
;
     MOV    AH,40H
     MOV    BX,02H         ;Standard error device
     MOV    CX,WLen
     MOV    DX,Offset Wrong
     INT    21H
;
     MOV    AX,0
     INT     21H           ;Abort
;
;    Clear ASCII accumulator
;
CNT2:    MOV    AL,0
    MOV    DI,Offset CntBeg
    MOV    CX,CntDif+1
    REP    STOSB
;
CNT3:    CALL    GETC
    TEST    AH,AH
    JNZ    CNT10
    TEST    AL,AL
    JZ    CNT3
;
;    Legal character, increment in ASCII
;
    MOV    BX,Offset CntEnd
    MOV    AL,[BX]
    DEC    BX
    MOV    CX,CntDif
    MOV    AH,[BX]
    ADD    AL,1
;
CNT4:    AAA
    MOV    [BX+1],AL
    MOV    AL,AH
    JNB    CNT3
    DEC    BX
    MOV    AH,[BX]
    JMP    CNT4
;
;    Make ASCII and eliminate leading zeros
;
CNT10:    MOV    BX,Offset CntBeg
    MOV    AH,' '
    MOV    CX,CntDif
;
CNT11:    MOV    AL,[BX]
    OR    AL,AH
    CMP    AL,AH
    JE    CNT12
    MOV    AH,'0'
    OR    AL,AH
CNT12:    MOV    [BX],AL
    INC    BX
    LOOP    CNT11
;
    OR    BYTE PTR [BX],'0'
;
;    Send count to standard output
;
     MOV    CX,CntLen
    MOV    AH,40H         ;Write
     MOV    BX,01H         ;Standard output
     MOV    DX,Offset CntMsg
     PUSH    CX
     INT    21H
     POP    CX
     CMP    AX,CX         ;Equal if OK
     JE    CNT25
;
    MOV    AH,40H
     MOV    BX,02H         ;Standard error device
     MOV    CX,FLen
     MOV    DX,Offset Fulld
     INT    21H
;
     MOV    AX,0
     INT     21H           ;Abort
;
CNT25:    CALL    CLOSE         ;Close file
;
     MOV    AX,0
     INT     21H           ;Abort
;
;    Get a character from standard input
;    Return char. in AL, EOF in AH
;
GETC:    MOV    AH,3FH         ;Read
     MOV    BX,0         ;Standard input
     MOV    DX,Offset Char
     MOV    CX,1         ;One byte
     INT    21H
     MOV    AH,0FFH         ;Check for EOF
     AND    AL,AL
     JZ    GETC2
     CMP    Char,EOF
     JE    GETC2
     INC    AH
     CMP    Char,LF         ;LF and not EOF?
     JE    GETC         ;Then get next char
GETC2:    MOV    AL,Char
     RET
;
;    Close standard output
;
CLOSE:    MOV    AH,3EH         ;Close
     MOV    BX,01H         ;Std. out
     INT    21H
     RET
;
COUNT    ENDS
;
     END    Start
 
  • Like
Likes Sajid86
  • #13
Avoid system level ASM. Start with the language you use most.

I would suggest you insert a fragment of inline ASM into your C++ code. Try two NOP instructions, then find those in the .asm listing of the compiled code.

By reading the ASM code generated by the compiler you will see the format required. Put in a couple of NOP blocks as markers, one each side of a high level line and see how C++ compiles the line.

You can then start to insert more useful blocks of ASM that interact with your higher level code.
 
  • #14
Baluncore said:
Avoid system level ASM. Start with the language you use most.

I would suggest you insert a fragment of inline ASM into your C++ code. Try two NOP instructions, then find those in the .asm listing of the compiled code.

By reading the ASM code generated by the compiler you will see the format required. Put in a couple of NOP blocks as markers, one each side of a high level line and see how C++ compiles the line.

You can then start to insert more useful blocks of ASM that interact with your higher level code.
I agree in principle with your suggestion of starting with something simple. When I started, I kept things simple for a time by at first restricting myself to experimenting with modifications to existing code. I learned most of the instruction set from the (fully backward compatible) System 360 manual, which was much thinner than the corresponding System 370 manual (largely because there was no virtual storage on the System 360).

In PL/I (a high-level language produced by IBM in the '60s), you can't use assembly language directly in line with the PL/I code, but you can declare and call assembly language subroutines. IBM uses PL/S, which allows inline assembly language, for its own system code, but doesn't release that integrated compiler+assembler to its customers.

If someone wants to become proficient in assembly language coding, he'll soon enough have to stop restricting himself to gingerly testing of the waters, and jump in. Before doing that, it's good to have a strong conceptual grasp of what's going on, plenty of samples and exercises, and a vibrant support community. And as in other fields of endeavor, no matter how talented you are, persistence is indispensable for success.
 
  • #15
The Operator's Manual for the first Altair computer has a very good introduction to basic CPU architecture of the 8080 CPU and Machine/Assembly Language. A high quality .pdf scan of the manual is available here:

http://www.classiccmp.org/dunfield/altair/d/88opman.pdf
(above found with:
https://www.google.com/search?&q=altair+8800+operator's+manual)

A minor drawback is that Octal, rather than Hexadecimal, is used. This is because the instructions for the CPU, although 8 bits, is based on 3-bit fields for source/destination. A couple years later, Intel (the CPU maker), rewrote their documentation using Hex which was coming into widespread use. The Octal representation made the initial learning curve a lot gentler though.

Cheers,
Tom
 
  • Like
Likes sysprog
  • #16
  • #17
sysprog said:
Links to pages for open source textbooks for 35 programming languages (including Intel assembly language) and for no-charge textbooks for 3 more: https://www.ossblog.org/opensourcebooks/.
Thank you for the link, you help me a lot.
 
  • Like
Likes sysprog

What is Assembly Language?

Assembly Language is a low-level programming language that is specific to a particular computer architecture. It uses symbolic instructions to represent machine code and is often used for writing operating systems, device drivers, and embedded systems.

Why should I learn Assembly Language?

Learning Assembly Language can help you better understand how a computer operates at the hardware level. It also allows you to write programs that are highly efficient and can access system resources directly, making it useful for developing low-level software.

Is Assembly Language difficult to learn?

Assembly Language can be challenging to learn, especially for those who are used to higher-level languages. It requires a good understanding of computer architecture and a lot of patience, but with practice and dedication, anyone can learn it.

What are some resources for learning Assembly Language?

There are many online tutorials, books, and video courses available for learning Assembly Language. Some popular resources include "Assembly Language Step-by-Step" by Jeff Duntemann and "Assembly Language for x86 Processors" by Kip Irvine.

Can I use Assembly Language for modern software development?

While Assembly Language is not commonly used for modern software development, there are still some use cases where it can be useful, such as for developing low-level programs or optimizing critical sections of code. However, it is not a necessary skill for most software developers.

Similar threads

  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
8
Views
876
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
2
Replies
60
Views
16K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top