CSC231 Homework 3 2015

From dftwiki3
Revision as of 14:56, 30 September 2015 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- --D. Thiebaut 13:51, 19 September 2012 (EDT) ---- <tanbox> This assignment is due on 10/07/15 at 11:55 p.m. </tanbox> =Problem #1= What is le...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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:

eax: 0x1234AAFF


Submit your file in Section HW 3 PB 1 on Moodle.


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 first message
		mov	edx, msg1Len	; # of chars to print
		int 	0x80

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

;;; print msg3
		mov	eax, 4		; write
		mov	ebx, 1		; stdout
		mov	ecx, msg3	; address of third message
		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


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


		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 hw3c.asm and submit it as follows:

   rsubmit hw3 hw3c.asm