Difference between revisions of "CSC231 Lab 1 2014"

From dftwiki3
Jump to: navigation, search
(Creating a program from scratch)
(Submit Your Solution to Moodle)
 
(22 intermediate revisions by the same user not shown)
Line 16: Line 16:
 
<br />
 
<br />
 
<tanbox>
 
<tanbox>
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 not be graded.  It is self-paced, but you should work with somebody else in [http://cs.smith.edu/~jfrankli/111s08/pairProgramming2000.pdf pair programming] mode.
+
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 9/11/14, 9:00 a.m'''. for it to be automatically evaluated and graded.
 
</tanbox>
 
</tanbox>
  
Line 23: Line 23:
  
  
 +
=Work Due=
 +
<br />
 +
* Solution for Program 1, submitted on Moodle
 +
* Solution for Program 2, submitted on Moodle
 +
* Due date: 9/11/14, 9:00 a.m.
 +
<br />
 +
 +
=Computer Accounts=
 +
<br />
 +
* 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 [http://cs.smith.edu/dftwiki/index.php/Policy policy for the acceptable use of your new account]
 +
*# sign the piece of paper given to you
 +
*# return it to me
 +
<br />
 +
=SSH to Beowulf2=
 +
<br />
 +
* To connect to the new server for CS classes:
 +
 +
  ssh -Y 231a-'''xx'''@beowulf2.csc.smith.edu
 +
 +
:(replace '''xx''' by your new 2-letter Id)
 +
<br />
 
=Creating a program from scratch=
 
=Creating a program from scratch=
 
+
<br />
 
* Find the skeleton program on the class Web page (or open it [[CSC231_skeleton_program | here]])
 
* Find the skeleton program on the class Web page (or open it [[CSC231_skeleton_program | here]])
  
Line 31: Line 54:
 
* Create a file called '''skel.asm''' in your account, and save the [[CSC231 skel.asm | skeleton program]] in it.  At the Linux prompt, type:
 
* Create a file called '''skel.asm''' in your account, and save the [[CSC231 skel.asm | skeleton program]] in it.  At the Linux prompt, type:
  
   emacs skel.asm
+
   emacs -nw skel.asm
  
:Use the [[Emacs Quick Reference| Emacs Quick-Reference]] page for the most often used commands.
+
:If you do not remember emacs commands, use the [[Emacs Quick Reference| 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 [[CSC231_skel.asm | skel.asm]] and call it '''lab1.asm'''
 
* Make a copy of [[CSC231_skel.asm | skel.asm]] and call it '''lab1.asm'''
  
 
   cp skel.asm lab1.asm
 
   cp skel.asm lab1.asm
 +
 +
* Edit lab1.asm
 +
 +
  emacs -nw lab1.asm
  
 
* Add a string variable in your data section:
 
* Add a string variable in your data section:
Line 46: Line 75:
 
                
 
                
  
* Add some code to output the string in the ''text (code) section''
+
* Add some code to output the string in the ''text (code) section'', right below the '''_start:''' label
  
 
                
 
                
Line 110: Line 139:
 
|
 
|
  
== Mini Challenge of the Day ==
+
== Problem #1 ==
 
|}
 
|}
 
[[Image:QuestionMark3.jpg|right|120px]]
 
[[Image:QuestionMark3.jpg|right|120px]]
  
 +
* Copy the previous program in a new file, called '''lab1_1.asm'''
 +
 +
* Modify your new program so that its '''output''' looks like this:
 +
 +
*********************************
 +
*&nbsp;Welcome&nbsp;to&nbsp;CSC231&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
 +
*&nbsp;Home&nbsp;of&nbsp;the&nbsp;Assembly&nbsp;Language&nbsp;*
 +
*********************************
 +
             
 +
 +
The lines of stars contain 33 *-characters. Each line is thus 34-character long (to account for the line-feed character).
  
* Modify your program so that its output looks like this:
+
* Assemble and link your program.  Make sure it displays the correct output.
  
                    *********************************
+
===Version 2===
                    * Welcome to CSC231            *
+
 
                    * Home of the Assembly Language *
+
* 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!
 +
 
 +
<br />
 +
===Submit Your Solution to Moodle===
 +
<br />
 +
* Follow the steps illustrated in this [[Submitting programs for automatic testing on Moodle| page]] to submit your program to Moodle.
 +
<br />
 +
<br />
 +
{| style="width:100%; background:silver"
 +
|-
 +
|
 +
 
 +
== Problem #2 ==
 +
|}
 +
[[Image:QuestionMark4.jpg|right|120px]]
  
             
 
  
The lines of stars contain 33 *-characters. Each line is thus 34-character long (to account for the line-feed character). Can you find a solution where the number of characters in your data section is not 4 x 34 = 136 characters, but 3 x 34 = 102, instead?
+
* Write another program that will print out this series of strings on the screen:
  
Test it out!
+
*
 +
**
 +
***
 +
****
 +
*****
  
==Submit your Solution (optional)==
+
* 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
  
Enter your name or names in the header of the program, and at the Linux prompt, type:
 
  
    rsubmit lab1 lab1.asm
+
<br />
 +
===Submit Your Solution to Moodle===
 +
<br />
 +
* Follow the steps illustrated in this [[Submitting programs for automatic testing on Moodle| 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. 
 +
<br />
 +
<br />
  
 
=Troubleshooting=
 
=Troubleshooting=

Latest revision as of 05:57, 4 September 2014

<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" /> --D. Thiebaut 19:55, 7 September 2010 (UTC)





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 9/11/14, 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: 9/11/14, 9:00 a.m.


Computer Accounts



SSH to Beowulf2


  • To connect to the new server for CS classes:
 ssh -Y 231a-xx@beowulf2.csc.smith.edu

(replace xx by your new 2-letter Id)


Creating a program from scratch


  • Find the skeleton program on the class Web page (or open it here)
  • Login to beowulf 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 -F stabs 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

QuestionMark3.jpg
  • 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

QuestionMark4.jpg


  • 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 Beowulf the first time, and if you are using a Mac, you get a message of this form:

ssh 231a-xx@beowulf.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 beowulf.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 beowulf. 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