Difference between revisions of "CSC231 Homework 1 2017"

From dftwiki3
Jump to: navigation, search
(Problem #1)
(Your Assignment)
Line 85: Line 85:
 
<br />
 
<br />
 
; Question
 
; Question
: What is the output of this mystery program?  Please answer this question on Moodle.
+
: 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.
 
<br />
 
<br />
 
<br />
 
<br />

Revision as of 17:53, 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.