ssh -Y your_user_name@your_machine_name.cs.swarthmore.eduSee the week 1 Mon/Tues lab for more information about remotely logging into CS lab machines.
Once remotely connected to cs, you can start other xterms on our system by:
$ xterm &Then create a week02 subdirectory in your weeklylab subdirectory and copy over some files (the ls and pwd commands just let you see where you are in the directory structure):
cd cs31/weeklylab pwd mkdir week02 ls cd week02 pwd cp ~newhall/public/cs31/week02/* . ls
We are going to try this out on a C program with different variable types:
int main () { int x, i; unsigned int y; unsigned char uch; float f; int array[10]; // an array (like Python list) of 10 int values char ch; char *s = "Hello There"; // a string in C x = y = ch = uch = f = 1; array[0] = x; // C for loop: for(i = 0; i < 10; i++) { array[i] = i*i; } }The C for loop:
for(init_stmt; loop_condition; count_expr) { loop body }is evaluated:
Let's compile and run the a.out file inside the gdb debugger:
$ gcc -g types.c $ gdb ./a.out (gdb) break main (gdb) run (gdb) break 20 # set a break point at line 20 (gdb) cont # continue execution until hit a breakpoint (gdb) print x (gdb) print y (gdb) print (x - 2) (gdb) print (y - 2) (gdb) next (gdb) print x (gdb) print/t x # print in binary (note: leading 0's are not printed (gdb) print/x x # print in hexidecimal (gdb) p/t x # p is shorthand for print in gdb (gdb) p/t 2 + (8*23) # you can print any arithmeitic expression (gdb) p 0x2a + 10 # 0x is the prefix for a hexidecimal literal (gdb) p 0b1010 + 10 # 0b is the prefix for a binary literal (gdb) p 0b1010 + 0b10 (gdb) p/t x # some bit-wise operators (gdb) p/t !x (gdb) p/t x & 0b10101010 (gdb) p/t x | 0b10101010 (gdb) p/t x ^ 0b10101010 (gdb) p/t x << 2 # bit shift (gdb) p x << 2 (gdb) p uch # operations on different C types (gdb) p/c uch (gdb) p uch+257 # this converts uch to an int, then adds to 257, the result is an int (gdb) p (char)(uch+257) # re-cast the result as a char (gdb) set x = 10 # can change the value of a program variable # the examine command is similar to print but takes a memory address # (or a variable location) as its argument (gdb) x &x # examine memory at the memory address of the variable x (gdb) x &y (gdb) x/s s # the name of a string or array is a synonym for its address (gdb) x/d s (gdb) x/d array (gdb) x/d &array[3] # the memory address of the 3rd bucket in array (gdb) quit
The Logisim web page has user documentation that will be very helpful for the next lab assignment. We are using version 2.7.
$ logisim # start new project $ logisim proj_file.circ # edit an existing projectWe will start with firstcircuit.circ
$ logisim firstcircuit.circNext, step through the Beginner's tutorial and try building the XOR circuit.