Fall 2020

Fri Oct 23 - bits and bytes

Recording ?

Questions about anything ?

jupyter demo

Do a demo on jupyter within the terminal of :

... just so we're all on the same page.

Check out the "background" section on my resources page if you would like practice with this shell or C stuff.


Possible topics to discuss :

We should work through two's complement integers for, say, n=4 bits.

... and we'll see where the conversation takes us.

pythagorean triples

Talk about the homework project euler problem ...

SEPC rep & alternate

I'll let you discuss ...

setting up the data lab

Show how to get going with the "data lab" , on jupyter.marlboro in a terminal.

This is due in a week; it's the culmination of the "playing with bits" material.

$ mkdir my_datalab
$ cd my_datalab
# download datalab-handout.tar to your laptop, upload in GUI to jupyter, or
$ wget   # wget = "web-get"
$ tar xf datalab-handout.tar               # tar = "tape-archive" ; Xtract File
$ ls
data_lab-handout  datalab-handout.tar
$ cd data_lab-handout
$ ls
bits.c  btest.c  decl.c  ishow.c   README
bits.h  btest.h  dlc   fshow.c    Makefile  tests.c
# Your job : edit bits.c so that it passes the tests.
$ make    $ compile everything here, using the Makefile rules.
$ ./btest       # ... shows you what's not working.
$ ./   # ... see if you're following the rules and gives your score
Correctness Results     Perf Results
Points  Rating  Errors  Points  Ops     Puzzle
0       1       1       0       0       bitXor
0       1       1       0       0       tmin
0       1       1       0       0       isTmax
0       2       1       0       0       negate
0       2       1       0       0       sign
0       2       1       0       0       getByte
0       3       1       0       0       isAsciiDigit
0       3       1       0       0       conditional
0       3       1       0       0       replaceByte
0       4       1       0       0       logicalNeg
0       4       1       0       0       bitParity
0       4       1       0       0       floatInt2Float
0       4       1       0       0       floatFloat2Int
Score = 0/60 [0/34 Corr + 0/26 Perf] (0 total operators)

Each of the puzzles is a function that you are to implement using only a subset of the C language. The rules vary for different problems. For most of them, you're restricted to a handful of operations; no loops, no "if" statements.

The point of all this is to see what you can do with only a few primitive operations.

These are "puzzles"; you can be a great programmer, understand the mysteries of the universe, and still may come up blank if you don't see the trick.

So don't spend all week on any one of them, eh?

Preview of coming attractions (if we get this far)

Starting in on the "machine code" material sometime next week might be a good idea ... there are a lot of pieces here (registers, memory layout, procedure call mechanism, opcodes, gdb, ...).

We're trying to learn to understand the basic workings of x86 64bit assembly code. We will not be trying to write it, but only to read it and appreciate some of the tricks.

 *  demo.c   
 *            It's a demonstration C program, eh?
#include <stdio.h>

void add_numbers(int a, int b, int* answer_ptr){
    // put them sum of a and b into the location given by the pointer.
    *answer_ptr = a + b;

int main(){
    int a, b, answer;   // declare (allocate memory for) signed 32bit integers.
    a = 10;             // code execution starts here.
    b = 20;
    add_numbers(a, b, &answer);                   // call a function
    printf(" %d + %d is %d \n", a, b, answer);    // call a system function

    return 0;

Quick quiz :

Here's how you can look inside what's going on.

(This is what we'll be doing in the bomblab, and try to learn about in the "machine code" lectures, slides, and chap 3 stuff.)

$ gcc -g --save-temps demo.c -o demo
# --save-temps => keep intermediate files (include, assembly, object)
# -g => "include debugging symbols in binary" (gdb cannot show C code without this)
$ gdb -tui demo   # the Gnu Debugger ; with "tui" , the "Text User Interface"
(gdb) start       # breakpoint at main; start program
(gdb) layout split  # what to see ... also (reg, src, asm)
(gdb) next        # go to next line of code (also 'step'; step into functions)
(gdb) x $rip      # examine register instruction pointer
(gdb) print a     # show value of variable a
(gdb) x/10x main+10   # examine/format address

Are we having fun yet?

after class additions

I've attached the ipad notes I during class.

I've posted my C code for the pythagorean.c assignment. /courses /fall2020 /systems /notes /oct23
last modified Fri October 23 2020 4:29 pm

attachments [paper clip]

  last modified size
TXT blackboard_bits.pdf Fri Oct 23 2020 04:03 pm 305K