Difference between revisions of "CSC231 Midterm Preparation"

From dftwiki3
Jump to: navigation, search
(New page: =A List of Problems to Prepare for the In-Class Closed-Books Midterm= * Write a small assembly program (don't worry about writing a complete program: just the data and instructions necess...)
 
 
(2 intermediate revisions by the same user not shown)
Line 20: Line 20:
 
                 msg2    db "world",10,"!"
 
                 msg2    db "world",10,"!"
 
                 msg3    db 0x0a
 
                 msg3    db 0x0a
 
+
 
                         section .text
 
                         section .text
 
                         mov    ebx,msg
 
                         mov    ebx,msg
 
                         add    byte [ebx+9],'-'-10
 
                         add    byte [ebx+9],'-'-10
 
                         mov    byte [msg3-2],' '
 
                         mov    byte [msg3-2],' '
 
+
                         mov    eax,WRITE
+
                         mov    eax,4
                         mov    ebx,STDOUT
+
                         mov    ebx,1
 
                         lea    ecx,[msg]
 
                         lea    ecx,[msg]
 
                         mov    edx,msg3-msg
 
                         mov    edx,msg3-msg
Line 55: Line 55:
  
 
                   65
 
                   65
 
+
 
+
 
                   -3
 
                   -3
 
+
 
+
 
                   32767
 
                   32767
  
Line 77: Line 77:
 
                    
 
                    
  
* what is the purpose of the ADC instruction? When is it useful?
+
* what is the purpose of the XOR instruction? When is it useful?

Latest revision as of 13:13, 15 October 2012

A List of Problems to Prepare for the In-Class Closed-Books Midterm

  • Write a small assembly program (don't worry about writing a complete program: just the data and instructions necessary) that displays all the letters of the alphabet on the screen.
  • Write a program that displays the first 20 fibonacci terms.
  • Write a program that stores the factorial of word-variable x into word-variable y.
  • What is the contents of eax, ebx, ecx, and edx after the execution of each instruction?
                       mov    eax,10
                       mov    edx,0
                       mov    bx,3
                       div    bx
                       
              
  • What's a segmentation fault? Give an example of an instruction that would cause one.
  • What is printed by this program?
                       section .data
               msg     db 10,10,10,"hello ",10
               msg2    db "world",10,"!"
               msg3    db 0x0a

                       section .text
                       mov     ebx,msg
                       add     byte [ebx+9],'-'-10
                       mov     byte [msg3-2],' '

                       mov     eax,4
                       mov     ebx,1
                       lea     ecx,[msg]
                       mov     edx,msg3-msg
                       int     0x80
                 
  • What's a big endian processor? a small endian processor?
  • Write a program that uses only one string of characters "********" and that prints this pattern:
                 ********
                 ******
                 ****
                 **
                 
  • Show the memory once the following data section of a program has been loaded into memory (indicate hex values with a 0x... prefix)
                             section .data
                 a           dd        10
                 b           dd        -1
                 msg         db        1,2,3,4,5,6,7
                 c           dw        0xaa


  • What is the binary and hexadecimal representations of the following 16-bit words (assume we are using 2's complement)?
                 65


                 -3


                 32767



  • What is the advantage of 2's complement over other systems of representation of signed integers?
  • What is the contents of the different registers after the following instructions have finished executing?
                            mov   eax,"231a"
                            and   eax,0xff00ff00
                            mov   ebx,0
                            mov   bl, '+'
                            shl   ebx,16
                            or    bl, '-'
                            or    eax,ebx
                 
  • what is the purpose of the XOR instruction? When is it useful?