Lab 2. Linux
For the activities in this lab, first log in to your Linux as you did in Lab 1. Perform a git pull on your repository to make sure it is up to date.
This lab has the following goals:
- Gain experience navigating the Linux environment.
- Gain experience using a terminal-based text editor---
Vim. - Get acquainted with Assembly programing.
Part 1. Solve the Mystery
Use cd to navigate into your lab2 directory. Once you're in there, use the
ls command to list that directory's contents. Then use cd to go into the
clmystery directory. You'll notice a file named instructions! Read it
using the cat command.
Some shotcuts you may find useful:
Up arrow: repeat the previous command<tab>(or double<tab>): auto-complete filename or path<ctrl> + c: terminate the current running command
While following the instructions to solve this problem, please take notes to show your thought process, i.e., how you reach to the final conclusion. After you've solved the mystery, show the final answer and your note to your instructor and get checked off!
Part 2. Terminal-based Text Editor Training
The Linux command-line terminal, or shell, is an extremely powerful tool. In Linux, you control the machine solely through this text-based input.
One common task on the command line is text editing (analogous to using Notepad on Windows or TextEdit on Mac.) For simple text-editing tasks, one can use nano. However, it is very worthwhile to learn a more sophisticated editor such as vim or emacs. These editors come with a slightly steeper learning curve, but once a user is up to speed, their many useful functionalities can boost productivity. In this part of the lab, you'll get to know one of these text editors.
In this class, we will choose Vim as the text editor
Vim
vim should already work on your Linux install.
If you like, you can run the following command in the terminal to install some useful configurations, e.g., showing line numbers.
wget -O ~/.vimrc https://www.rose-hulman.edu/class/csse/csse132/vimrc
Read the Tutorial: Run vimtutor to open the official tutorial.
There are 7 lessons in total in this tutorial, but you only need to go through lesson 1 to lesson 6. When you are reading
the tutorial, write down the keyboard shortcuts for following operations on your instructor verification sheet:
- Flip to the next/previous page
- Go to a certain line with a line number
- Go to the end of the current line
- Insert text at the end of current line
- Copy (or cut) a line and paste it
- Select and copy (or cut) multiple characters and paste them
- Select and copy (or cut) multiple lines and paste them
- Search a word in the text
- Undo and redo (i.e., redo an undone action)
Tip: You may be used to hitting CTRL-z to undo. But on Linux,
CTRL-z is used to suspend the current process (leaving it running
in the background) and return to the shell. If this happens to you
while using vim, type fg at your terminal to bring vim back
to the foreground.
Handy Features
With the special vim configuration installed above (via the wget command), you can use the following handy features:
* Tab completion: while coding in vim, you can type part of a word and hit <tab> to auto-complete it.
* Comment/Uncomment lines: At any line, type gcc to comment/uncomment the current line. To comment/uncomment multiple lines, select the lines in visual mode and type gc.
Show your instructor
To check this item off from your instructor verification sheet, you will be tested to demo some of the operations mentioned above.
Part 3: Assembly Practice
- Go to the
writeAssemblyfolder underlab2. - Implement the functions in
problems.s(hint: to write the code, open the file in VIM withvi problems.s) Once you finish writing a function, you can type
maketo compile your code and (using the provided test functions in
test_asm.c) create an executabletest_asmthat can test your code. Run./test_asmto test.- Show the output to your instructor, once you pass all tests.
Finishing the Lab
- Scan and upload the signed instructor verification sheet to Gradescope.