Difference between revisions of "CSC231 Homework 3 2015"

From dftwiki3
Jump to: navigation, search
(Problem #1)
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 15:56, 30 September 2015 (EDT)
 
----
 
 
--[[User:Thiebaut|D. Thiebaut]] 13:51, 19 September 2012 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] 13:51, 19 September 2012 (EDT)
 
----
 
----
Line 37: Line 35:
 
  edx: 0xXXXXXXXX
 
  edx: 0xXXXXXXXX
  
where XXXXXXXX are 8 hexadecimal digits, ALL IN UPPERCASE.   So, for example, if you think eax will contain the value 1234aaff after the instructions have executed, you would write:
+
Make sure the registers are in lowercase, and followed by a colon.  Make sure they are listed in alphabetical order.  In the lines above, XXXXXXXX are 8 hexadecimal digits representing the contents of a given register.  The digits must '''ALL BE IN UPPERCASE'''.
 +
 
 +
So, for example, if you think eax will contain the value 1234aaff after the instructions have executed, you would write:
  
 
  eax: 0x1234AAFF
 
  eax: 0x1234AAFF
Line 47: Line 47:
  
  
Submit your file in Section HW 3 PB 1 on Moodle.
+
Submit your file in Section HW 3 PB 1 on Moodle.  The grade for this exercise will not be visible.
  
 
=Problem #2=
 
=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.
+
What is left in eax, ebx, ecx, and edx after the following instructions have executed? 
  
<br />
+
<code><pre>
<source lang = "asm">
+
mov eax, 0x0
section .data
+
mov ebx, 0x1
msg1        db            "CSC231 Assembly", 10, 10
+
mov ecx, 0x2
msg1Len    equ            $-msg1
+
mov edx, 32
msg2        db            "................", 10
 
msg2Len    equ            $-msg2
 
msg3        db            "Fall 2012", 10, 10
 
msg3Len    equ            $-msg3
 
  
+
mov al, bl
section .text
+
mov ah, ch
global _start
+
mov dl, dh
_start:
+
mov dh, bl
;;; print msg1
+
mov bx, cx
mov eax, 4 ; write
+
mov ch, 0x0a
mov ebx, 1 ; stdout
+
mov cl, 0x0a+32
mov ecx, msg1 ; address of first message
 
mov edx, msg1Len ; # of chars to print
 
int 0x80
 
  
;;; print msg2
+
</pre></code>
mov eax, 4 ; write
+
<br />
mov ebx, 1 ; stdout
+
<br />
mov ecx, msg2 ; address of second message
+
Store your answers in a text file called '''hw3_2.txt''', which contains just 4 lines, with the following format:
mov edx, msg2Len ; # of chars to print
 
int 0x80
 
  
;;; print msg3
+
eax: 0xXXXXXXXX
mov eax, 4 ; write
+
ebx: 0xXXXXXXXX
mov ebx, 1 ; stdout
+
ecx: 0xXXXXXXXX
mov ecx, msg3 ; address of third message
+
edx: 0xXXXXXXXX
mov edx, msg3Len ; # of chars to print
 
int 0x80
 
  
;;; exit
+
Submit your file in Section HW 3 PB 2 on Moodle.  The grade for this problem will not be visible until past the due date.
mov ebx, 0
 
mov eax, 1
 
int 0x80
 
  
</source>
 
 
<br />
 
<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>
 
 
<br />
 
<br />
Note: you cannot modify the way msg1, msg2, or msg3 are defined in your program.  Typically you will copy-paste the program above into a new file called '''hw3b.asm''' and add a new series of instructions at the beginning of the code section.
 
 
 
=Problem #3=
 
=Problem #3=
  
 
+
Here's a program:
 
<br />
 
<br />
 
<source lang="asm">
 
<source lang="asm">
 +
; hw3_3.asm
 +
; Your name
 +
; displays a string, modify it, then print the modified version.
 +
;
 
section .data
 
section .data
msg1 db "I love chocolate", 10   
+
msg1 db 10, "I love chocolate", 10   
 
msg1Len equ $-msg1
 
msg1Len equ $-msg1
  
Line 135: Line 105:
 
mov edx, msg1Len
 
mov edx, msg1Len
 
int 0x80
 
int 0x80
 +
 
;;; put your code here
 
;;; put your code here
 +
  
 
;;; print modified string
 
;;; print modified string
Line 151: Line 123:
 
</source>
 
</source>
 
<br />
 
<br />
This program prints out:
+
* When this program is executed, it prints out:
 
<code><pre>
 
<code><pre>
 +
 
I love chocolate
 
I love chocolate
 +
 
I love chocolate
 
I love chocolate
  
 
</pre></code>
 
</pre></code>
  
Your assignment is to add a section of code between the two print sections that will modify msg1, so that when it is printed a second time, it will have changed. The output of your program should look exactly like this:
+
Your assignment is to add a section of code between the two print sections, and not change the data section in any way.  Your new code will modify the contents of the string msg1, in such a way that when the second print section is executed, it will print a new string, shown below.
  
 
<br />
 
<br />
 
<code><pre>
 
<code><pre>
 +
 
I love chocolate
 
I love chocolate
 +
 
J'aime chocolat!
 
J'aime chocolat!
  
Line 168: Line 144:
  
 
<br />
 
<br />
Store your program in a file called '''hw3c.asm''' and submit it as follows:
+
In other word your new program should start with "I love chocolate" in msg1, print it, then modify msg1, print it again, and this time the message that shows up on the screen is "J'aime chocolat!".
 +
 
 +
Reminder, you cannot add any new variables to your program.
 +
 
 +
Store your program in a file called '''hw3_3.asm''' and submit it in the HW 3 PB 3 section on Moodle.
 +
 
 +
<tanbox>
 +
Note that the message starts with a 10, which is a linefeed.  Make sure that when you modify the string, you do not change this character, as Moodle expects it to be the first character output by your program.
 +
</tanbox>
 +
 
 +
<br />
 +
 
 +
=Problem #4=
 +
<br />
 +
Assume that we have this simple code section:
 +
<br />
 +
<source lang="asm">
 +
x      dw    0, 1, 0xFF22
  
    rsubmit hw3 hw3c.asm
+
        mov  eax, dword[x]
 +
        mov  ax, 0xFFEE
 +
        mov  dword[x], eax
  
 +
</source>
 +
<br />
 +
* What is the content of the memory after the 3rd mov instruction has executed?
 +
:::a) FF EE 01 00 22 FF
 +
:::b) EE FF 01 00 22 FF
 +
:::c) EE FF 01 22 FF
 +
:::d) FF EE 22 FF
 +
:::e) EE FF 22 FF
  
 +
* Submit your answer in HW 3 PB 4, on Moodle.
 
<br />
 
<br />
  
 +
=Problem #5=
 
<br />
 
<br />
 +
Assume that we have this simple code section:
 +
<br />
 +
<source lang="asm">
 +
x      dd    0, 1, 2
 +
 +
        mov  eax, dword[x+2]
 +
        mov  ah, 0xFF
 +
        mov  dword[x+6], eax
  
 +
</source>
 
<br />
 
<br />
 +
* What is the content of the memory after the 3rd mov instruction has executed?
 +
:::a) 00 00 00 00 00 01 FF 00 00 01 00 00
 +
:::b) 00 00 00 00 01 00 00 FF 01 00 00 00
 +
:::c) 00 00 00 00 00 FF 01 00 00 01 00 00
 +
:::d) 00 00 00 00 01 FF 01 00 00 01 00 00
 +
:::e) 00 00 00 00 FF 01 01 00 00 00 01 00
  
 +
* Submit your answer in HW 3 PB 5, on Moodle.
 
<br />
 
<br />
 +
<showafterdate after="20151008 00:00" before="20151230 00:00">
 +
=Solution Problems=
 +
==Problem 1==
 +
    1 eax: 0x00004378
 +
    2 ebx: 0x12344321
 +
    3 ecx: 0x08766181
 +
    4 edx: 0xFFFF78FF
 +
==Problem 2==
 +
    1 eax: 00000001
 +
    2 ebx: 00000002
 +
    3 ecx: 00000A2A
 +
    4 edx: 00000100
 +
==Problem 3==
 +
::<source lang="asm">
 +
 +
 +
                section .data
 +
msg1            db      10, "I love chocolate", 10 
 +
msg1Len        equ    $-msg1 
 +
 +
       
 +
                section .text
 +
                global  _start
 +
_start:
 +
 +
;;; print original string
 +
                mov    eax, 4
 +
                mov    ebx, 1
 +
                mov    ecx, msg1
 +
                mov    edx, msg1Len
 +
                int 0x80
  
 +
;;; put your code here
 +
mov dword[msg1+1], "J'ai"
 +
mov dword[msg1+5], "me c"
 +
mov dword[msg1+9], "hoco"
 +
mov dword[msg1+13], "lat!"
 +
 +
;;; print modified string
 +
                mov    eax, 4
 +
                mov    ebx, 1
 +
                mov    ecx, msg1
 +
                mov    edx, msg1Len
 +
                int 0x80
 +
       
 +
;;; exit
 +
                mov    ebx, 0
 +
                mov    eax, 1
 +
                int 0x80
 +
</source>
 +
==Problem 4==
 +
 +
EE FF 01 00 22 FF
 +
 +
==Problem 5==
 +
 +
00 00 00 00 01 00 00 FF 01 00 00 00
 +
 +
</showafterdate>
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 
<br />
 
<br />
 +
<br />
 +
<br />
 +
<br />
 +
  
 
<br />
 
<br />
 
[[Category:CSC231]][[Category:Homework]]
 
[[Category:CSC231]][[Category:Homework]]

Latest revision as of 10:51, 13 October 2015

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


This assignment is due on 10/07/15 at 11:55 p.m.


Problem #1

What is left in eax, ebx, ecx, and edx after the following instructions have executed?

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 ch, 'a'
mov cl, 'a'+32



Store your answers in a text file called hw3_1.txt, which contains just 4 lines, with the following format:

eax: 0xXXXXXXXX
ebx: 0xXXXXXXXX
ecx: 0xXXXXXXXX
edx: 0xXXXXXXXX

Make sure the registers are in lowercase, and followed by a colon. Make sure they are listed in alphabetical order. In the lines above, XXXXXXXX are 8 hexadecimal digits representing the contents of a given register. The digits must ALL BE IN UPPERCASE.

So, for example, if you think eax will contain the value 1234aaff after the instructions have executed, you would write:

eax: 0x1234AAFF

If, on the other hand, you figure that eax contains 1, then you would write:

eax: 0x00000001


Submit your file in Section HW 3 PB 1 on Moodle. The grade for this exercise will not be visible.

Problem #2

What is left in eax, ebx, ecx, and edx after the following instructions have executed?

mov eax, 0x0
mov ebx, 0x1
mov ecx, 0x2
mov edx, 32

mov al, bl
mov ah, ch
mov dl, dh
mov dh, bl
mov bx, cx
mov ch, 0x0a
mov cl, 0x0a+32



Store your answers in a text file called hw3_2.txt, which contains just 4 lines, with the following format:

eax: 0xXXXXXXXX
ebx: 0xXXXXXXXX
ecx: 0xXXXXXXXX
edx: 0xXXXXXXXX

Submit your file in Section HW 3 PB 2 on Moodle. The grade for this problem will not be visible until past the due date.



Problem #3

Here's a program:

