Difference between revisions of "CSC231 Homework 1 2017"

From dftwiki3
Jump to: navigation, search
(Your Assignment)
(Problem #1)
Line 88: Line 88:
 
<br />
 
<br />
 
<br />
 
<br />
 +
=Problem 2: Programming Assignment=
 +
<br />
 +
You are given a program that is missing its code section.  Reconstruct the code section without modifying the data section, so that the output of the program is the following:
 +
<br />
 +
 +
cs231a-xx@aurora ~ $ ./hw1
 +
------------------------------------
 +
---------  CSC231 Assembly ---------
 +
------------------------------------
 +
cs231a-xx@aurora ~ $
 +
 +
 +
The incomplete source code of your program is given below:
 +
<br />
 +
::<source lang="asm">
 +
;;; hw1.asm
 +
;;; Your name
 +
;;; 
 +
;;; Add a description here
 +
;;;             
 +
;;; To assemble, link, and run: 
 +
;;;    nasm -f elf  hw1.asm
 +
;;;    ld -melf_i386 -o hw1 hw1.o
 +
;;;    ./hw1
 +
;;;     
 +
                section .data
 +
;;; you are not allowed to make any changes to the data section
 +
;;; below.
 +
msg            db      "  CSC231 Assembly "
 +
linefeed db 10
 +
dashline        db "------------------"
 +
lineLen equ $-dashline
 +
 +
 +
section .text
 +
                global  _start
 +
_start:
 +
;;; put your code below this point
 +
 +
;;; exit.  Do not add code below this line.                                                                                                               
 +
                mov    ebx, 0
 +
                mov    eax, 1
 +
                int    0x80
 +
</source>
 +
<br />
 +
Call your program '''hw1.asm''' and submit it to the programming section of Homework 1 on '''Moodle''' when you are done. 
 +
 +
Make sure the output of your program matches the output shown above, EXACTLY! 
 +
 +
Also, make sure you do not make any changes to the data section: this means no new string, no new labels, no new constants!  The autograder on Moodle will compare the data section of your program to the that of the solution program, and if they are different, you will not be given credit for your program, even if it outputs the correct strings!
 +
 +
 
<br />
 
<br />
 
<br />
 
<br />

Revision as of 18:03, 16 September 2017

--D. Thiebaut (talk) 17:42, 16 September 2017 (EDT)


Problem #1


Connect to your 231 account, and create this short assembly program, which you can call play1.asm:

;;; ; play1.asm
;;; ; program for Homework 1
;;; ; -------------------------------------------------------------------

;;;  ------------------------------------------------------------
;;;  data areas
;;;  ------------------------------------------------------------

	        section .data
msg1		db	"Homework 1", 10
msgLen		equ	$-msg1
	
;;;  ------------------------------------------------------------
;;;  code area
;;;  ------------------------------------------------------------

	        section .text
	        global  _start
_start:
		mov	eax, 4
		mov	ebx, 1
		mov	ecx, msg1
		mov	edx, msgLen
		int	0x80
;;;  exit()
	        mov     eax,1
	        mov     ebx,0
	        int     0x80	; final system call
  • Assemble, link and run the program. Verify that prints what it should be printing.
  • Generate a listing file, by using the -l (minus ell)
nasm -f elf -l play1.lst play1.asm

  • Edit the play1.lst file with emacs, and observe the relationship between the opcodes on the left and the corresponding instructions on the right.
  • Go back to the play1.asm and change the mov ecx, msg1 line to mov ecx, msg1+4, and change the mov edx, msgLen to mov edx, 5.
  • Assemble, link and run the program. Notice that the output is now different.
  • Generate a new listing file for the new play1.asm, and see how the opcodes of the two instructions you changed are now different. Make sure you understand how the opcodes relate to the instructions.


Your Assignment


Recreate the assembly program whose opcodes are shown below. I have removed the actual assembly part to leave only the opcodes.

     1                               
     2 00000000 486F6D65776F726B20-
     3 00000009 616E642043686F636F-
     4 00000012 6C61746520646F206E-
     5 0000001B 6F206D69782077656C-
     6 00000024 6C210A             
     7 
     8                                  	
     9 
    10 
    11 
    12                                  
    13 
    14 
    15 
    16 00000000 B804000000 
    17 00000005 BB01000000 
    18 0000000A B9[0D000000]
    19 0000000F BA09000000  
    20 00000014 CD80        
    21                      
    22 00000016 B804000000 
    23 0000001B BB01000000 
    24 00000020 B9[26000000]
    25 00000025 BA01000000  
    26 0000002A CD80        
    27                      
    28 0000002C B801000000  
    29 00000031 BB00000000  
    30 00000036 CD80


Question
What is the output of this mystery program? Please answer this question on Moodle. You do not need to submit the program you created. You only need to figure out what it prints.



Problem 2: Programming Assignment


You are given a program that is missing its code section. Reconstruct the code section without modifying the data section, so that the output of the program is the following:

cs231a-xx@aurora ~ $ ./hw1
------------------------------------
---------  CSC231 Assembly ---------
------------------------------------
cs231a-xx@aurora ~ $

The incomplete source code of your program is given below:

;;; hw1.asm
;;; Your name
;;;  
;;; Add a description here
;;;              
;;; To assemble, link, and run:  
;;;     nasm -f elf  hw1.asm
;;;     ld -melf_i386 -o hw1 hw1.o
;;;     ./hw1
;;;      
                section .data
;;; you are not allowed to make any changes to the data section
;;; below.
msg             db      "  CSC231 Assembly "
linefeed	db	10
dashline        db	"------------------"
lineLen		equ	$-dashline


		section .text
                global  _start
_start:
;;; put your code below this point

;;; exit.  Do not add code below this line.                                                                                                                 
                mov     ebx, 0
                mov     eax, 1
                int     0x80


Call your program hw1.asm and submit it to the programming section of Homework 1 on Moodle when you are done.

Make sure the output of your program matches the output shown above, EXACTLY!

Also, make sure you do not make any changes to the data section: this means no new string, no new labels, no new constants! The autograder on Moodle will compare the data section of your program to the that of the solution program, and if they are different, you will not be given credit for your program, even if it outputs the correct strings!