Difference between revisions of "CSC231 Homework 3 Fall 2012"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <tanbox> This homework can be done in pair. It is due at 11:59 p.m. + 1 min on 9/26/12 (which might be Mountain Day...) </tanbox> =Problem #1= What is left in e...")
 
(Problem #1)
Line 9: Line 9:
 
=Problem #1=
 
=Problem #1=
  
What is left in eax, ebx, ecx, and edx after the following instructions have executed:
+
What is left in eax, ebx, ecx, and edx after the following instructions have executed.  Express your answer in hexadecimal.
  
 
<code><pre>
 
<code><pre>
Line 24: Line 24:
 
mov cx, 0
 
mov cx, 0
  
 +
;;; show what is in eax, ebx, ecx, and edx now.
 +
</pre></code>
 +
 +
=Problem #2=
 +
 +
Starting with the program listed below, complement it so that it moves the string '''msg1''' into '''msg2''' and displays all three strings on the screen.
 +
 +
<br />
 +
<source lang = "asm">
 +
section .data
 +
msg1        db            "CSC231 Assembly", 10, 10
 +
msg1Len  equ            $-msg1
 +
msg2        db            "................", 10
 +
msg2Len  equ            $-msg2
 +
msg3        db            "Fall 2012", 10, 10
 +
msg3Len  equ            $-msg3
 +
 +
 +
section .text
 +
global _start
 +
_start:
 +
;;; print msg1
 +
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
 +
 +
;;; print msg2
 +
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
 +
 +
;;; print msg3
 +
mov eax, 4 ; write
 +
mov ebx, 1 ; stdout
 +
mov ecx, msg3 ; address of message to print
 +
mov edx, msg3Len ; # of chars to print
 +
int 0x80
 +
 +
;;; exit
 +
mov ebx, 0
 +
mov eax, 1
 +
int 0x80
 +
 +
</source>
 +
<br />
 +
The original program outputs:
 +
<code><pre>
 +
CSC231 Assembly
 +
 +
................
 +
Fall 2012
 +
</pre></code>
 +
 +
Your assignment is to add a series of instructions before the first section that prints msg1 that will copy msg1 into msg2, ''as efficiently as possible, and without using loops'', so that the program will print:
 +
 +
<code><pre>
 +
CSC231 Assembly
 +
 +
CSC231 Assembly
 +
 +
Fall 2012
 
</pre></code>
 
</pre></code>
  

Revision as of 12:58, 19 September 2012

--D. Thiebaut 13:51, 19 September 2012 (EDT)


This homework can be done in pair. It is due at 11:59 p.m. + 1 min on 9/26/12 (which might be Mountain Day...)


Problem #1

What is left in eax, ebx, ecx, and edx after the following instructions have executed. Express your answer in hexadecimal.

mov eax, 0x0
mov ebx, 0x12345678
mov ecx, 0x87654321
mov edx, 0xffffffff

mov al, bl
mov ah, ch
mov dl, dh
mov dh, bl
mov bx, cx
mov cx, 0

;;; show what is in eax, ebx, ecx, and edx now.

Problem #2

Starting with the program listed below, complement it so that it moves the string msg1 into msg2 and displays all three strings on the screen.


		section	.data
msg1        db             "CSC231 Assembly", 10, 10
msg1Len   equ            $-msg1
msg2        db             "................", 10
msg2Len   equ            $-msg2
msg3        db             "Fall 2012", 10, 10
msg3Len   equ            $-msg3

	
		section	.text
		global	_start
_start:	
;;; print msg1
		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

;;; print msg2
		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

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

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


The original program outputs:

CSC231 Assembly

................
Fall 2012

Your assignment is to add a series of instructions before the first section that prints msg1 that will copy msg1 into msg2, as efficiently as possible, and without using loops, so that the program will print:

CSC231 Assembly

CSC231 Assembly

Fall 2012

Problem #2