Recording ?
Questions about anything ?
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 :
! ~ & ^ | + << >>
... see for example wikipedia operators in CWe should work through two's complement integers for, say, n=4 bits.
... and we'll see where the conversation takes us.
Talk about the homework project euler problem ...
I'll let you discuss ...
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 https://cs.bennington.college/courses/fall2020/systems/labs/datalab_bennington/datalab-handout.tar # 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 Driverhdrs.pm driver.pl ishow.c README
bits.h btest.h dlc Driverlib.pm 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.
$ ./driver.py # ... 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?
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 :
int* a
and int *a
?<stdio.h>
and "stdio.h"
?main
special? Why is it int main
?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?
I've attached the ipad notes I during class.
I've posted my C code for the pythagorean.c assignment.
last modified | size | ||
blackboard_bits.pdf | Fri Oct 23 2020 04:03 pm | 305K |