MadSci Network: Computer Science
Query:

Re: Is binary programing possible today ?

Date: Mon Nov 5 12:56:22 2001
Posted By: Mike Westerfield, Staff, Computer Science, Byte Works, Inc.
Area of science: Computer Science
ID: 1004501317.Cs
Message:

It's certainly possible to program any digital computer entirely in 1's and 0's, but that was never a common way to program a computer. Let's look at the various alternatives, then see where you really want to jump in and try programming.

At the lowest level, every digital computer uses 1's and 0's (or the equivalent) to store programs and process information. In some really old computers you could actually see this process. A PDP machine I once programmed had a row of toggle switches on the front of the box, with one set for the address in memory and one set for the bits in the byte. You would set up the contents of a memory address, push a button to enter the value, and repeat. The only thing I ever used this ability for, through, was to tell the machine to load a real operating system.

Almost right away, people switched to either octal or hexadecimal numbers. It's just a lot easier to deal with B than with the string of digits 1011. On most machines, a byte is 8 bits, and two hexadecimal digits are used to represent the contents of a byte. You've probably seen hexadecimal and octal numbers in the past, but if not, you can find an explanation of them at http://www.intuitor.com/hex/bases.html. In a strictly purist sense, switching to hexadecimal means you're no longer using 1's and 0's, but most people would not care much about this distinction.

Programming in hexadecimal puts you into the realm of machine language programming. Very few people ever really did machine language programming, but it was done occasionally in the late 70's and early 80's for new computers that didn't have an operating system or any way to load one from another computer. As an example, a machine language program to add two two-byte numbers, one stored at memory location 1000 and the other at 2000, and save the result at 3000, would look like this for the 6502 microprocessor:

   18 AD 00 10 6D 00 20 8D 00 30 AD 01 10 6D 01 20 8D 01 30

In theory you could program at this level on a modern machine, but I didn't find a reference to any programs that would let you do it. All you really need, though, is a program that will take a string of hexadecimal values and write a binary file. Assuming you are using a Windows based computer, you then change the file to an exe file and run it.

Of course, there is more to it that this. Modern machines actually have a lot more than the program in the executable file. There is also some information used to tell the computer how to change the program so it will run in different memory locations, as well as some information that tells the computer a little about the program itself. While you could find all of the information you need to create all of this using hexadecimal numbers--or even 1's and 0's--it would be very, very tedious. I doubt if you could accomplish it without first learning assembly language programming.

And assembly language programming is the next step up. Assembly language uses simple names for the instructions the computer recognizes, adds labels so you don't have to figure out the specific location where a value is stored, and various other features to make writing programs easier. The assembler and its companion program, the linker, handle a lot of the drudgery of creating the relocation tables and header information I mentioned earlier. This is probably the closest it is practical for you to get to 1's and 0's. You certainly have complete control over every 1 or 0 that gets put into the program, but you have a tool that makes it fairly reasonable to actually write a real program. Most programmers don't use assembly language anymore, but it's still available. That program I mentioned a moment ago to add two numbers would look something like this:

   loc1   equ   $1000
   loc2   equ   $2000
   loc3   equ   $3000

          clc
          lda   loc1
          adc   loc2
          sta   loc3
          lda   loc1+1
          adc   loc2+1
          sta   loc3+2

Of course, the reason most people don't go to this trouble is that it's a lot easier in, say, C, where the same program would be

   short  a, b, c;
   c = a + b;

You can find assemblers and information about assembly language programs in a wide variety of places. There is an entire category devoted to assembly language programming on Yahoo! at http://dir.yahoo.com/Computers_and_Internet/Programming_and_Development/Languages/Assembly/


Current Queue | Current Queue for Computer Science | Computer Science archives

Try the links in the MadSci Library for more information on Computer Science.



MadSci Home | Information | Search | Random Knowledge Generator | MadSci Archives | Mad Library | MAD Labs | MAD FAQs | Ask a ? | Join Us! | Help Support MadSci


MadSci Network, webadmin@www.madsci.org
© 1995-2001. All rights reserved.