Difference between revisions of "CSC231 Addressing Mode Exercises"

From dftwiki3
Jump to: navigation, search
(Exercise 0)
Line 2: Line 2:
 
<br />
 
<br />
 
<!--(Highlight the boxes to see one possible solution...)-->
 
<!--(Highlight the boxes to see one possible solution...)-->
==Exercise 0==
+
==Exercise 1==
 
<br />
 
<br />
 
Indicate the addressing used by each of the instructions below.
 
Indicate the addressing used by each of the instructions below.
Line 46: Line 46:
 
<br />
 
<br />
  
==Exercise 1==
+
==Exercise 2==
 
Write a program that changes all the characters of an all-uppercase string to all-lowercase.  We assume the string does not contain blank spaces.  You can find an ASCII table [http://www.asciitable.com/ here].
 
Write a program that changes all the characters of an all-uppercase string to all-lowercase.  We assume the string does not contain blank spaces.  You can find an ASCII table [http://www.asciitable.com/ here].
  
Line 61: Line 61:
 
-->
 
-->
  
==Exercise 2==
+
==Exercise 3==
 
Write a program that fills an array of 8 bytes with the first 8 powers of 2: 1, 2, 4, 8, 16, etc.
 
Write a program that fills an array of 8 bytes with the first 8 powers of 2: 1, 2, 4, 8, 16, etc.
  
Line 80: Line 80:
 
-->
 
-->
  
==Exercise 3==
+
==Exercise 4==
 
Write a program that fills an array of 16 words with the first 16 fibonacci terms
 
Write a program that fills an array of 16 words with the first 16 fibonacci terms
  
Line 100: Line 100:
 
-->
 
-->
  
==Exercise 4==
+
==Exercise 5==
  
 
Write a program that fills an array of 10 double-words with the first 10 powers of 2.
 
Write a program that fills an array of 10 double-words with the first 10 powers of 2.
Line 121: Line 121:
 
-->
 
-->
  
==Exercise 5==
+
==Exercise 6==
 
Assume Powers is an array of 11 words, and the first word contains a constant.  Write the program that stores 1/2 the value of the constant in the 2nd word, 1/4 the value in the 3rd word, 1/8 4th word, 1/16 5th word, etc.
 
Assume Powers is an array of 11 words, and the first word contains a constant.  Write the program that stores 1/2 the value of the constant in the 2nd word, 1/4 the value in the 3rd word, 1/8 4th word, 1/16 5th word, etc.
  
Line 140: Line 140:
 
-->
 
-->
  
==Exercise 6==
+
==Exercise 7==
 
The example below copies a string into another string, reversing the order of the string to see if they are palindromes.  Rewrite it using a ''based indexed'' addressing mode.
 
The example below copies a string into another string, reversing the order of the string to see if they are palindromes.  Rewrite it using a ''based indexed'' addressing mode.
  

Revision as of 06:20, 2 October 2014

Exercises on Addressing Modes


Exercise 1


Indicate the addressing used by each of the instructions below.

;;;  ------------------------------------------------------------
;;;  Identify possible errors in the instructions below, and
;;;  indicate the addressing mode for each one.
;;;  ------------------------------------------------------------

                section .data
a               db      3
b               db      0x12345678
c               dw      0
x               dd      30        
array           dd      1,2,3,4,5,6,7,8,9,10
        
                section .text
                global  _start

_start:         mov     eax, a
                mov     eax, dword[a] ; is it an error?
                mov     ebx, array
                mov     eax, dword[ebx]
                mov     esi, 0
                mov     dword[ebx+esi], 0
                mov     dword[ebx+esi+4], eax
                mov     edi, b
                mov     byte[edi], 'Z'
                add     al, 'z'-'Z'
                mov     ecx, 10
for:            inc     ecx
                loop    for
    
;;;  exit()

                mov     eax,1
                mov     ebx,0
                int     0x80    ; final system call


Exercise 2

Write a program that changes all the characters of an all-uppercase string to all-lowercase. We assume the string does not contain blank spaces. You can find an ASCII table here.


Exercise 3

Write a program that fills an array of 8 bytes with the first 8 powers of 2: 1, 2, 4, 8, 16, etc.


Exercise 4

Write a program that fills an array of 16 words with the first 16 fibonacci terms


Exercise 5

Write a program that fills an array of 10 double-words with the first 10 powers of 2.


Exercise 6

Assume Powers is an array of 11 words, and the first word contains a constant. Write the program that stores 1/2 the value of the constant in the 2nd word, 1/4 the value in the 3rd word, 1/8 4th word, 1/16 5th word, etc.


Exercise 7

The example below copies a string into another string, reversing the order of the string to see if they are palindromes. Rewrite it using a based indexed addressing mode.