Difference between revisions of "CSC231 Lab 1 2017"
(→Assembly and Linking steps) |
(→Creating a program from scratch) |
||
Line 46: | Line 46: | ||
:(replace '''xx''' by your new 2-letter Id) | :(replace '''xx''' by your new 2-letter Id) | ||
+ | <br /> | ||
+ | =Playing with the Emacs editor= | ||
+ | <br /> | ||
+ | * Go to [[Emacs_%26_Shell_Tutorial| 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. | ||
<br /> | <br /> | ||
=Creating a program from scratch= | =Creating a program from scratch= |
Revision as of 15:14, 5 December 2016
--D. Thiebaut (talk) 15:01, 5 December 2016 (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.
Work Due
- Solution for Program 1, submitted on Moodle
- Solution for Program 2, submitted on Moodle
- Due date: XXXXX
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 231a-xx@aurora.csc.smith.edu
- (replace xx by your new 2-letter Id)
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
- Find the skeleton program on the class Web page (or open it here)
- Login to aurora with your new 231a-xx account (see the Troubleshooting section at bottom of this page in case of trouble)
- Create a file called skel.asm in your account, and save the skeleton program in it. At the Linux prompt, type:
emacs -nw skel.asm
- If you do not remember emacs commands, use the Emacs Quick-Reference page for the most often used commands.
- Save it by typing Control-X followed by Control-C in emacs. You should be back at the Linux prompt.
- 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.
Problem #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!
Submit Your Solution to Moodle
- Follow the steps illustrated in this page to submit your program to Moodle.
Problem #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 that your program contains. 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 5 *-characters?l
Submit Your Solution to Moodle
- Follow the steps illustrated in this page to submit your program to Moodle. Select the Lab 1 Problem 2 link on the Moodle Page.
- The due date for both programs is 9/11/14 at 9:00 a.m.
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 231a-xx@aurora.csc.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.csc.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