The goal of the assignment is to implement a small C library (set of 5 functions) that enables getting and setting subfields in a bitvector. This is especially useful for applications like network packet processing. We will use it later in this class for understanding number representations and for converting LC3 assembly code into machine code. First read the Getting Started section below and then study the documentation for field.h in the Files tab to understand the details of the assignment.
This article may give you hints on how to do various bit operations.
Jack Applin found that the expression v - ((v<<1) & (1<<w))
sign-extends the value in v
which is w
bits wide.
NOTE: No loops are required in this assignments. Use of loops will be penalized.
Save Target As..
for each of the files.
field.h
(do not modify)field.c
(complete this file)testField.c
(do not modify)cd
command can be used for this.
gcc -g -Wall -c -std=c99 testField.c
gcc -g -Wall -c -std=c99 field.c
gcc -g testField.o field.o -o testField
testField
and read how to run the
the program.
testField bin 11259375
and you should see the output:
dec: 11259375 hex: 0xABCDEF bin: 0000-0000-1010-1011-1100-1101-1110-1111
You now have a functioning program. All the commands work,
however, only bin
will produce correct results at this point.
field.c
,
study the documentation in found in the files tab.
Plan what you need to do before writing code.
The best way to complete the code is to follow a write/compile/test sequence. Do not attempt to write everything at once. Rather choose one function and do the following steps.
field.c
using your
favorite editor.field.c
using
gcc -g -Wall -c -std=c99 field.c
. You will find
it convenient to work with both a terminal and editor window at
the same time.gcc -g testField.o field.o -o testField
.field.c
using the
checkin
program. Use the name FIELD. At the terminal
type:
~cs270/bin/checkin FIELD field.c
The above command submits your assignment. For a sanity check, type the following to get the file you checked in and make sure it compiles and runs properly with the provided files:
mkdir sanityCheck cd sanityCheck ~cs270/bin/peek FIELD field.c > field.c cp ../field.h ../testField.c . gcc -g -Wall -c testField.c gcc -g -Wall -c field.c gcc -g testField.o field.o -o testField // Do LOTS of test cases.Relax, you are done with your assignment!