Difference between revisions of "CSC231 Addressing Mode Exercises"

From dftwiki3
Jump to: navigation, search
(Exercise 1)
Line 7: Line 7:
  
  
 
+
<!--
  msg    db      "hellotherehowareyou"
+
  msg    db      "HELLOTHEREHOWAREYOU"
 
  MSGLEN  equ    $-msg
 
  MSGLEN  equ    $-msg
 
   
 
   
Line 16: Line 16:
 
         inc    ebx            ; ebx points to next char                       
 
         inc    ebx            ; ebx points to next char                       
 
         loop    for
 
         loop    for
 
+
-->
 
 
 
 
  
 
==Exercise 2==
 
==Exercise 2==

Revision as of 07:14, 30 September 2014

Exercises on Addressing Modes

Exercise 1

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


Exercise 2

Write a program that fills an array of 8 bytes with the first 8 fibonacci terms


fib     db      1, 1, 0, 0, 0, 0, 0, 0
NOFIB   equ     $-fib

        mov     ebx, fib
        mov     esi, 2          ; point to Fib[3]                               
        mov     ecx, NOFIB-2    ; skip first 2 Fibs                             
        mov     al, byte[ebx+esi-1] ;                                           
for:    add     al, byte[ebx+esi-2]
        mov     byte[ebx+esi], al ; fib_i = fib_i-1 + fib_i-2                   
        inc     esi               ; point to next uncomputed fib                
        loop    for               ; go back  


Exercise 3

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


...


Exercise 4

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


...


Exercise 5

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 6

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.

msg1    db      "Esope reste ici et se repose"
msg2    db      "                            "
MSGLEN  equ     $-msg2

        mov     esi, msg1
        mov     edi, msg2
        mov     ecx, MSGLEN

for     mov     al, byte[esi]
        mov     byte[edi], al
        inc     esi
        inc     edi
        loop    for