Week 1.b CS3650 01/10 2024 https://naizhengtan.github.io/24spring/ 1. Bits, bytes, and ints 2. (continued) Mechanics and admin 3. Crash course of computer organization ------------------------ Recap -- course: basics of computer organization + OS -- goals & non-goals -- basics 1. bits, bytes, and ints * bit = binary digit, 0 or 1 Q: How many bit patterns can a group of 2 bits have? [Answer: 2^2 = 4] Q: How many bit patterns can a group of 3 bits have? [Answer: 2^3 = 8] Q: How many bit patterns does a group of n bits have? [Answer: 2^n] * Digression: any self-respecting CS person must memorize powers of 2 2^1 = 2 2^2 = 4 2^3 = 8 2^4 = 16 2^5 = 32 2^6 = 64 2^8 = 128 2^9 = 256 2^10 = 1024 [fun fact: programmer's day -- the 256th of the year (09/12 or 09/13) -- 10/24 ] * Q: why bit has only two values? does it work for a machine with bits representing three values? [Answer: yes! there are ternary computers see: https://en.wikipedia.org/wiki/Ternary_computer Aside, ternary machines are "optimal" in some sense. It provides "optimal coding of numbers". ] * byte = 8 bits - bit is too tiny - The term byte is coined by Werner Buchholz (IBM). - Q: a bit can represent two numbers, 0 and 1. How many numbers can be represent by a byte? [Answer: 2^8 = 256] * int - for *unsigned integer*, a byte can represent: [0, 255] -- "unsigned" means "non-negative" - for *signed integer*, people use the most significant bit to represent the sign -- an analogy: -1 vs. +1 -- for a byte, 00000000 = 0 ... 01111111 = 127 --- 10000000 = V1? ... 11111111 = V2? -- Q: V1 and V2, which is smaller? What do you think? Also, what're V1 and V2? [Answer: for today, V1=-128, V2=-1 this is called "two's complement". ] * capacity metric: KB--PB 2^10 = 1024 ~= 10^3 (Kilo, KB) 2^20 ~= 10^(3*2) = 10^6 (Mega, MB) 2^30 ~= 10^(3*3) = 10^9 (Giga, GB) 2^40 ~= 10^(3*4) = 10^12 (Tera, TB) 2^50 ~= 10^(3*5) = 10^15 (Peta, PB) next are EB, then ZB, then YB * memory (DRAM) vs. disk/SSD size - Q: if you buy a disk/SSD with 1TB, how many bytes you will get? [Answer: 10^12 bytes < 2^40 bytes] - Q: if you buy a memory with 16GB, how many bytes you will get? [Answer: 16 * 2^30 bytes] 2. (continued) Mechanics and admin [from last time] c. labs: --key piece of the course --"Start early" "When is early?" "Earlier than you think" --Regardless, you need to allocate time. --we expect you think through, then ask --"Here is my code. It doesn't work. Please debug." won't work. --If you get a reply from a TA, and then send email 20 minutes later asking a closely related question, that’s probably not great too. -- late labs: 120hr slack hours -- penalty: -1% per late hour and -50% max -- apply slack hours to whichever lab you like. -- for example, you have 10 slack hours left, * lab2, 60hr late * lab3, 10hr late What're you going to do? d. lectures --attending: no roll call, but...will randomly pick students to answer questions -- get -1 (out of 100) in your final grade -- max -1 for each class e. integrity policies: --Here are some questions: Looking at a classmate's solution and then coding it by yourself afterward Showing your code to a classmate who has questions Modifying code that you find on StackOverflow Modifying code for a similar assignment that you find on GitHub The correct answer: ALL of these are ruled out by the policy. --Please see the policy page, and let me say here: --The collaboration and academic integrity policy is real --please make sure that you've really thought through your question on your own before you ask for help --Exams will have questions about labs; and "If there are inexplicable discrepancies between exam and lab performance, we will overweight the exam, and possibly interview you." (see the policy page) 3. Crash course of computer organization [draw a mini computer: memory, CPU, disk ] +--------------+ | CPU | +-------------------+ | +- ALUs | <--fetch-- | memory | | +- registers | | +- array of bytes | +--------------+ +-------------------+ \ ^ commands / \ data v / +--------------------+ | disk | | +- array of blocks | +--------------------+ * how a CPU works? - ALUs - registers for example, ip tells CPU where's the next instruction * how memory works? - a sequence of bytes * how disk works? - a sequence of blocks * how a program (helloworld) runs? * a file on disk * load to memory; have code and data segmentes * the code segment is a sequence of instructions * instructions are like "add 1 and 1", "multiply x and y" * CPU needs to run the instructions * how does CPU know which instructions to run? CPU has a register %ip * one way to see how a CPU works: while (true) { instruction <- fetch from memory pointed by %ip execute instruction %ip <- address of next instruction } * Demo: executing helloworld [use egos-NU as an example] - a programmer writes helloworld.c - compile helloworld.c to assembly, then to object, then to executable binary (called ELF, executable and linkable format) - run the program [acknowledgement: Jinyang Li and Tiger Wang]