Notices
Results 1 to 13 of 13

Thread: The simplest computer program

  1. #1 The simplest computer program 
    Forum Professor
    Join Date
    Feb 2009
    Posts
    1,773
    Years ago , (in the 70s I think ) I tried unsuccessfully to understand how you could write computer code. I got as far as binary numbers but no further .
    Apparently a string of zeros and 1's could be read as a command to a computer.

    So is any one able to give me the very simplest example of a command .I guess there also has to be a rudimentary language to "translate" this series of binary digits?

    So say all I wanted to do was to write the very simplest command conceivable what would be the shortest series of digits and what could be the most rudimentary "language" ?


    Reply With Quote  
     

  2.  
     

  3. #2  
    Cooking Something Good MacGyver1968's Avatar
    Join Date
    Aug 2006
    Location
    Dallas, Texas
    Posts
    2,051
    Machine code is the lowest level language. Pretty much the smallest snipet of code would be a single line of machine...like loading a register with a value. "load AX, FFFF"


    Fixin' shit that ain't broke.
    Reply With Quote  
     

  4. #3  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    Your title of the post is about the simplest program. Answering that depends on your definition of simple (from the computer's or human's point of view) and program (which category of languages you're looking at).

    Now, it seems like you're talking about machine language, which is the 1s and 0s the computer itself is actually executing. There is no lower level language than that, though it's very hard for humans to use directly, which is why assembly, FORTRAN, C, etc. were created.

    In that case, the simplest program (ignoring the OS specific initialization code, which is usually provided for you) would just be the empty program. The simplest single command would probably be something like a set register to constant command. IIRC that gets bundled in with the store command on Intel chips, so I guess it depends on your definition of simple. The shortest command would be one that doesn't need any arguments like a return statement, which takes up 8 bits.
    Reply With Quote  
     

  5. #4  
    Forum Professor
    Join Date
    Feb 2009
    Posts
    1,773
    Ok so to parade my ignorance is 8 bit a series of 3 binary digits 2 to the power of 3 ? And is the simplest language for translating the code into the computer one which is no longer in use ?

    I was just thinking when they developed the forerunner of Fortran was there an embyonic "language" that they used at the very outset (just to get the computer to make a rudimentary response)?

    Who was it who first wrote the first code for computers ? Was it Turing or is he just the first man to develop it so that people took notice?

    I did make an effort to learn this at the time when computer first programming became generally known and written about but was unable to get to grips with the concepts (that might be showing) .
    Reply With Quote  
     

  6. #5  
    Forum Freshman pzkpfw's Avatar
    Join Date
    Mar 2014
    Location
    New Zealand
    Posts
    79
    Nop
    Reply With Quote  
     

  7. #6  
    Moderator Moderator Janus's Avatar
    Join Date
    Jun 2007
    Posts
    2,070
    Quote Originally Posted by geordief View Post
    Ok so to parade my ignorance is 8 bit a series of 3 binary digits 2 to the power of 3 ? And is the simplest language for translating the code into the computer one which is no longer in use ?

    I was just thinking when they developed the forerunner of Fortran was there an embyonic "language" that they used at the very outset (just to get the computer to make a rudimentary response)?
    The basic language is machine language. This is coded directly into the microprocessor when it is built. The machine language consists of a number of operation codes or "op codes", and the set of op codes will differ from processor to processor. These op codes represent basic instructions regarding manipulating data in the processor's internal registers and external memory.

    They include simple logic (AND, OR, XOR etc.), math operations (Add and Subtract) or moving data around among some other things.

    In a simple 8 bit processor, each op code is an 8 bit binary number. The op code tells the computer the operation to perform and where to get the data.

    For example for the 6502 processor, 10101001 is the op code for "load the number immediately after this op code into the accumulator of the processor.

    If you want to load a value of 5 into the accumulator the entire instruction is

    10101001
    00000101

    The op code 10101100 means load the accumulator with the number you find at the memory address immediately following.

    Memory addresses are 16 bits long, so the address is broken up into to parts and the total instruction might look like this:

    10101100
    10111101
    00001000

    Basically, when the processor sees 10101100, it knows to take the numbers in the following two memory locations and use them find where the number you want added to the accumulator is.

    A very basic program might look like this:

    10101001
    00000101
    01101001
    00000110
    10001100
    11110000
    10111100
    00000000


    The first byte says take the number in the following memory location and loads it into the accumulator.

    The third byte starts the next instruction. It means take the number in the following memory location and add it to the contents of the accumulator. After which the contents of the accumulator will be the Sum.

    The fifth byte starts the next instruction: Take the value in the accumulator and store it at the memory location indicated by the following two bytes. The processor makes a complete memory address from the following two bytes and copies the number in the accumulator to there.

    The eighth byte is the break command and stops the program.

    So basically, this program takes the numbers 5 and 6, adds them together and stores the result at memory address 10111101111000.

    Now you might be asking, "How does the computer distinguish between 10101001 the op code and 10101001 the number?"

    It can't. When you first turn on the computer it goes to a set memory address where it expects to find an op code. It performs the op code and then looks for the next op code. Where it looks depends on what the first op code was.

    So lets say you made an error in the first line of our program above and wrote 10101100 rather than 10101001

    10101100
    00000101
    01101001
    00000110
    10001100
    11110000
    10111100
    00000000

    Now the computer reads this:

    1.Take the number in at the following address and load it into the accumulator.
    Originally, the instruction only used 2 memory locations, what should have been the next op code to be executed is used as part of an address.

    As a result, it now looks for the next op code at line 4, which was not originally intended to be an op code, but the processor will now treat as one.

    This code means " Take the number found at the following memory location and shift all its bits to the left with a zero filling the vacated bit position." (so for example, if the location held 11000110, it holds 10001100 after the operation) The address used by this particular op code only needs the the lower 8 bits, as the upper 8 are assumed to be 0.

    This means the processor looks for the next op code at line 6.

    This says 'If the result of the last operation resulted in a zero value, the next op code to be executed will be at the memory location indicated by adding the following value to the present memory location.' If final result did not result in zero, this is not executed and the processor continues to line 8 and breaks , otherwise it adds 10111100 to the memory address of the op code( it jumps ahead 292 lines) and continues running from there until it reaches a break command.
    So not only does the program not do what it was supposed to, it rewrote a memory location that could contain data or an op code, possibly corrupting a program stored elsewhere.

    Not only that, if the result of that rewrite was a zero value, it would continue to run, from a location that might or might not be an intended op code doing even more damage.

    Higher languages have to be translated into these op code for the computer to run them.
    "Men are apt to mistake the strength of their feelings for the strength of their argument.
    The heated mind resents the chill touch & relentless scrutiny of logic"-W.E. Gladstone


    Edit/Delete Message
    Reply With Quote  
     

  8. #7  
    Forum Freshman
    Join Date
    Oct 2017
    Posts
    5
    The simplest program ever is the Unix program true. Here is all the code needed to replicate it's behavior:

    Basically true's job is to execute successfully so that it will return the exit status 0 (which is interpreted as true in Unix). It accomplished this by successfully doing nothing.

    It even had a copyright notice:
    The /bin/true Command and Copyright

    So apparently doing nothing was copyrighted by AT&T.
    Reply With Quote  
     

  9. #8  
    Forum Freshman
    Join Date
    Oct 2017
    Posts
    15
    the "hello world" application lol
    Reply With Quote  
     

  10. #9  
    Forum Masters Degree
    Join Date
    Aug 2009
    Location
    New Jersey USA
    Posts
    643
    I believe creating console applications in a procedural style with the C language is a good place to start.
    Reply With Quote  
     

  11. #10  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,530
    Using something interpreted like Python is probably easier as a way of getting started.
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  12. #11  
    Forum Freshman
    Join Date
    Sep 2017
    Posts
    17
    // Simple Program
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    clrscr();
    printf("Hello World");
    getch();
    }
    Reply With Quote  
     

  13. #12  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,530
    Or, even simpler:

    0000: BR 0

    Or:

    0000: HCF
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  14. #13  
    Forum Masters Degree
    Join Date
    Aug 2009
    Location
    New Jersey USA
    Posts
    643
    I have also heard that taking a procedural approach to Python or JavaScript is a good way to start off.
    Reply With Quote  
     

Similar Threads

  1. Is it possible to program logos, pathos, and ethos recognition into a computer?
    By Ye_Yodeling_Ice_Maelstrom in forum Computer Science
    Replies: 1
    Last Post: November 16th, 2012, 01:12 AM
  2. Replies: 30
    Last Post: May 1st, 2012, 09:07 AM
  3. What is the simplest definition for time?
    By sreeramavarmaraja in forum Physics
    Replies: 138
    Last Post: February 29th, 2012, 03:11 PM
  4. Finding a good online Computer Science Program
    By jb in forum Computer Science
    Replies: 7
    Last Post: June 7th, 2009, 03:56 PM
  5. computer science program help?
    By krissyxdee in forum Computer Science
    Replies: 0
    Last Post: March 22nd, 2009, 05:44 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •