CSC231 Homework 3 2015

From dftwiki3
Revision as of 20:48, 30 September 2015 by Thiebaut (talk | contribs) (Problem #1)
Jump to: navigation, search

--D. Thiebaut (talk) 15:56, 30 September 2015 (EDT)


--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.

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.

Problem #3


		section	.data
msg1		db	"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


This program prints out:

I love chocolate
I love chocolate

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:


I love chocolate
J'aime chocolat!


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



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.