LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How was the first program ever written? (https://www.linuxquestions.org/questions/programming-9/how-was-the-first-program-ever-written-4175472452/)

thelinuxist 08-07-2013 05:41 AM

How was the first program ever written?
 
Hi,

after learning some programming languages, I got to philosophizing a bit. The first python interpreter was written in C (I think?) and the first C compiler was written in ASM. But in which language was the first assembler written?

That's what I don't understand, because humans cannot write machine language directly (Can anyone? Looking at binary files opened with less, I don't think anyone could understand or even write even a simple app that way - not to think about a compiler).

So how was that made? I hope the question isn't too dumb to be answered. It's not technical, but rather just an "understanding" question.

druuna 08-07-2013 05:54 AM

Mybe these 2 links will shed some light:
- How was the first compiler written?
- Bootstrapping (compilers)

danielbmartin 08-07-2013 07:42 AM

Quote:

Originally Posted by thelinuxist (Post 5004721)
... humans cannot write machine language directly ...

Yes, they can. I am not personally able to do this, but I have seen it done by programmers who knew the opcodes by heart and consequently did not need the convenience of mnemonics.

Daniel B. Martin

Ser Olmy 08-07-2013 08:23 AM

Quote:

Originally Posted by thelinuxist (Post 5004721)
That's what I don't understand, because humans cannot write machine language directly (Can anyone? Looking at binary files opened with less, I don't think anyone could understand or even write even a simple app that way - not to think about a compiler).

Of course we can. Humans designed the CPU, so humans know which machine code instruction correspond to which assembly language mnemonic.

You write your program on paper using assembly or hexadecimal values. I've done that, and it's not that hard for a small program. You then transfer those values to the computer somehow.

The first computers were programmed with physical switches, each switch corresponding to one bit. Of course, entering large programs using switches would take ages, so the first program you make is one that can accept input from another source. Then perhaps you use that input to feed the computer a hex editor program, then use that to make an assembler, and so on.

schneidz 08-07-2013 08:32 AM

Quote:

Originally Posted by thelinuxist (Post 5004721)
Hi,

after learning some programming languages, I got to philosophizing a bit. The first python interpreter was written in C (I think?) and the first C compiler was written in ASM. But in which language was the first assembler written?

That's what I don't understand, because humans cannot write machine language directly (Can anyone? Looking at binary files opened with less, I don't think anyone could understand or even write even a simple app that way - not to think about a compiler).

So how was that made? I hope the question isn't too dumb to be answered. It's not technical, but rather just an "understanding" question.

not a dumb question... when i was in college i had an ee course in microprocessors where on some of the written exams we would need to translate byte-code <-> assembly code for the 65c02 cpu...

something like
Code:

0xad05
would load the accumulator register with the value of 5. that is hard to read so assembly mnemonics were created to make it more readable:
Code:

lda $05 ; load the accumulator with a value of 5
still cryptic but notice i am allowed to add a comment that the interpreter will ignore. to make it more readable 3rd generation languages were created: (c):
Code:

int apples=5;
char fruit[10]; // character array of type of fruit.

which makes it very obvious what each variable is (and when compiled it will generate the proper machine code for the cpu arhetecture. and finally 4gl's make it seem like an english sentance (sql):
Code:

select count from food where fruit = apple

Z038 08-07-2013 08:46 AM

Quote:

Originally Posted by thelinuxist (Post 5004721)
... because humans cannot write machine language directly (Can anyone? Looking at binary files opened with less, I don't think anyone could understand or even write even a simple app that way - not to think about a compiler).

Yes, it's possible, and it's not that difficult, but it is tedious. I wrote a fullscreen text editor for a 6502-based Apple II computer back in the early '80s. I had a 6502 instruction reference, so I did all my coding on paper using assembler opcodes, then I hand-assembled it and entered all the machine code in my program file using a hex editor.

I have disassembled many programs by hand from machine code to symbolic assembly language too.

I had access to an Altair 8800 back in the early '80s also. Machine language programs had to be toggled in through switches on the front panel. All those programs had to be hand-assembled on paper first before entering them. When you turned off the computer, they were gone. At least, until floppy drives (8 inch) and drivers for cassette tape were available, and then they could be saved and reused.

H_TeXMeX_H 08-07-2013 09:03 AM

Bootstrapping must be done in the real world as much as in the virtual world. How were the first tools built ? By hand, piece by agonizingly tedious piece.

brianL 08-07-2013 09:18 AM

Maybe they used a binary keyboard?

danielbmartin 08-07-2013 09:22 AM

As might be expected, the first computer program was written by the first computer programmer.

Refer to http://en.wikipedia.org/wiki/Ada_Lov...mputer_program

Daniel B. Martin

psionl0 08-07-2013 09:29 AM

ENIAC was programmed largely by hardwiring plugboards and setting switches on "portable function tables".

http://www.columbia.edu/cu/computinghistory/eniac.html

sundialsvcs 08-07-2013 09:29 AM

Augusta Ada King, the Countess of Lovelace is arguably (of course ...) the world's first computer programmer. She wrote programs for Charles Babbage's never-completed, steam-driven Difference Engine and Analytical Engine. By hand. It is unknown whether her programs contained any syntax errors. ;)

schneidz 08-07-2013 12:09 PM

^ programmable loom came first, didnt it ?

turboscrew 08-09-2013 07:22 AM

Quote:

Originally Posted by brianL (Post 5004874)
Maybe they used a binary keyboard?

Actually, close:
http://www.quadibloc.com/comp/panint.htm

johnsfine 08-09-2013 07:37 AM

Quote:

Originally Posted by thelinuxist (Post 5004721)
humans cannot write machine language directly

I have written many programs in machine language (none recently).

Long ago computers had toggle switches on their front panels to let you directly store data/programs into memory while the computer was halted. I not only wrote programs in machine language, I also inserted such programs into the computer via the front panel toggle switches.

Later computers had loader programs stored in ROM chips, so you could type machine language programs in hex to get them into memory. I did a lot of that as well.

I never wrote anything as complicated as a compiler directly in machine language. Turing did. I'm not sure whether anyone else has. A multi layered bootstrap process is easier.

Once I did the full process of bootstrapping to a high level language compiler myself: Write a crude assembler in machine language: Write a better assembler in that crude assembly language. Write the compiler for a usable subset of a high level language in that assembler. Rewrite that, plus some extra language features in that subset language. Enhance the language and compiler together, using new language features to support newer language features.

turboscrew 08-09-2013 07:43 AM

Writing a program using switches was really not so tedious, when the computer had something like 512 registers.
(Those days memory locations were called registers - or rather the computer only had registers, and if there were many of them, they were implemented as memory.)


All times are GMT -5. The time now is 11:21 AM.