*Miscue's Computer Science Thread*

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Miscue
    Super Moderator

    • Oct 2000
    • 7105

    #1

    *Miscue's Computer Science Thread*

    I was talking to Zvanut in #automags and he was curious about learning how to program. But he asked an interesting question... "How do I learn it right?" You can always pick up a book on some PL (Programming Language) and start using it... but the funny thing is that you really won't understand how the PL itself, and computers in general, actually works just by using it. There's lots and lots of background info.

    I figure most of you could care less, but hey, this is the Friendly Corner so I can say what I want, right? If this is boring to ya, I can easily quit. If there's continued interest... I'll periodically make additions. Oh, and I will avoid being overly technical... try to keep things simple...

    <B>What is Binary? </B>

    Everybody knows that computers use 1's and 0's. But what does that really mean? 1/0... on/off... sure. These 1's and 0's represent something that the computer can understand. What these 1's and 0's mean depend on the context in which they are used. A list of binary could represent some numerical value... maybe a letter... maybe a memory address where some information is stored... an instruction to add two numbers together. Could be anything.

    Example: 01101001 could mean the number 105 if it was intended to represent a number. It could also be the letter 'i' if it was meant to represent a character. There are particular rules you follow to represent particular things with binary... which I won't get into.

    Why do computers use binary (base 2)? Why can't they use numbers 1-10 (base 10)? This is largely to do with the way the electrical components work. The problem is that they can only <B>accurately</B> and <B>reliably</B> (calibration, interference, transistor behavior issues) tell the difference between two voltage states: low voltage, and high voltage. Low voltage is typically around 0 volts, high voltage around 5... depending. And, usually low voltage represents a 0, and high represents a 1. If some brilliant electrical engineer figured out how to tell the difference between 10 voltage states, then computers could work in the decimal number system like we do.

    What does it mean that my computer is a 32 bit system? Well, it kinda depends on what you're talking about... but for the most part it means that the largest values that the CPU can deal with in one shot is 32-bits (which is a pretty big number). So like... say you were adding two numbers together... if you deal with stuff that goes over 32 bits it won't work right. You can add arbitrarily large numbers beyond 32-bits if you have the memory for it, but the CPU cannot do it on it's own... you have to tell it how to by using combinations of its 32-bit instructions. (Basically you end up breaking the big number into chunks and deal with it a piece at a time)

    Why is this important? Well, once you start programming... it's good to know how the computer stores numbers/values/etc. and processes them. Like say you just started out with C++. A common question is "Why do I have to tell it what kind of stuff I'll be putting into my variables?"

    ie: How come I can't just skip the the 2nd line w/o the first?:

    int x, y, z;
    z = x + y;

    Well, when you tell the computer that x, y and z are integers (int)... it knows how much space in memory to set aside for them... and it knows that it's the kind of values that you can do arithmetic with. Going back to what I said before... remember how 01100110 could mean 105 or the letter 'i'? The computer doesn't know what it means unless you tell it what it is. This is why you have to tell the computer in your c++ programs what your variables represent.

    Questions? Comments? Praise? Middle-Fingers?

    This stuff is fun to me and off the top of my head so it's effortless typing it out, and I get bored a lot - especially at work... so if ya guys are interested in additions... I could...
  • vf-xx
    Henchmen Inc.
    • Nov 2001
    • 3311

    #2
    Ok, i'm tired and I didn't read the whole thread, but computer's use binary because the one's and zeros represent switch postions. That's all a computer is for, flipping switches really really fast. (I think)

    NE way, tis a hard subject, Hope you learn something.

    PS: Don't expect any more from me, I'm in ME not CS
    -- Feedback--

    Comment

    • deded
      so.fresh.and.so.clean!
      • Nov 2001
      • 371

      #3
      This is a great idea! I used to get all of my nerdy info @ linuxnewbie.org... but when Sensei retired, I slowly drifted away, and don't have a home nerd board anymore!

      If at first you don't succeed, skydiving is not for you.

      Comment

      • prikkaboo
        Registered User
        • Jul 2001
        • 65

        #4
        I think its a cool topic. You should do more posts like this hehe "miscue's computer class." It answers alot of questions for me so now i won't have to bother you so much on irc.

        Comment

        • udtseal
          Registered User
          • Sep 2001
          • 702

          #5
          AHHHHHHHHH!!!!!! *Footstep sound running away, door slams*


          I used to be a CS major...never again....curls on the floor weeping...

          Comment

          • Arman/XPM

            #6
            Good one Miscue!
            Give me some time, and I will be glad to contribute also.

            udtseal
            I understand where you are coming from -
            -Arman

            Comment

            • Failure
              I Love Techno
              • Nov 2001
              • 487

              #7
              Good read. You going to add more info? I'd like to learn.

              Comment

              • synreal
                code monkey
                • Oct 2001
                • 1051

                #8
                Next Week's Lesson: Assembly (It's not just for Breakfast Anymore)?


                AO Drops for sale

                Comment

                • cphilip
                  Former Moderator

                  • Jun 2026
                  • 16216

                  #9
                  You mean there is a "Science" to it? I turn mine on it works whats so hard about that?




                  AGD, where we are so good we can do it with only ONE tube!

                  cphilip.com

                  Comment

                  • Miscue
                    Super Moderator

                    • Oct 2000
                    • 7105

                    #10
                    Originally posted by synreal
                    Next Week's Lesson: Assembly (It's not just for Breakfast Anymore)?
                    Sure, why not?

                    <B>What is Assembly? Better yet, what is machine language?</B>

                    To understand assembly you have to understand the machine language of the CPU... they are one in the same. When you're writing in assembly (Low-Level Programming language)... your lines of code have a 1 to 1 correlation with a machine level instruction... unlike in a HLPL (High-Level Programming Language) like c++ where a single line of code has to be represented by numerous CPU instructions. A single line of assembly code can be represented by a single 32-bit (depending) binary value. But we of course do not program in binary anymore, although we could if we wanted... but that's kinda stupid. We have 'assemblers' so we never have to do this - programs that take stuff written in some human understandable form... directly into binary.

                    So what's a machine instruction?

                    The CPU has hardwired into it a set of operations that it can do... like: add, subtract, etc. Memory loading and storing operations. Instructions to compare numbers with, like if one number is greater than another. The CPU has built in memory called 'registers' that it uses for immediate storage. No information can be processed until it reaches a CPU register, which makes a register prime real-estate.

                    There are different classes of instructions. I'll give you an example of a 32-bit MIPS (RISC) I-format instruction (Don't worry what this means, it's unimportant)

                    *************
                    ---op----------rs--------rt--------address-------------------
                    |--6 bits--|--5 bits--|--5 bits --|----16 bits-----------------|

                    op = the basic operation of the instruction, traditionally called the opcode

                    rs = The first register source operand

                    rt = The second register source operand
                    **************

                    Let's say we had the assembly instruction (its meaning is unimportant):
                    <B>lw $t0,32($s3)</B>

                    I have no idea what the binary equivolent is, but lets say this is what is was:
                    <B>110010</b>01101<b>00010</b>1101101010111001</B>

                    The <B>lw</B> is an operation (op) and gets represented by the first 6-bits (<b>110010</B>), $t0 is the name of a register (rs) and gets represented by the next 5 bits (01101), $s3 is the second register (rt) being used (<B>00010</B>) and the 32 is what fills up the 16 bit address that's left over (1101101010111001).

                    With this you can kinda see how assembly really is a representation of the CPU's machine language itself.

                    Comment

                    • synreal
                      code monkey
                      • Oct 2001
                      • 1051

                      #11
                      slow day?


                      AO Drops for sale

                      Comment

                      • Miscue
                        Super Moderator

                        • Oct 2000
                        • 7105

                        #12
                        Absolutely, I'm stuck at work and am as bored as can be. This passes the time.

                        Comment

                        • synreal
                          code monkey
                          • Oct 2001
                          • 1051

                          #13
                          wanna code java servlets for me? c'mon you know you wanna

                          great way to kill time and braincells


                          AO Drops for sale

                          Comment

                          • Miscue
                            Super Moderator

                            • Oct 2000
                            • 7105

                            #14
                            Bah, I'm not that bored.

                            Comment

                            • Miscue
                              Super Moderator

                              • Oct 2000
                              • 7105

                              #15
                              <B>RISC and CISC</B>

                              I'm sure many of you have heard the terms RISC and CISC before. RISC stands for Reduced Instruction Set Computer, and CISC stands for Complex Instruction Set Computer. (Some people replace 'Computer' with Chip or other things... whatever, it doesn't really matter)

                              An example of a CISC chip would be the CPUs that PC's use... Intel and AMD - X86 based. A RISC chip would be like PowerPC, MIPS, and several others.

                              RISC and CISC are terms that describe a CPU's architecture. They basically are two different philosophies. The CISC philosophy is to throw in lots of 'powerful' instructions... a Swiss Army knife approach. RISC is the opposite, it wants to have as few instructions as it can. So even when chips get etched out onto silicon... a RISC chip physically takes up less space than a CISC chip for the most part.

                              So if a CISC chip has all the powerful instructions, how come a RISC chip can smoke it so bad? - as you may have heard. Why does a 300MHz RISC chip usually run faster than a 300MHz CISC? Or for that matter, why is it possible that any two chips regardless of architecture with the same clock speeds can actually process data faster?

                              There are many many things that determine the ultimate speed of your machine... and surprisingly - clock speed is one of the less important factors (although, yes... big-time clock speed can give you significant performance gains). I'll explain this better next time... but for now, I'll leave you with this loose analogy:

                              Imagine if you were racing a monster truck (CISC) against a Ferrari (RISC). What's going to happen depends on what you'll be racing them on. Let's say you are doing this on a race track... paved roads... or what have you. The Ferrari is going to win of course. What if it were an off-roading type course? The monster truck is going to win... especially since the owner of the Ferrari would kill you if you off-roaded it hard. What happens if 99% of the race will be on a race track, and 1% off-road? The Ferrari is going to haul on the race track, but it's going to take it really slow when it has to off-road... whereas this would be the monster truck's specialty. Bottom line is, despite the Ferrari having to take it really slow once it hits off-road... since 99% of the race is on a road, 99% of the time it's totally whooping the truck, and it's going to reach the finish line first - regardless.

                              Comment

                              Working...