Difference between revisions of "CSC231 Homework 1 2015"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <bluebox> This homework assignment will be released Wednesday afternoon, '''after the first class'''. </bluebox>")
 
Line 2: Line 2:
 
----
 
----
 
<bluebox>
 
<bluebox>
This homework assignment will be released Wednesday afternoon, '''after the first class'''.
+
This homework assignment is concurrent with Lecture 1, which took place on 9/9/15.  It is due Sunday night 9/20/15, at 11:55 p.m.
 
</bluebox>
 
</bluebox>
 +
<br />
 +
=Preparation=
 +
<br />
 +
==Part 1==
 +
* Login to your 231a-xx account on '''aurora.smith.edu'''.
 +
* Create the following assembly program, assemble it, link it, and run it (the commands are in the header):
 +
<br />
 +
::<source lang="asm">
 +
;;; ; hw1prep1.asm
 +
;;; ; D. Thiebaut
 +
;;; ;
 +
;;; ;
 +
;;; ; To assemble, link, and run:
 +
;;; ;    nasm -f elf  hw1prep1.asm
 +
;;; ;    ld -melf_i386 -o hw1prep1 hw1prep1.o
 +
;;; ;    ./hw1prep1
 +
;;; ;               
 +
 +
section .data
 +
msg1 db "The quick red fox jumped over the dog", 10
 +
msg1Len equ $-msg1
 +
 +
       
 +
 +
section .text
 +
global _start
 +
_start:
 +
 +
;;; print message
 +
mov eax, 4 ; write
 +
mov ebx, 1 ; stdout
 +
mov ecx, msg1 ; address of message to print
 +
mov edx, msg1Len ; # of chars to print
 +
int 0x80
 +
 +
;;; exit
 +
mov ebx, 0
 +
mov eax, 1
 +
int 0x80
 +
 +
</source>
 +
<br />
 +
* Observe the output.
 +
<br />
 +
==Part 2==
 +
<br />
 +
* Same question, but with a different program.  Make sure you study the code of both programs and see how they differ.  Then see how their output compare.
 +
<br />
 +
::<source lang="asm">
 +
;;; ; hw1prep2.asm
 +
;;; ; D. Thiebaut
 +
;;; ;
 +
;;; ;
 +
;;; ; To assemble, link, and run:
 +
;;; ;    nasm -f elf  hw1prep2.asm
 +
;;; ;    ld -melf_i386 -o hw1prep2 hw1prep2.o
 +
;;; ;    ./hw1prep2
 +
;;; ;               
 +
 +
section .data
 +
msg1 db "The quick red fox jumped"
 +
msg1Len equ $-msg1
 +
       
 +
msg2 db " over the dog", 10
 +
msg2Len equ $-msg2
 +
 +
       
 +
 +
section .text
 +
global _start
 +
_start:
 +
 +
;;; print message, part 1
 +
mov eax, 4 ; write
 +
mov ebx, 1 ; stdout
 +
mov ecx, msg1 ; address of message to print
 +
mov edx, msg1Len ; # of chars to print
 +
int 0x80            ; get Linux to print the message
 +
 +
;;; print message, part 2
 +
mov eax, 4 ; write
 +
mov ebx, 1 ; stdout
 +
mov ecx, msg2 ; address of message to print
 +
mov edx, msg2Len ; # of chars to print
 +
int 0x80            ; get Linux to print the message
 +
 +
;;; exit
 +
mov ebx, 0
 +
mov eax, 1
 +
int 0x80
 +
 +
 +
</source>
 +
<br />
 +
=Problem 1=
 +
<br />
 +
* Write an assembly language program called '''hw1a.asm''' that displays the following message.
 +
* Make the code section (''text section'') of your program contain as few instructions as possible.
 +
================
 +
================
 +
=  CSC231  FALL 2015  =
 +
================
 +
================
 +
 +
* You will be given on how to submit your program to Moodle in a few days.  Stay tuned...
 +
<br />
 +
=Problem 2=
 +
<br />
 +
* Same question as for Problem 1, but this time using as few characters in the data section, as possible.  You are not limited for the size of your code section any longer.  Just the size of the data section should be as small as possible.
 +
<br />
 +
Call your program '''hw1b.py'''.
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
 +
[[Category:CSC231]][[Category:Asm]]

Revision as of 10:49, 10 September 2015

--D. Thiebaut (talk) 16:08, 8 September 2015 (EDT)


This homework assignment is concurrent with Lecture 1, which took place on 9/9/15. It is due Sunday night 9/20/15, at 11:55 p.m.


Preparation


Part 1

  • Login to your 231a-xx account on aurora.smith.edu.
  • Create the following assembly program, assemble it, link it, and run it (the commands are in the header):


;;; ; hw1prep1.asm
;;; ; D. Thiebaut
;;; ;
;;; ;
;;; ; To assemble, link, and run:
;;; ;     nasm -f elf  hw1prep1.asm
;;; ;     ld -melf_i386 -o hw1prep1 hw1prep1.o
;;; ;     ./hw1prep1
;;; ;                

		section	.data
msg1		db	"The quick red fox jumped over the dog", 10
msg1Len	equ	$-msg1

        

		section	.text
		global	_start
_start:	

;;; print message
		mov	eax, 4		; write
		mov	ebx, 1		; stdout
		mov	ecx, msg1	; address of message to print
		mov	edx, msg1Len	; # of chars to print
		int 	0x80

;;; exit
		mov	ebx, 0
		mov	eax, 1
		int	0x80


  • Observe the output.


Part 2


  • Same question, but with a different program. Make sure you study the code of both programs and see how they differ. Then see how their output compare.


;;; ; hw1prep2.asm
;;; ; D. Thiebaut
;;; ;
;;; ;
;;; ; To assemble, link, and run:
;;; ;     nasm -f elf  hw1prep2.asm
;;; ;     ld -melf_i386 -o hw1prep2 hw1prep2.o
;;; ;     ./hw1prep2
;;; ;                

		section	.data
msg1		db	"The quick red fox jumped"
msg1Len	equ	$-msg1
        
msg2		db	" over the dog", 10
msg2Len	equ	$-msg2

        

		section	.text
		global	_start
_start:	

;;; print message, part 1
		mov	eax, 4		; write
		mov	ebx, 1		; stdout
		mov	ecx, msg1	; address of message to print
		mov	edx, msg1Len	; # of chars to print
		int 	0x80            ; get Linux to print the message

;;; print message, part 2
		mov	eax, 4		; write
		mov	ebx, 1		; stdout
		mov	ecx, msg2	; address of message to print
		mov	edx, msg2Len	; # of chars to print
		int 	0x80            ; get Linux to print the message

;;; exit
		mov	ebx, 0
		mov	eax, 1
		int	0x80


Problem 1


  • Write an assembly language program called hw1a.asm that displays the following message.
  • Make the code section (text section) of your program contain as few instructions as possible.
================
================
=  CSC231  FALL 2015  =
================
================

  • You will be given on how to submit your program to Moodle in a few days. Stay tuned...


Problem 2


  • Same question as for Problem 1, but this time using as few characters in the data section, as possible. You are not limited for the size of your code section any longer. Just the size of the data section should be as small as possible.


Call your program hw1b.py.