Monday, February 14, 2011

lecture #5

Reed book, read chapter 1.

First quiz, in lab, next wednesday. covers material up to the end of today.

HW#1:
1) Convert these numbers to binary:
7
14
103

2) Convert these binary numbers to decimal:
11001
110
11
1101

3) Convert those numbers in part 2 to octal.
4) Convert those numbers in part 2 to hexadecimal.

end user software. e.g Microsoft Word

programming software. Integrated development environment for creating end-user software. compiler. things used by programmers to create software.

system software. your operating system. Windows XP. lets you launch programs, manage files. used by other programs.

How do you program a computer?
Computer speaks machine language. 01110101 1111
Do humans speak machine language?

assembly language
mov ax, 4
mov bx, 5
add ax, bx

mov = 1001
add = 1111
ax = 1000
bx = 0001

1001 1000 0100
1001 0001 0101
1111 1000 0001

this process of translating TO / FROM machine language very simple.

http://en.wikipedia.org/wiki/Assembly_language
low-level programming languag

assembler

http://en.wikipedia.org/wiki/Low-level_programming_language

first generation, second generation languages

High-level programming language
http://en.wikipedia.org/wiki/High-level_programming_language

Some C++ code to calculate costs:
http://www.functionx.com/cpp/examples/ifelse1.htm
#include <iostream>
using namespace std;

void main()
{
    unsigned int Miles;
    const double LessThan100 = 0.25;
    const double MoreThan100 = 0.15;
    double PriceLessThan100, PriceMoreThan100, TotalPrice;

    cout << "Enter the number of miles: ";
    cin >> Miles;

    if(Miles <= 100)
    {
        PriceLessThan100 = Miles * LessThan100;
        PriceMoreThan100 = 0;
    }
    else
    {
        PriceLessThan100 = 100 * LessThan100;
        PriceMoreThan100 = (Miles - 100) * MoreThan100;
    }

    TotalPrice = PriceLessThan100 + PriceMoreThan100;

    cout << "\nTotal Price = $" << TotalPrice << "\n\n";
}

compiler or an interpreter
compiler does the translation up front.
takes in C++ sources code. outputs machine language.

interpreter.
does not translate front.
translates as executing, as carrying out the instructions.

C++ compiled.
Javascript interpreted.

First quiz only up to this point.
Quiz does not include book material.

8 comments:

  1. Hi Prof.,

    What and how are you going to ask about assembly language in the exam? Do we have to memorize what mov, add, ax and bx mean?

    P.S. I dont have your email.

    Cindy Leung

    ReplyDelete
  2. you certainly won't have to reproduce it. you might want to be able to recognize it when you see it, at this point. (by the way, mov means "move", add means "add", and ax and bx are just spots in the extremely short term memory.)

    if you take the name by which I sign this comment and append @gmail.com to it, you'll have my email address. I don't want to put it up in plaintext because of spambots.

    ReplyDelete
  3. that means i have to recognize them as numbers?

    because you said:
    mov = 1001
    add = 1111
    ax = 1000
    bx = 0001

    or we just need to know the meanings of them? (mov = move, etc.)

    ReplyDelete
  4. no, not as numbers, just the meanings of them. indeed, as i mentioned in class, i was just making up those numbers for the sake of illustration.

    ReplyDelete
  5. when converting binary to decimal do i start from the right right or left when inputting the numbers. because in the video you put up the numbers were already there. so for example is the answer to 11001= 25, or is it 200??

    ReplyDelete
  6. also is 11001 converted to hexadecimal 19? cuz i read online to divide the number into sects of 4 so it would be 1001 which converts to 9 in decimal. and 0001 converts to 1 indecimal. and then you just add em up to 19? i read that somewhere and it worked for a larger number but i have no way of checking... if not canu write the formula because its the only thing confusing me at this point...

    ReplyDelete
  7. "also is 11001 converted to hexadecimal 19? cuz i read online to divide the number into sects of 4 so it would be 1001 which converts to 9 in decimal. and 0001 converts to 1 indecimal. and then you just add em up to 19?"
    yes.

    "i read that somewhere and it worked for a larger number but i have no way of checking"
    you can type:
    0b11001 in hexadecimal
    in Google and it will give you the answer.

    all the best,
    josh

    ReplyDelete