Difference between revisions of "CSC231 Lab 1 2017"
(→Creating a program from scratch) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 43: | Line 43: | ||
* To connect to the new server for CS classes: | * To connect to the new server for CS classes: | ||
− | ssh -Y | + | ssh -Y cs231a-'''xx'''@aurora.smith.edu |
:(replace '''xx''' by your new 2-letter Id) | :(replace '''xx''' by your new 2-letter Id) | ||
<br /> | <br /> | ||
+ | =Setup the Bash shell= | ||
+ | <br /> | ||
+ | You will only have to do this once this semester. At the Linux prompt, type | ||
+ | |||
+ | setup231.sh | ||
+ | |||
+ | and '''logout'''. Then '''log back in'''. You should be able to see a different prompt, indicating that your default shell is now '''bash'''. | ||
+ | <br /> | ||
+ | |||
=Playing with the Emacs editor= | =Playing with the Emacs editor= | ||
<br /> | <br /> | ||
Line 53: | Line 62: | ||
=Creating a program from scratch= | =Creating a program from scratch= | ||
<br /> | <br /> | ||
− | * | + | * In this section, you will create a [[CSC231_skeleton_program | skeleton program]] that you will then edit and create a new assembly program. |
− | * | + | * If not logged in yet, login to '''aurora''' with your new cs231a-xx account (see the [[CSC231_Lab_1#Troubleshooting |'''Troubleshooting''']] section at bottom of this page in case of trouble). |
− | * | + | * Get a copy of the '''skel.asm''' from your instructor's account with the '''getcopy''' command. It will be saved in your current directory: |
− | + | getcopy skel.asm | |
− | |||
− | |||
− | |||
* Make a copy of [[CSC231_skel.asm | skel.asm]] and call it '''lab1.asm''' | * Make a copy of [[CSC231_skel.asm | skel.asm]] and call it '''lab1.asm''' | ||
Line 92: | Line 98: | ||
int 0x80 | int 0x80 | ||
</source> | </source> | ||
− | <br /> | + | <br /> |
− | |||
− | |||
* Save your file by typing '''Control-X''', '''Control-C''' while in emacs. | * Save your file by typing '''Control-X''', '''Control-C''' while in emacs. | ||
Line 158: | Line 162: | ||
| | | | ||
− | == | + | == Exercise #1 == |
|} | |} | ||
[[Image:QuestionMark3.jpg|right|120px]] | [[Image:QuestionMark3.jpg|right|120px]] | ||
Line 194: | Line 198: | ||
| | | | ||
− | == | + | == Exercise #2 == |
|} | |} | ||
[[Image:QuestionMark4.jpg|right|120px]] | [[Image:QuestionMark4.jpg|right|120px]] | ||
Line 208: | Line 212: | ||
* Assemble, link, and run your program. Make sure it works before continuing. | * Assemble, link, and run your program. Make sure it works before continuing. | ||
− | * Count the number of *-characters | + | * Count the number of *-characters in your string(s). Is it 15? If so, good; that's a good solution. |
+ | * Here is a <font color="magenta">'''challenge'''</font> for you: could you rewrite your program so that it contains only a string of 5 *-characters? Try finding a solution. You will have to change the code section to make this work. | ||
Line 226: | Line 231: | ||
It is possible that if you are using '''ssh''' to connect to Aurora the first time, and if you are using a Mac, you get a message of this form: | It is possible that if you are using '''ssh''' to connect to Aurora the first time, and if you are using a Mac, you get a message of this form: | ||
− | ssh | + | ssh cs231a-xx@aurora.smith.edu |
================================================== | ================================================== | ||
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! | WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! | ||
Line 238: | Line 243: | ||
Add correct host key in /Users/alex/.ssh/known_hosts to get rid of this message. | Add correct host key in /Users/alex/.ssh/known_hosts to get rid of this message. | ||
Offending key in /Users/xxxxx/.ssh/known_hosts:1 | Offending key in /Users/xxxxx/.ssh/known_hosts:1 | ||
− | RSA host key for aurora | + | RSA host key for aurora.smith.edu has changed and you have requested strict checking. |
Host key verification failed. | Host key verification failed. | ||
Latest revision as of 09:10, 13 September 2017
--D. Thiebaut (talk) 10:37, 30 January 2017 (EST)
<meta name="keywords" content="computer science, assembly language, pentium, exercise, machine language, intel" /> <meta name="description" content="Dominique Thiebaut's Web Page" /> <meta name="title" content="Dominique Thiebaut -- Computer Science" /> <meta name="abstract" content="Dominique Thiebaut's Computer Science Web pages" /> <meta name="author" content="thiebaut at cs.smith.edu" /> <meta name="distribution" content="Global" /> <meta name="revisit-after" content="10 days" /> <meta name="copyright" content="(c) D. Thiebaut 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,2008" /> <meta name="robots" content="FOLLOW,INDEX" />
Contents
This lab is the first lab of this course and its purpose is to bring everybody up to speed with the assembly process, and have a tiny bit of fun at the same time. It will be graded. You have to submit it to Moodle before XXXX, 9:00 a.m. for it to be automatically evaluated and graded.
Computer Accounts
- You should get a new computer account for CSC231. You will need to
- record your new account and password in a safe place,
- read the policy for the acceptable use of your new account
- sign the piece of paper given to you
- return it to me
SSH to Aurora
- To connect to the new server for CS classes:
ssh -Y cs231a-xx@aurora.smith.edu
- (replace xx by your new 2-letter Id)
Setup the Bash shell
You will only have to do this once this semester. At the Linux prompt, type
setup231.sh
and logout. Then log back in. You should be able to see a different prompt, indicating that your default shell is now bash.
Playing with the Emacs editor
- Go to this page and follow the steps that will lead you to edit a messed up text file into the original short story that it is. You will use 90% of the Emacs commands you need to know.
Creating a program from scratch
- In this section, you will create a skeleton program that you will then edit and create a new assembly program.
- If not logged in yet, login to aurora with your new cs231a-xx account (see the Troubleshooting section at bottom of this page in case of trouble).
- Get a copy of the skel.asm from your instructor's account with the getcopy command. It will be saved in your current directory:
getcopy skel.asm
- Make a copy of skel.asm and call it lab1.asm
cp skel.asm lab1.asm
- Edit lab1.asm
emacs -nw lab1.asm
- Add a string variable in your data section:
msg db "Welcome to csc231", 10 MSGLEN equ $-msg
- Add some code to output the string in the text (code) section, right below the _start: label
mov eax, 4 mov ebx, 1 mov ecx, msg ; use the same name as the string in the data section mov edx, MSGLEN ; # of chars in string int 0x80
- Save your file by typing Control-X, Control-C while in emacs.
Assembly and Linking steps
- You should be back at the Linux prompt. Assemble your program
nasm -f elf lab1.asm
- Fix any errors you may get by starting emacs again and figuring out where the error is.
- Link your program
ld -melf_i386 -o lab1 lab1.o
- You shouldn't get any errors at this stage.
Execution
- Run your program:
./lab1
- It should run and display the string.
Playing around with the program
- Modify the msg string to make it look like this:
msg db 10, 10, "Welcome", 10, "to", 10, "csc231", 10, 10 MSGLEN equ $-msg
- Reassemble, link and run the new version of your program.
- Something different. Modify your program once more, as shown below:
msg db 10, 10 db "Welcome", 10 db "to", 10, "csc231" db 10 db 10 MSGLEN equ $-msg
- Reassemble, link and run the new version of your program.
Exercise #1 |
- Copy the previous program in a new file, called lab1_1.asm
- Modify your new program so that its output looks like this:
********************************* * Welcome to CSC231 * * Home of the Assembly Language * *********************************
The lines of stars contain 33 *-characters. Each line is thus 34-character long (to account for the line-feed character).
- Assemble and link your program. Make sure it displays the correct output.
Version 2
- Can you alter your program so that the number of characters in your data section is not 4 x 34 = 136 characters, but 3 x 34 = 102 characters, instead? The reason for such a question is that often assembly language will be used by programmers to trim programs, i.e. making them faster or shorter so that their performance can be increased, or their footprint in memory can be lowered.
- Test it out!
Exercise #2 |
- Write another program that will print out this series of strings on the screen:
* ** *** **** *****
- Assemble, link, and run your program. Make sure it works before continuing.
- Count the number of *-characters in your string(s). Is it 15? If so, good; that's a good solution.
- Here is a challenge for you: could you rewrite your program so that it contains only a string of 5 *-characters? Try finding a solution. You will have to change the code section to make this work.
Troubleshooting
It is possible that if you are using ssh to connect to Aurora the first time, and if you are using a Mac, you get a message of this form:
ssh cs231a-xx@aurora.smith.edu ================================================== WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! ================================================== IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is bf:db:14:e6:a4:e0:f3:3d:d8:87:35:66:a9:35:68:fb. Please contact your system administrator. Add correct host key in /Users/alex/.ssh/known_hosts to get rid of this message. Offending key in /Users/xxxxx/.ssh/known_hosts:1 RSA host key for aurora.smith.edu has changed and you have requested strict checking. Host key verification failed.
In this case, use the editor of your choice and edit the file ~/.ssh/known_hosts and remove the lines that contains the word aurora. Be careful, the lines are very long and wrap around to form blocks of 4 or 5 lines on your screen, so deleting one line will require a big block to disappear. Bold text