CSC231 Exercises with Mov, Arithmetic and Logic Instructions

From dftwiki3
Revision as of 08:34, 27 September 2010 by Thiebaut (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut 13:34, 27 September 2010 (UTC)


The Mov Instruction

Assume that we have the following variables declared in the data segment.



         section     .data
msg1     db          "hello world", 10
MSGLEN   equ  	     $-msg1
msg2  	 db   	     "            "
msg3  	 db   	     "            "

msg4  	 db   	     "A man, a plan, a canal, Panama"
MSG3LEN	 equ  	     $-msg4
msg5  	 db   	     "                              "

fib1  	 db   	     1,	1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,	233
FIB1LEN	 equ  	     $-fib1
fib2     db          0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,   0


fib3     dw          1, 1, 2, 3, 5, 8, 13
FIB3LEN	equ  	     ($-fib3)/2

fib4  	 dw   	     0,	0, 0, 0, 0 ,0, 0

fib5  	 dd   	     1,	1, 2, 3, 5, 8, 13, 23
fib6  	 dd   	     0, 0, 0, 0, 0, 0, 0,  0    


Question 1
Write the instructions necessary to move the contents of msg1 into msg2. Remember: we do not know loops yet, so don't try to use loops.
Question 2
Same as Question 1, but into msg3, and this time with as few instructions as possible.
Question 3
msg4 is a palyndrome. Reverse it into msg5 with MOV instructions.
Question 4
Copy the array fib1 into fib2 with MOV instructions.
Question 5
if the array fib1 were one byte longer, what would that byte contain, assuming that it represents the next fibonacci term of the series?
Question 6
Copy fib3 into fib4
Question 7
Copy fib5 into fib6


Arithmetic Instructions

These questions assume that you know how to use ADD, INC, SUB, DEC, AND, OR, XOR.

Question 1
Assume that the array fib4 contains all 0s, as shown above, write the instructions necessary to compute the fibonacci terms and store the first 7 terms into it.
Question 2
Assume that we want to increment all the bytes of fib1 by 1. Figure out as many different solutions for this problem.
Question 3
what are the contents of eax and ebx at the end of the following group of instructions:


        mov	     eax, 0xff
        mov  	     ebx, 5
        xor  	     eax, ebx
        xor  	     ebx, eax
        xor  	     eax, ebx