Skip to content

permutationlock/cs301_fall_2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS301 Fall 2021

Examples for the Fall 2021 CS301 class at UAF.

Requirements

All of the examples require an x86_64 machine running a Linux distro with gcc and nasm installed. However, the readme file in each folder contains a link to run the code on Netrun.

Vagrant VM

A Vagrant box avenbross/cs301 is available with Alpine Linux, all of these examples in this repo, and the packages required to run them.

To set up a VM this way you need to install VirtualBox and Vagrant and then run the following commands (in PowerShell on Windows, terminal on Linux/macOS):

vagrant init avenbross/cs301
vagrant up

To log in and start using the machine run:

ssh -p <port> vagrant@localhost

Enter the password "vagrant" when prompted. The port that the VM is running on is shown during the startup process (it will be something like 2200 or 2222). If you missed it, you can find it by running:

vagrant ssh-config

Once you are logged in to the server you need to know a little about Linux to get around. You can run the command ls to list the files and subdirectories of the current directory. You can use cd <directory name> to change directory. For example, when you first log in to the server running ls shows:

alpine:~$ ls
cs301_fall_2021

Lets move into the cs301_fall_2021 folder and see what is inside:

alpine:~$ cd cs301_fall_2021
alpine:~/cs301_fall_2021$ ls
README.md                             function_ptr
array_of_function_ptrs                function_ptr_in_struct
basic_struct_with_asm                 input_index_to_find_in_array
call_c_function_from_asm              linking_c_and_asm
construct_and_return_c_struct_in_asm  linking_cpp_and_asm
count_as_in_string

Next, move into the linking_c_and_asm example folder and open the main.c file with nano text editor:

alpine:~/cs301_fall_2021$ cd linking_c_and_asm
alpine:~/cs301_fall_2021/linking_c_and_asm$ nano main.c

Press CTRL-X to close the file (select no if asked to save changes). You can do the same thing to read foo.asm by executing nano foo.asm.

Having looked through the code, let's build and run the example:

alpine:~/cs301_fall_2021/linking_c_and_asm$ ./build.sh
alpine:~/cs301_fall_2021/linking_c_and_asm$ ./run
assembly returned: 1783

Great, we compiled a C and assembly project and it ran! This created an executable and a couple object files (.o files):

alpine:~/cs301_fall_2021/linking_c_and_asm$ ls
README.md  build.sh   clean.sh   foo.asm    foo.o      main.c     main.o     run

To get rid of these just run the clean script:

alpine:~/cs301_fall_2021/linking_c_and_asm$ ./clean.sh
alpine:~/cs301_fall_2021/linking_c_and_asm$ ls
README.md  build.sh   clean.sh   foo.asm    main.c

All the other examples can be built the same way (and you can copy a directory to start your own project). I would recommend not modifying the files in the cs301_fall_2021 directory if you are not experienced with git. I will be updating the repo and if you modify the files, pulling updates will cause merge conflicts. Instead make copies of examples by running cp -r directory_to_copy copy_name.

If you are curious as to how each example is built and cleaned you can open those script files with nano as well and simply read the list of commands they execute.

When you are done, you can close the ssh session by running the command exit. This will leave the machine running and you can ssh in later. If you instead want to shut the machine down (all your files will be saved, but you will have to re-run vagrant up to boot up the machine again) you can instead run sudo poweroff.

Some other things you might want to look at:

About

Examples for UAF CS301

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published