; hw3_3.asm
; Your name
; displays a string, modify it, then print the modified version.
;
		section	.data
msg1		db	10, "I love chocolate", 10  
msg1Len		equ	$-msg1	

	
		section	.text
		global	_start
_start:	

;;; print original string
	        mov	eax, 4
		mov	ebx, 1
		mov	ecx, msg1
		mov	edx, msg1Len
		int	0x80

;;; put your code here


;;; print modified string
	        mov	eax, 4
		mov	ebx, 1
		mov	ecx, msg1
		mov	edx, msg1Len
		int	0x80
	
;;; exit
		mov	ebx, 0
		mov	eax, 1
		int	0x80


  • When this program is executed, it prints out:

I love chocolate

I love chocolate

Your assignment is to add a section of code between the two print sections, and not change the data section in any way. Your new code will modify the contents of the string msg1, in such a way that when the second print section is executed, it will print a new string, shown below.



I love chocolate

J'aime chocolat!


In other word your new program should start with "I love chocolate" in msg1, print it, then modify msg1, print it again, and this time the message that shows up on the screen is "J'aime chocolat!".

Reminder, you cannot add any new variables to your program.

Store your program in a file called hw3_3.asm and submit it in the HW 3 PB 3 section on Moodle.

Note that the message starts with a 10, which is a linefeed. Make sure that when you modify the string, you do not change this character, as Moodle expects it to be the first character output by your program.


Problem #4


Assume that we have this simple code section:

x       dw    0, 1, 0xFF22

        mov   eax, dword[x]
        mov   ax, 0xFFEE
        mov   dword[x], eax


  • What is the content of the memory after the 3rd mov instruction has executed?
a) FF EE 01 00 22 FF
b) EE FF 01 00 22 FF
c) EE FF 01 22 FF
d) FF EE 22 FF
e) EE FF 22 FF
  • Submit your answer in HW 3 PB 4, on Moodle.


Problem #5


Assume that we have this simple code section:

x       dd    0, 1, 2

        mov   eax, dword[x+2]
        mov   ah, 0xFF
        mov   dword[x+6], eax


  • What is the content of the memory after the 3rd mov instruction has executed?
a) 00 00 00 00 00 01 FF 00 00 01 00 00
b) 00 00 00 00 01 00 00 FF 01 00 00 00
c) 00 00 00 00 00 FF 01 00 00 01 00 00
d) 00 00 00 00 01 FF 01 00 00 01 00 00
e) 00 00 00 00 FF 01 01 00 00 00 01 00
  • Submit your answer in HW 3 PB 5, on Moodle.


<showafterdate after="20151008 00:00" before="20151230 00:00">

Solution Problems

Problem 1

   1 eax: 0x00004378
   2 ebx: 0x12344321
   3 ecx: 0x08766181
   4 edx: 0xFFFF78FF

Problem 2

   1 eax: 00000001
   2 ebx: 00000002
   3 ecx: 00000A2A
   4 edx: 00000100

Problem 3

                section .data
msg1            db      10, "I love chocolate", 10  
msg1Len         equ     $-msg1  

        
                section .text
                global  _start
_start: 

;;; print original string
                mov     eax, 4
                mov     ebx, 1
                mov     ecx, msg1
                mov     edx, msg1Len
                int 0x80

;;; put your code here
				mov		dword[msg1+1], "J'ai"
				mov		dword[msg1+5], "me c"
				mov		dword[msg1+9], "hoco"
				mov		dword[msg1+13], "lat!"

;;; print modified string
                mov     eax, 4
                mov     ebx, 1
                mov     ecx, msg1
                mov     edx, msg1Len
                int 0x80
        
;;; exit
                mov     ebx, 0
                mov     eax, 1
                int 0x80

Problem 4

EE FF 01 00 22 FF

Problem 5

00 00 00 00 01 00 00 FF 01 00 00 00

</showafterdate>