Difference between revisions of "CSC231 Lab 1 2014"

From dftwiki3
Jump to: navigation, search
(Mini Challenge of the Day)
Line 13: Line 13:
 
   
 
   
 
__TOC__
 
__TOC__
 +
<br />
 +
<br />
 +
<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.
 +
</tanbox>
  
This lab is the first lab of this course.  It will get you started with the process of assembling, linking, and running assembly programs for the Intel processor.
+
<br />
 +
<br />
  
  

Revision as of 08:26, 10 September 2012

<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 not be graded. It is self-paced, but you should work with somebody else in pair programming mode.




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 skel.asm
Use the Emacs Quick-Reference page for the most often used commands.
  • Make a copy of skel.asm and call it lab1.asm
  cp skel.asm 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


             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.


Mini Challenge of the Day

QuestionMark3.jpg


  • Modify your 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). 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?

Test it out!

Submit your Solution (optional)

At the Linux prompt, type:

   rsubmit lab1 lab1.asm

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