No announcement yet.

How to learn Intel assembly?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to learn Intel assembly?

    Hi all,

    My experience with Assembler is quite limited. The only thing I have done is building a little test program for a 8-bit 6502-based gaming console a few years ago, just for fun. I found 6502 assembly to be very fun and easy to learn.

    I would like to learn modern Intel 32-bit Assembler, so I could use the Inline Assembly feature of PowerBASIC. Mostly for fun and interest in this feature, at this time I can't really think of a feature that I wouldn't be able to do with normal BASIC code, but maybe someday... Also I have seen inline assembly code in examples posted here (and elsewhere), that I would like to "understand" myself.

    Are there any good books on this subject, that you guys/gals would suggest for a newbie?

    Best regards, Vincent

  • #2

    it's not an easy question. It doesn't make a lot of difference to program with an external assembler or the inline assembler. The most modern compilers supply an inline assembler, which is very convenient for the programmer. A good starting point to PowerBASIC's inline compiler should be:

    If you need some ideas, what you could do with assembly language in general, please check:

    I hope that helps a bit.

    Encoding Team


    • #3
      I like generally to learn by example. Last machine coding I did was at Uni for a Transputer (remember them) and a 6502 so that would be, erm, errr, 15 year+ ago.

      Pointers to a well annotated command set would be useful too.
      Neil Croft (cissp)


      • #4
        Here's an old but still rather useful outline of many integer opcodes that can be used for a quick reference.
        Attached Files


        • #5
          Back in the day, I never used MASM, instead, I used A86 assembler with D86 debugger. It was great AND SHAREWARE. Eric Isaacson wrote them and was part of the original MASM team, I believe. This was quite simply a great assembler, with not just a subset of the MASM commands, but a SUPERSET.

          Why do I tell you this? Because it's still available for free, and it's even been upgraded to A386 / D386. It supports todays processors, just like PB.

          I generally use the A86 documentation as my assembler reference.

          You can try this, especially with the debugger, and see EXACTLY what your code is doing...also the documentation is quite good, and will help to teach you. You can try it out for awhile, without spending alot. When you get more proficient, you'll feel more comfortable using PB's inline assembler. Even if you just want to us the PB only, you'll find great documentation with the A86 that will help you with the PB assembler also.

          Here is a link:

          Of course, most important with Assembler isn't just the syntax, but you have to understand the hardware and the CPU registers etc. Get a good understanding of that, and the language will make more sense, in fact, for many things like bit manipulations and hardware interactions, it's the only way to go. Throw in the lightening speed and low overhead.

          Way back when, I used to do everything I needed (alot of PLC front ends and machine controls) with Quickbasic and A86. What I couldn't do easily in QB, I used assembler to do. Now PB does it all, inline. I love Powerbasic, it married my two favorite things!
          "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
          "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill


          • #6
            Perhaps the great virtue of PowerBASIC is that it is written in assembler by an assembler language programmer and it shows in a number of interesting ways.

            You can code legacy basic complete with line numbers if you want, clean cut respectable high level legacy basic with structured loop handling if you don't know any better but then you can get into the quick and dirty stuff if you really want and even use a few GOTOs if you don't care about being politically correct.

            You can go the next level down and play with pointers and get some very good performance increases where it matters and do things that legacy basic does not handle well but depending on your background and personal preference you have the final performance option, a high quality Intel compatible notation assembler that in the current version does the complete opcode set up to MMX and XMM and importantly has a very flexible #align directive in a useful range of 2 4 8 16 32 and 64 byte alignment.

            Often people see assembler as a last resort when they cannot work out how to do something any other way yet this does not do justice to the capacity or even vaguely understand why such a capacity is available.

            You write code in assembler because YOU CAN. Free from crippleware assumptions, 2nd, 3rd and 4th hand pecking orders of why its politically correct to write bloated garbage you can do more or less whatever you want if you can get it to work and package it in any manner that is convenient so its easy to use.

            Now learning and using an assembler is a different matter, the reference material is in fact excellent, Intel publish a very comprehensive set of manuals for their processors and while they are not casual light reading, you have exhaustively good reference material available.

            Gradualism is the action in learning to use an assembler, start with simple code, MOV, ADD, SUB, CMP etc ... and learn how the conditional jumps work,
            JE, JNE, JZ, JS, JNS etc ....

            To start make a SUB or FUNCTION that has the #REGISTER NONE directive so that the compiler optimisation does not take over the registers and make sure you use the FUNCTION = whatever to exit the function, never never use a RET to exit a basic function or it will go BANG.

            You need to learn a couple of very basic things, data SIZE and operand types.

            mov eax, 12345678  ; immediate operand copied into the EAX register
            mov eax, ptrData  ; memory operand copied into register EAX.
            mov pMem, eax  ; copy EAX register into a 32 bit memory operand
            mov eax, edx  ; copy EDX into EAX
            The intel x86 processor does not have an opcode to handle direct memory to memory copy. If you try and code,

            mov mem1, mem2
            It does not work as the MOV mnemonic does not support an opcode that will do it. You must copy memory to memory either through a register OR with a trick using PUSH POP.

            mov eax, mem1
            mov mem2, eax
              ; or
            push mem1
            pop mem2
            Usually the register version is faster and you woud use it in a critical algorithm but PUSH POP does not use a register at all so it can be very handy in some places.

            Probaly a good piece of advice to start with, get used to using memory operand early as registers are a scarce commodity which you can run out of very quickly.

            When you have an algo up and running you can start optimising it but the trick is to get it going first.
            hutch at movsd dot com
            The MASM Forum - SLL Modules and PB Libraries