Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Learning Assembly language

  1. Jan 22, 2012 #1
    Hello everyone.

    I have lot of extra time. So, I thought why don't I do some pure assembly language programming. So, basically, first I want to target 80x86 architecture processor. And get solid idea and understanding on programming through pure Assembly language. I don't want to learn assembly language in a way which will make me use pre-defined functions later. I mean, I want to write all of the code in pure assembly language, as if I am creating a new Operating System. I have learned somewhere that no Operating system gives any random user a privilege to interact with the HDD and other critical components of a computer and if random user wants to access any of those critical components, he/she is suppose to take help of pre-defined functions described by the Operating system. I believe, by taking use of these predefined functions, the user will be confined to do the usual things that Operating System will allow you to do. If someone needs extra control over the system, he/she must reverse engineer the entire targeted Operating System and figure out everything and then exploit the flaws and gain access to the critical components. I don't want to go into doing exploitation business. I want to learn genuinely and just for fun. I don't have any big goals. But I want to learn pure assembly language seriously.


    1. Just for instance: If I want to draw a curve on my display console I must be able to this through pure assembly language. I don't want to take help of any pre-defined functions. I mean I want to interact with the three color guns (Red,Blue,Green) of CRT monitor directly and be able to draw my desired curves.

    2. I want to learn the assembly language such that if someone gives me any processor of any architecture and whether it is 8 bit, 16 bit, 32 bit, 64 bit, 128 bit ... or any custom built multi-core microprocessor with 17 bits or 19 bits and an added extra register segment and additional control unit segment inside this custom built microprocessor with other components and peripherals as well, I must be able to look at the manual and must be able to implement my logic. Logic which even includes writing the entire Operating System and/or Graphical User interface through pure assembly language.

    I know, this is going to be very very very hard for me who just knows the basics of a particular processor and about it's architecture. And I am certainly not a master at it. But, as I said earlier, I don't have any big goals just looking to pass my immense amount of free time by doing some pure assembly language programming. Please help.

    So, I require:

    1. A good assembler which, should I say, meets my requirement (please read further to know more about the requirement and will help you get an idea). I know there are assemblers like FASM, MASM, NASM, TASM. I think, I used NASM earlier. I don't know if it supports any predefined functions. But I don't want to use any predefine functions as I described my intentions earlier. So, help me in selecting the best assembler that could be nice for me and which don't support any predefined functions and will enable me to write pure assembly language code.
    Also, I want to do my pure assembly programming without interacting with installed Operating System as if I am in 1960s - 1980s and where all I have is DOS. And I am trying to develop a revolutionary Operating System from scratch. So, that after I develop this Operating System, which even includes support(device drivers) for monitor and other peripherals, I want to burn this code into another machine's HDD(generally create .ISO image file, I guess) and get the machine work using my developed Operating System. Tell me if that is possible today.

    2. Editor window. I don't remember what editor window I used earlier. So, I need your help here also.

    I also want to say that, I am serious in learning pure assembly language as much as I could. Maybe, if I find it not very very complex I might go ahead and think about developing device drivers or an Operating System or Graphical User Interface through pure assembly language, in a way where I don't have to use any predefined functions. I think, I have already stressed a lot on learning pure assembly language.

    In addition to all the above that I have said, which is the main objectives and goals and aims. I also want to say the following, so that it gives you some idea, I want to get the ground knowledge of using pure assembly language and experience the era when there was only DOS and how people felt happy when they first created games using pure assembly language and when sounds devices were included with the computers, those people learned to put sounds in their games through pure assembly language. I think this paragraph will give you an idea about what I am looking for. I don't care how efficient or fast or execution or assembling of pure assembly language will be, unless we had different versions of same type of assemblers in those days. I don't want to talk more details on this. But I think you certainly have an idea by now about my requirements. I only want to learn pure assembly language. All the above may look very lofty ambitions but this is just for fun and I am serious in learning pure assembly language.

    Last edited: Jan 22, 2012
  2. jcsd
  3. Jan 22, 2012 #2


    User Avatar
    Homework Helper

    Even if you were to do development in MSDOS, you'd still run into issues trying to communicate with some of the hardware. For example, most video card manufactures will not release the direct interface specifications for their hardware. Instead you have to go through BIOS calls to change between text and graphics modes on the video cards, load fonts, ..., . Once it's in graphics mode, you can directly write to a portion of the graphical memory, but then you need BIOS calls to switch between banks of video card memory.

    You can still get specification the comon components on older PC's, timer, keyboard, serial port, game port, floppy disk port, IDE hard drive port, but I'm not sure where you can buy an older PC. Newer PC's don't have game ports or floppy ports, and emulate the old IDE interface for use with SATA drives.

    If your goal is to learn assembly language, learning to program the hardware would be a secondary goal. In the meantime, you could focus on writing MSDOS programs that use the standard BIOS and MSDOS function calls (these are INT instructions). If you wanted to program hardware, the timer chip would probably be the easiest to learn, perhaps writing a program that determines run time with a high degree of accuracy.

    You might consider some type of "hobbyist" project kit with a single board, cpu, ram, and some hardware, but I don't know if these exist anymore. Another possibility is some type of virtualized hardware: for example, a development kit for the ARM cpu includes an emulator with source code level debugger, but it doesn't have any virtual devices, and it's expensive (unless there's a student version of the kit). I don't know if there are any cheap or free virtualized machines that include virtualized hardware and a proper development environment.
    Last edited: Jan 22, 2012
  4. Jan 23, 2012 #3
    Okay. I want to try the following. Tell me if it's possible. First, I want to buy a single core processor, video card, basic RAM, HDD, Processor compatible Motherboard, keyboard, a mouse, CRT Monitor, HDD cables, CMOS battery, and I guess, internally, all the components in the computer system runs on Switched-mode Power supply, so, I would want to buy that too. And now I am thinking about connecting all of these component together. Please guide me if I am missing any component here. So, if everything is right here. I have my home-assembled computer ready. Now, if I switch on my home assembled computer, I will not see anything on my monitor because there is no System Software. So, now I am thinking about making my own System software. Even writing the interface which helps me edit the settings of the hardware. I mean, the interface which we get when we press DEL during boot time.


    Tell me if I understood this correctly:

    As you pointed out manufacturers of video card do not provide their interface and I am suppose to use their functions, and make function calls to display text or to display graphics on my CRT monitor by making use of BIOS(drivers that are already burned inside the ROM). The BIOS is connected to video card. So, that means, I have to call the function from BIOS code. And once the control is in graphics mode, I can directly write to a portion of graphical memory and display graphics but I have to switch between banks of video card to display text message on my CRT monitor.
    Do you think I definitely need to include video card in my set up? I mean, I am not going to write any intense game logic. And should I definitely include a video card? I thought there is always a built-in circuitry inside the CRT monitor. And this built-in circuitry inside the CRT monitor will have registers and some processor or perhaps a micro controller, attached to color guns(Red,Blue,Green). And I could just use pure Assembly language to target those chips on the mother board as well as inside the CRT monitor. I don't want to learn about the interface that these video card manufacturers provide if you say that I don't need video card just to display few 2-D lines and curves on my CRT monitor. Is this interface, that you mentioned, does it have specifications of how the electronic circuitry of video card is built?

    If you have ever seen Matlab program and the graphics display ability that this software has, does Matlab software developer guys knows the interface of video card which is enabling them to display graphs on the monitor? Or are they just using the functions in BIOS code which is permanently burnt inside ROM. I mean, putting 3-D graphics on the display is demanding operation and if BIOS is taking care of all of this then that is great.
    I know if I have full-fledged Operating system installed and if I want to attach a video card to my computer, I just have to put the video card in the PCI slot and install the drivers which is provided by the video card manufacturer and the installed driver software of video card will rest on the Operating system.

    So, after analyzing all of the above, I think I came to a conclusion if I really need to use video card for processing high graphics data coming from the processor through RAM ( I am assuming that video card drivers are installed on a full-fledged Operating system and I intend to use video card to serve my purpose) then I need to get hold of the interface(drivers) provided by the manufacturer and meddle with it.

    That will be a lot of reverse software engineering that I don't intend to do at all.

    But please, answer my other requirement about Assembler and editor. I still want to learn pure assembly language. But, now I want to use drivers that are burned inside ROM to make use of video card to display simple 2-D lines and curves. And the same pure assembly language I want to use to program Embedded systems. I don't have interest in writing code for Embedded system using C/C++ language and doing cross-compilation. I like C/C++ as mush as I like pure Assembly language. I think, code written in C/C++ language require more number of clock cycles of the processor to perform a task and will require more memory space when compared to code written in pure assembly language. I know all the above mentioned issues are not a big problem today because processor gives you high speed and we have plenty of memory. But still I want to learn pure Assembly language.

    I will feel a lot happier even if I just get to see the best assembler and editor which will enable me and help me write pure assembly language. So, please suggest an Assembler and editor so that I could learn pure assembly language. I will just give it a try to program some system, perhaps an Embedded system using pure assembly language and shall try to use pre-defined functions, if I could not achieve my programming feat without using video cards and the pre-defined functions of video cards.

    Please, suggest an assembler and editor for writing code in pure assembly language.

    Thanks again.
    Last edited: Jan 23, 2012
  5. Jan 23, 2012 #4


    User Avatar
    Homework Helper

    If this doesn't have to be a PC, you might consider buying a hobby type single board computer that uses an Intel 8088 or 8086.

    The monitor is driven by a graphics card. You can use an LCD monitor if it works with VGA output.

    How the power supply works doesn't matter.

    You should be able to by a pre-built hobbyist type single board computer.

    You have to switch between banks of memory to access all of the video card's memory even when in graphics mode.

    A monitor connects to a video card, not directly to a computer. You need a video card.

    No, the program probably uses the direct x interface which is part of the video card driver that is installed into windows. The bios is not used.

    It would be a lot easier to buy a hobby project board that just includes a processor and something like a small LCD display chip. I did a web search for "hobby single board project computer" and found a few hobby type boards. I would avoid the ones you have to wire up yourself.

    If the goal is to learn pure assembly language, then why not start with some simple programs that run under a dos console window, using the standard c libraries to input from keyboard and output to video card? The point here is to learn assembly language programming in general, instead of learning to write device drivers.
    Last edited: Jan 24, 2012
  6. Jan 24, 2012 #5


    User Avatar
    Science Advisor

    For MSDOS there are standard interrupts. Also if the OP installs a VESA TSR (video driver), then he can use the appropriate interrupts to setup complex video modes, which include those using 24-bit colour.

    The interrupt lists are pretty comprehensive for MSDOS if he wants to go down that route.

    The only problem I see if is if video cards don't have the legacy chipsets for old standardized support however with a good enough emulator, the calls to hardware ports and interrupts should be emulated correctly if this has to be the case.

    I agree in part but here is why I disagree in part.

    One project that would be interesting for the OP is to create a simple WAV file player for the soundcard. This would have to be done in an emulated environment like DOSBox but it is a good project none-the-less.

    Programming the sound card to play a sound file requires programming the Direct Memory Address controller and this is a pretty good exercise in configuring hardware using assembly. We take it for granted now, but its useful for the OPs purposes.

    Also as you have suggested, programming interrupts is a good thing to do. Apart from the timer chip, the other standard one I would recommend is the keyboard driver. Coding a really simple keyboard driver that prints the keys that are being pressed (kinda like a simple DirectX test would) is also a good project.
  7. Jan 25, 2012 #6
    I want to create my own DOS, design and develop my own video card, CRT monitor, Microprocessor, and write device drivers in pure assembly language for video card. And I want to use pure assembly language to write softwares to whatever systems that I create. I don't like the compilers of any high level languages or mid level languages in general. I think, there are too many drawbacks with high level languages and their compilers. And I think I will begin to not like assemblers that we have today if I find any drawbacks in it. So, as a matter of fact, I even want to create my own assembler. If I find any drawbacks with my self developed assembler then I will directly work with binary digits 0s and 1s and start flipping switches and let people call me antique. I think flipping switches was the case even before 1960s, I guess. And if I find any problem in working directly with 0s and 1s then I will develop a new technology.
    But the problem here is, I first want to understand how assembly language works and how data is assembled and converted into binary code by assemblers. I intend to design and develop my own microprocessor that is compatible with the currently available RAM and motherboard in the market. This is my project. I don't like to work on mundane concepts. I think that is very boring.
    I intend to work in Research and Development domain in my country, specifically in Electrical engineering and computer language programming field, 30 years from now. I believe this is the amount of time that I will need to learn and investigate all of the above concepts. Not happy. And I think by then we will be using data processors of some other technology. But, no worries.

    Let me ask you few more things by taking you to flash back scenes of the era when human beings found material to develop microprocessors.
    Now, let us apply some Applied physics here and quickly sum up everything.

    We discovered electron, electricity, magnetism and figured out all the concepts pertaining to this eventually. Eventually, we discovered material suitable to make solid state devices. We created few devices like vacuum tubes. We invented first computer. These computers were using switches as already discussed in this thread. Now, scientists did not like big things. So, they tried making them smaller. They succeeded. Next step, is the exact thing that I want to know. This is where I am stuck. If I can go back in time to 1960s and see the working of a computer, I would first want to investigate how data was stored on magnetic tapes, then work on designing assemblers with the people already working on this project. Investigate about Interpreters. And also investigate what events exactly made the computer geniuses to come up with DOS. And then investigate what events exactly ushered in an era to design softwares post DOS. And then came compilers and mid/high level language.

    I want to use my 32 bit computer to write softwares and drivers for my systems. I will design my own hardware. They will not be much complex but hopefully I shall improve. This will be like developing some primitive system. Perhaps, an Embedded system.

    So, please suggest me what is the best assembler and editor to learn pure assembly language. Suggest me the assembler and editor that were used even before DOS era and can even be used now to write pure assembly language code. I may come back and ask you more questions about assemblers.
    Or simply, you can suggest me a good assembler and an editor that will work to do pure assembly language. No offense to anyone, but I do not like working with high level or mid level languages on my projects.

    I do not think there are any books that will help me find all of this. Since, you guys have worked on those earlier computer systems I know that you all must be knowing a lot of things and can share your experience and knowledge.
    Last edited: Jan 25, 2012
  8. Jan 25, 2012 #7


    User Avatar
    Science Advisor

    pairofstrings, hold on just a sec!

    You need to realize that what you want to do is a lot of work!

    As other posters in this thread have said (or alluded to), keep it simple! Start on one project and keep adding mini projects to your big project.

    This is good because you may find that you really don't want to put in all the effort to learn something and you can leave it there and work on something else.

    One recommendation I have for you is to get the MSDOS source code. It exists out on the web and a tonne of it is written in assembler code. Take a look at that before you make any serious decisions about writing your own mini OS.
  9. Jan 26, 2012 #8


    User Avatar
    Homework Helper

    Any intel compatable assembler will be good enough. The editor isn't that important. You would want a debugger that can at least display the registers.

    For 16 bit real mode (MSDOS), you can download Masm 6.11 (assembler) along with a linker, and CodeView (source level debugger) directly from Microsoft or other sites. You'll probably want QuickHelp, which include descriptions of the intel instruction set and masm directives that you use in source code. Programmer's WorkBench (the Microsoft one for MSDOS, not the one for Unix or the old one for Macs) can be used as an IDE (integrated development environment), that works with projects (multiple source files). If you ever do embedded programming, you'd want exe2bin, or something similar, to create an binary image file. I'm not sure of the download links for all of these old tools, which date back to the 1980's thru early 1990's, but a web search will produce quite a few hits.

    Another option for 16 bit would be Borland Turbo Assembler which includes an IDE, assembler, linker, debugger, ...

    For 32 bit or 64 bit mode, Visual C/C++ express (free) includes Masm 8.00.xx, and a source level debugger. You'll need to add a build step so a project knows to use masm (ml.exe) to create an object file from a .asm file.
    Last edited: Jan 26, 2012
  10. Jan 26, 2012 #9


    User Avatar
    Science Advisor
    Homework Helper

    You might learn more from an open source OS that was intended to be educational, like MINIX, than trying to reverse engineer MSDOS. In fact you might even learn why about 99% of MINIX is not written in assembler...

    But I think your ambition to "do everything yourself from scratch" is unlikely to get anywhere, unless you really have say 10 or 20 years to devote to this full time.
  11. Jan 26, 2012 #10


    Staff: Mentor

    I used the Borland assembler (TASM) and debugger (TDEBUG) extensively back in the early 90s, and IMO, they were much easier to use than the equivalent MS tools. Just my opinion...
  12. Jan 26, 2012 #11


    User Avatar
    Gold Member

    Absolutely agree. Too bad Borland had such poor marketing and faded away; they really DID have a superior product.
  13. Jan 26, 2012 #12
    Go to Source Forge and look at the source code for the operating systems that they list. It is all open source, usually well commented, and you can see what was done and why.
    Today most OS's are a combination of C and assembler code. You can embed asm into C code and do what you want done faster that way.

  14. Jan 27, 2012 #13
    Did I understand Paul's words correctly? Please see the figure. Figure 1.

    Okay. Thanks for your guidance. You all might have already understood that I was trying to draw an outline so that I can get good intuitional understanding of the subject and that will make me likely to grasp the subject in its entirety. And with considerable efforts, later I can connect the dots seamlessly. Sorry, I did not mean to ...rush in my earlier post.

    Anyways, I have another general question.
    My computer is running Windows Vista(TM) Home Premium, Service Pack 2 and the specifications are:
    Processor: Intel(R) Pentium(R) Dual CPU T2310 @ 1.46GHz 1.47 GHz,
    System type: 32-bit Operating System
    RAM: 1.50GB


    I want to write assembly language code for 16, 32, 64, 128-bit processors on the machines that run 32-bit or 64-bit (or possibly even higher bits!) Operating system. I want to start with 16-bit, 80x86 processor architecture and later move to processors that support/accept more number of bits for processing, like 32-bit processor or 64 bit processor or 128 bit processor at once and so on. I may even change my machine on which I am going to write my code for the target machine. Currently I am using 32-bit processor, detail information about my machine is given above. Do I have to change my 32-bit processor computer machine if I want to target a processor that takes 8-bits or 32-bits or 64-bits of inputs? Which assembler should I used? Please see the figure below. Figure 2.


    As I already suspected and predicted earlier that there are going to be problems for me in using and finding a good assembler. I did some reading on FASM, NASM, MASM, TASM. Each of them have their limitations. MASM only good for windows. TASM not free and maintained properly, NASM supports few things but is only good for 32-bit processors. I found FASM to be good but it does not have much parsing power.

    I am not a master in programming using Assembly language but I want to work dedicatedly on this so, I want and I wish atleast one assembler to be perfect. Like say, having AASM (Awesome assembler). Do we have anything like that? I mean someone should be able to say, "just take this assembler buddy and you should be able to use it to program anything using assembly language on any processor architecture whether 16-bit, 32- bit, 64 bit, 128 bit and so on and on any bit Operating system, like 16-bit, 32-bit, 64-bit ...and 128-bit!" No, I am not picky, I just want to be able to do my work perfectly, like everyone else in the league. Please see the figure below. Figure 3.


    Question 2:

    Please tell me about 128-bit processors and can the number of bits supported by a processor go beyond 128-bits. Can we see 128-bit Operating system in the future? And can we create a HDD that can allocate so many(how much exactly?) memory location and give each memory location a unique address, so that I can store data into those memory locations? How will RAM that supports 128-bit of information and carry 128-bit of information to the processor and HDD going to look like? Is there a possibility to go beyond 128-bit on HDD, RAM, Processor?

    Figure 4.


    I am going to change my picture. Please wait. ...Fixed. Please answer my questions that are in the figures of this post (post#13).
    Last edited: Jan 27, 2012
  15. Jan 27, 2012 #14


    User Avatar
    Gold Member

    There is no conceptual limit to processor word size, but it will not be compelling for quite a few years to move beyond 64 bits for normal computer use.

    HDD and RAM have little, if anything to do with each other. They are totally different technologies and your confusing the two / equating the two is not helping your understanding of computers.

    EDIT: also, you continue to confuse O.S. size and computer word size. They are not the same. You can run a 32 bit operating system just fine on a 64-bit machine (but you can't do the reverse).

    I find your colored graphics / lettering unreadable, so can't comment on any of them
  16. Jan 27, 2012 #15


    User Avatar
    Homework Helper

    Just use MSDOS either directly or in a virtual machine. MSDOS runs in real mode, which is 16 bit. Just don't use any 32-bit prefixes on the instructions.

    You can get XP, Vista, or Windows 7 in 32 bit or 64 bit mode. The 64 bit OS's can run 32 bit code.

    Early versions of MASM predate any version of Windows. Masm 6.11 can be used to generate code for MSDOS or any environment that will run with 8088 (8 bit) or 8086 (16 bit) processors.

    From Wiki: There are currently no mainstream general-purpose processors built to operate on 128-bit integers or addresses:

  17. Jan 27, 2012 #16


    User Avatar
    Gold Member

    Hey, good point. Gads. MASM 6.11 ... boy, THAT'S been a while!

    I used to write BIOS code with that for both DOS and CPM (a different, and better, version of the DOS BIOS, that never really caught on)

    LATER EDIT: OOPS ... I did NOT use MASM 6.11 for CPM ... that was earlier. And CPM was not a DOS BIOS replacement, it was an alternate OS to DOS but used the same BIOS's
    Last edited: Jan 27, 2012
  18. Jan 27, 2012 #17
    If you want to use assembler code exclusively then you can disregard C programming but in C programs you can use embedded assembler code. Like I said - most OS's since DOS are written in C with embedded assembler code.

    Writing the entire OS in machine language is going to be a monumental task.
    I run DOS 6.22 on a quad core Intel processor (boot to CD or USB 1.44 floppy).
    I think you can run a 16 bit OS on any Intel chip from 80286 on as long as you use the proper syntax for the older chip. The older commands are compatible with the newer chips. (backward compatability at the machine code level)
    Processes get added with newer chips.

    by the way, you must be a bit masochistic to want to do this all in machine code. :)

  19. Jan 27, 2012 #18


    User Avatar
    Homework Helper

    That would be CPM-86. Wiki article:


    CPM ran on the older 8080 compatable instruction set. You could also run CPM with an 8085 or Z80.
  20. Jan 27, 2012 #19
    Thanks for writing. You can call me "a bit masochistic" or ...whatever. I set challenges on myself because I like it. And if you have read my first post of this thread, I have already mentioned that I have immense amount of time and I want to learn pure assembly language. I think learning pure assembly language is going to help me a lot in understanding complicated functions of a computer and I can design some impressive system as my project when I take higher studies in electrical engineering. I have also mentioned my method of learning in post#13. Hope that answers your curiosity. Please read all of my posts. I write nice stories, you will not get bored.
    Please tell me if I have correctly understood the meaning of embedded ASM and C language programming.

    EDIT: Sorry, I wrote "embedded ASM and C language programming" above. I was actually referring to the part where I can use assembly language code in my C language program in the C language editor, like in Turbo C/C++ version 3.0 editor and compiler.
    Anyways, thanks for the information in post#20. But my two questions in figure 1 of post#13 is still not resolved. It is about (Turbo) C/C++ compiler and C program containing ASM code. And there is another question in same figure 1 of post#13 as well. Please see figure 1. Please comment on my first figure of post#13.

    I have found some interesting things on the internet regarding a Processor and RAM limits. But could not understand the text. I shall come back to this topic for discussion once I get answers to all my questions in the figures of post#13.

    I have fixed all my pictures in post#13. So, please write. All the comments and corrections and discussions and analysis are welcome. Please see my post#13 and tell me what is wrong and how it could be correct and please answer my questions from all the figures. Thanks.
    Last edited: Jan 27, 2012
  21. Jan 27, 2012 #20


    User Avatar
    Homework Helper

    Embedded applications are ones that go into devices other than than a typical computer. This could include a hard drive, a cell phone, a microwave oven, an ECU for a car, ... . The basic coding methods are the same, but the interfaces that the code works with are different than a PC and how the code is initially loaded on the device is different. The operating system, if any, will be different than the ones normally used on a PC.

    Wiki article for embedded system.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook