UMBC CMSC211

UMBC | CSEE |


STUDY GUIDE FOR ASSEMBLY LANGUAGE PROGRAMMING FOR THE IBM PC FAMILY, 3RD EDITION

  1. Convert the number 45 to binary:
  2. Convert the number 4CA0 to binary:
  3. Convert the number 1011101B to decimal:
  4. Convert the number 5Ah to decimal:
  5. Convert the number 89 to hex:
  6. Convert the number 101100011101B to hex:
  7. What is -14 in 8 bit 2's complement notation?
  8. What is the 8 bit 2's complement number 11101011B in decimal?
  9. Convert the number 29 to binary:
  10. Convert the number 3CD9h to binary:
  11. Convert the number 110100B to decimal:
  12. Convert the number 5Ah to decimal:
  13. Convert the number 101101011101B to hex:
  14. Convert the number 52 to binary:
  15. Convert the number 29 to binary:
  16. Convert the number 10111001B to decimal:
  17. Convert the number 19Bh to decimal:
  18. Convert the number 1011010111010B to hex:
  19. Convert the number 210 to hex:
  20. Do the following arithmetic problems by converting to 8 bit 2's complement binary numbers, performing the arithmetic in binary, then converting the result back to a signed decimal number. Indicate where overflow occurs. (Hint: 72 = 1001000B, 67 = 1000011B, and 39 =100111B)
    1. 72
      + 39

       

    2.      
    3. -67
      +72

       

    4. -72
      +67

       

    5. -67
      -39

       

  21. Do the following arithmetic problems by converting to 8 bit 2's complement binary numbers, performing the arithmetic in binary, then converting the result back to a signed decimal number. Indicate where overflow occurs, and why. (Hint: 83 = 1010011B, 58 =111010B, and 47 =101111B)
    1. 58
      +47

       

    2. -58
      +47

       

    3. -58
      -83

       

    4.                                                  
    5. -58
      +83

       

  22. Convert the number 0a6eh to binary:
  23. Convert the number 101101110010101B to hex:
  24. Convert the number 1011010B to decimal:
  25. Do the following arithmetic problems by converting to 8-bit 2's complement, performing the arithmetic, and then converting back to the decimal answer. Indicate any overflow that occurs.
    1. 28
      +75

       

    2. -28
      +75

       

    3. 82
      +75

       

    4.                                                    
    5. -82
      +75

       

  26. Convert the number 482 to binary:
  27. Convert the number 10110101001011B to hex:
  28. Convert the number 0ABH to decimal:
  29. Given that 35 = 001000118, 87 = 01010001B, and 51 = 001100118, do the following arithmetic problems by translating to 8-bit 2's complement form, doing the arithmetic in that form, and translating the result back to decimal. Indicate where overflow occurs, and why.
    1. 35
      -87

       

    2. -35
      -87

       

    3. -51
      87

       

    4. -51
      -87

       

  30. What are the contents of ax after executing the following sequence of instructions?
    mov ax, 9876h ;
    mov al, 0d5h ;             ax =________________________________
    
  31. Fill in the contents of ax in hex where requested in the comments below.
    
    Stuff    DW  89ABh
    MoreOfIt DB  10h
    Nonsense DB  32h
             ...
             mov ax, Stuff      ;ax = _____________
             mov ax, 7654h
             mov ah, MoreOfIt   ;ax = _____________
    
             mov al, Nonsense   ;ax = _____________
             mov ax, 7654h
             mov al, ah         ;ax = _____________
             mov ax, 7654h
             mov ah, 'a'        ;ax = _____________
    
    (HINT: 'a' = 97 = 61h)
    
             mov ax, 7654h
             mov ax, 'a'        ;ax = _____________
             mov ah, MoreOfIt
             mov al, MoreOfIt + 1 ;ax = ___________
             mov ah, 'a'
             mov al, 'a' + 1    ;ax = _____________
             mov ah, 5
             mov al, 8          ;ax = _____________
    
  32. Name the three major segments of a PC assembly language program, and give a brief description of the function of each. (Hint: Each is started by a pseudo-instruction beginning with a '.' .
  33. Write a complete assembly language program which displays the line
    You owe me $nnnn
    
    where nnnn  is the decimal value of the word Dols declared in the .DATA segment. (Use PutDec to display the value of Dols.)
  34. Write data declarations and PCMAC.INC macro calls to display the following line on the CRT screen and leave the cursor at the beginning of the next line:
    Pay the $2.00
    
  35. In order to use the macro _PutStr, what pseudo-instruction must precede it in the program?
  36. In order to use the instruction call PutDec (PutDec in UTIL.LIB) what pseudo-instruction must precede it in the program?
  37. Give assembly code necessary to display the two lines
    One thing 
    Leads to another
    
    Use only one DB statement.
  38. Write assembly data and code to display the message 'Enter amount: ', read in a decimal number and then display 'The amount was $', followed by that number. A typical run might be
    Enter amount: 1234 
    The amount was $1234
    
    (Hint: remember that PutStr destroys ah and dx.)
  39. Translate the following C statements into MASM code. All variables are assumed to be signed words.
    1. X = A / ( 5 + B ); 
    2. if (A + 4 < B)
      {
           X = X / 2; 
      }
    3. if (A <= B) { B = 2; } else { A = A - 1; }
    4. if ( (A < B) || (C = = 0) ) 
      {
         X = 12;
      }
  40. Fill in the contents of the specified registers after the following combinations of instructions have been executed ?
    A     db    12h
    C     dw    4321h
          ....
          mov   ax, 1234h     ; ax = _____________
    
          mov   al, A         ; ax = _____________
          mov   ax, 1234h
          mov   ax, C         ; ax = _____________
          mov   ax, 3FFFh
          inc   ax            ; ax = _____________
          mov   ax, 3FFFh
          inc   AL            ; ax = _____________
          mov   ax, -1
          mov   bx, -1
          imul  bx            ; ax = _____________
    
                              ; dx = _____________
      
  41. Write assembly language code to perform the following C assignment statements. Assume that all variables are signed words.
    1. X = - (A + B);
    2. Y = 14 * (A - B);
    3. Z = Z - 1;
    4. W = (A + 20) / (X - 14);
  42. Write assembly language code to effect the following C code (assume signed WORD variables): x = (a + 3) / 27;
  43. Write assembly language code fragments to accomplish the same purpose as the following C code. Assume that all variables are signed words.
    1. Counter = Counter - 1;
    2. LastDigit = Numb % 10;
    3. Average = (A + B + C) / 3;
    4. Y = A - 24 * (X - 1);
  44. Write assembly language code to effect the following C code (assume signed WORD variables): x = a / (b - 1);
  45. Fill in the blanks with the specified contents, in hex or binary:
           mov ax, 1234h
           mov al, -1           ; ax = _____________
           inc ax 
           mov ax, 1234h 
           inc al               ; ax = _____________
           mov al, 80h
           cbw                  ; ax = _____________ 
           mov al, 77h
           cbw                  ; ax = _____________
           mov ax, -1
           mov bx, 3
           mul bx               ; ax = _____________
    
                                ; dx = _____________
           mov ax, -1           ; bx still contains 3
    
           imul bx              ; ax = _____________
    
                                ; dx = _____________
      
  46. Fill in the blanks with the specified contents, in hex or binary:
           mov ax, 1200h
           dec ax               ; ax = _____________
           mov ax, 1200h
           dec al               ; ax = _____________
           mov al, FEh
           cbw                  ; ax = _____________
           mov al, 5Eh
           cbw                  ; ax = _____________
           mov ax, -1
           mov bx, 5
           imul bx              ; ax = _____________
    
                                ; dx = _____________
           mov ax, 3            ; bx is still 5
    
           mul bx               ; ax = _____________
    
                                ; dx = _____________
           mov ax. 3
           imul bx              ; ax = _____________
    
                                ; dx = _____________
    
           mov ax, 27
           cwd                  ; ax = _____________
           mov ax, 5
           idiv bx              ; ax = _____________
    
                                ; dx = _____________
           mov ax, -2
           cwd
           mov bx, 2
           idiv bx              ; ax = _____________
    
                                ; dx = _____________
           mov ax, -2
           cwd
           mov ax, 2
           div bx               ; ax = _____________
    
                                ; dx = _____________
      
  47. Write a complete MASM program which does the following: Read a single character from the keyboard; compare the character read to the to the character 'y'; if they are equal, display 'YES', otherwise display 'MAYBE'.
  48. Write assembly language code to perform the same function as the following C code. Assume that all variables are signed words.
    1. if (A > 14) 
          A = 0; 
    2. if (X <= Y) 
      {
          A = X;
      }<
      else 
      {
          A = Y; 
      }
    3. if ( (A >= B + 3) || (X = 100) ) br>
          M = 2 * M;
    4. while (A < B)
      {br>
          A = A + 1;
          B = B / 2; 
      }
  49. Let N be a word variable and aChar a byte variable. Write code to display N copies of aChar. Be sure that you display no characters if N is 0.
  50. Write assembly language code to effect the following C code (assume signed WORD variables):
    if ( (a > 4) || (rate = 15) )
    {
         b = a + 10;
    }
    else
    {
        b = a;
    }
      
  51. Suppose that A, B, C, X, Y, and Z are signed word variables. Write assembly language code to accomplish the function of the following C fragments:
    1. while ( X > 0 )
      {
          X = X - 12; b
          A = A + 1;
      }
    2. if ( C <= 5 ) 
      {
          X  = X + 1;
      }
      else
      {
          Y  = Y - 1;
      }
    3. if (( A == 4) && (B > X + 7))
      {
          Y = 0
      }
  52. Suppose that A, B, C, X, Y, and Z are signed word variables. Write assembly language code to accomplish the function of the following C fragments:
    1. if (A > X + 5)
      {
          Max = A;
      }
      else 
      {
          Max = X + 5;
      }
      
    2. while (M != N)
      {br>
          if (M > N)
          {
              M = M - N;
          } 
          else 
          {
              N = N - M:
          }
      
    3. if ((Day = = 1) || (Day = = 7))
      {
          Weekend = 1 ;
      }
      
    4. if (X < 0) 
      {
          Sgn = -1;
      } 
      else if (X > 0) 
      {
          Sgn = 1;
      } 
      else
      {
          Sgn = 0;
      }
      
  53. Write assembly language code to effect the following C code (assume signed WORD variables):
    1. if ((a > 4) || (rate = 15) ) 
      {
         b = a + 10;
      } 
      else
      {
          b = a;
      }
      
    2. Count = 0;
      ReadKey  = getchar( ); /*ASCII value goes to al */
      while (al == '*') br>
      {
          Count = Count + 1;
          ReadKey = getchar( );     
      } /* Note: onlyone getchar( ) required! */
      
    3. for(  I = 1; I <= 80; I++)
      {
          printf("*");
      }
      
    4. Sum = 0;
      
      for (I = 1; I <= 100; I++)
      { 
          Sum = Sum +I;
      }
      printf("The sum is %d\n", Sum);
      
  54. Write code which jumps to the label Beyond defined elsewhere if OFFSET A occurs in memory after OFFSET B, where A and B are labels defined in the .DATA segment.
  55. Write a complete, separately translated assembly language function Unmax which takes as input two unsigned numbers in ax and bx and returns as its value (in ax) the larger of the two. Then write a test program TestProg which tests UnMax by calling it with three appropriate sets of values and displaying the results. Finally, give the appropriate commands to assemble, link, and execute TestProg.
  56. The instruction push 153 is illegal. (That is, pushing a literal is illegal.). Write code to show how this could be done legally:
  57. Describe exactly what happens when the following instruction is executed call Whatsit
  58. Describe exactly what happens when the following instruction is executed ret
  59. Write a complete separately compiled assembly language procedure PutSmall which takes as input a number in the range 0..99 in AL and displays the number with leading zeroes. That is, it is always displayed as precisely two digits. Since I told you that you weren't going to have to divide, I will give you an alternate method: The instruction AAM (ASCII Adjust for Multiplication) does AH := AL div 10, AL := AL mod 10 (the original AL on the right side in both cases.)
  60. The macro @GetTime returns the time of day, CH = hours, CL = minutes, and DH = seconds. Write an assembly fragment which uses @GetTime and PutSmall to display the current time in the form hh:mm:ss.
  61. Suppose that Digit is a byte variable containing a digit character (e.g., '3'). Write assembly code to convert Digit to its numeric value (0..9) and store it in the signed word variable Value.
  62. Suppose that ah and al are the left and right bytes, respectively, of the ASCII representation of a two digit number. Write assembly code to convert this number to its numeric equivalent and leave the result in ax. For instance, if at the start ah = '3' and al = ‘5', when you are done you should have ax = 35 (= 0023h). Use any registers you wish.
  63. Write a macro message such that the call Message <This is a message> causes the parameter 'This is a message' to be displayed followed by a carriage return and line feed.
  64. Write a macro NonNeg A which changes the value of A to 0 if A is less than 0.
  65. Write a macro HexIt D which takes a number in a byte D, 0 <= D <= 15, and displays it as a single hex digit on the CRT. (0 is displayed as '0',10 as 'a', etc.)  Then using HexIt, write a complete separately compiled procedure PutoctB which displays the byte in the AL register as three octal (base 8) digits. (These three digits are, left to right, bits 6-7, bits 3-5, and bits 0-2. It is probably better to do this as three separate cases than to try to write a loop to do it. Use the back of this page to complete the procedure if necessary.)
  66. Suppose the following macro has been defined:
    AMac MACRO a, b, c
               cmp a, b
               jz c
               ENDM
      
    What code will be generated by the following invocations of the macro? (Note that some of the code is invalid!)
    1. AMac X, 14, ALabel
    2. AMac X+3, 14, ALabel
  67. Write a macro Thrice which displays its argument three times, each time followed by an exclamation point. Thus Thrice Help would display Help! Help! Help! (You may assume that the macro _PutStr is available.) How would you use Thrice to display the message Help Me! Help Me! Help Me!
  68. Suppose the following macro has been defined:
    AMac MACRO a, b, c
              cmp a, b
              jz c
             ENDM
      
    What code will be generated by AMac X, 14, ALabel
  69. Suppose the following macro has been defined:
    BMac MACRO a, b, z, c
               cmp a, b
               jz c
               ENDM
      
    What code will be generated by BMac X, 14 , ge, Alabel
  70. Suppose the following macro has been defined:
    CMac MACRO a, b, z, c
               cmp a, b
               j&z& c
              ENDM
      
    What code will be generated by CMac X , 14 , ge , ALabel
  71. The following probably won't work. Explain why, and fix it:
    LongJZ  MACRO aLabel
            jnz   around
            jmp   aLabel
    around: 
            ENDM
      
  72. What will the contents of the register ax be after executing each of the following instruction sequences?
            mov  ax, 5
            shl  ax, 1                 ; ax =_____________________
    
            mov  ax,10011100101b       ; binary
            and  ax,11001001110b       ; ax =_____________________
      
  73. PWORD is a word containing a 9 bit quantity in bits 3-11 (numbered from right to left, 0 to 15). Write MASM code to extract this quantity and store it in the word N.
  74. The word X contains a field in bits 6-11 (numbering from the right starting at 0). Write assembly code to extract this field and store it as a number from 0 to 63 in the word N.
  75. Write assembly language code which sets bits 5-9 of the word X to 11001B. (Bits are numbered from right to left, starting at 0.) 
  76. Write assembly language code which extracts the contents of bits 5-9 of word X, shifts them all the way to the right, and stores them in the word Field.
  77. Fill in the contents of BL at the indicated places in the comments in the following code:
          mov    bl, 11110000B
          and    bl, 11001100B           ; bl =_____________________
          mov    bl, 11110000B
          or     bl, 11001100B           ; bl =_____________________
          mov    bl, 11110000B
          xor    bl, 11001100B           ; bl =_____________________
          mov    bl, 11110000B
          not    bl                      ; bl =_____________________
          mov    bl, 11110000B
          shl    bl, 1                   ; bl =_____________________
          mov    bl, 11110000B
          rol    bl, 1                   ; bl =_____________________
          mov    bl, 11110000B
          shr    bl, 1                   ; bl =_____________________
          mov    bl, 11110000B
          sar    bl, 1                   ; bl =_____________________
      
  78. N is a word variable. Write assembly code to extract the number in bits 4-11 of N and place it, right justified, in the AX register. Remember that bits are counted from the right end of the number, starting at 0.
  79. N is a word variable. Write assembly code to store the contents of AL in bits 4-11 of the word N. (AH may contain any sort of garbage).
  80. Suppose that X is a word variable with bits numbered as usual from 0-15, right to left. Write assembly language fragments to accomplish the following:
    1. Set bit 5 of X to 1
    2. Set bits 4-6 of X to 0
    3. Toggle bit 8 (i.e., set it to 1 if it was 0, to 0 if it was 1)
    4. Set bits 4-9 of X to 101011B. Note: Previous contents of these bits might be anything, so they have to be cleared first.
  81. Write an assembly code fragment which sets the word variable N equal to the number of 1 bits in the word X. That is, if X =14 (=1110B), then N = 3, and if X = -1, N =16.
  82. Fill in the blanks with the specified contents, in hex or binary:
    MASK    EQU   00111100B
            mov   al, 11100101B
            and   al, MASK           ; al =_____________________
            mov   al, 11100101B
            or    al, MASK           ; al =_____________________
            mov   al, 11100101B
            xor   al, MASK           ; al =_____________________
            mov   al, 11100101B
            not   al                 ; al =_____________________
            mov   al, 11100101B
            neg   al                 ; al =_____________________
            mov   al, 11100101B
            shr   al, 1              ; al =_____________________
            mov   al, 11100101B
            sar   al, 1              ; al =_____________________
            mov   al, 11100101B
            ror   al, 1              ; al =_____________________
      
  83. In file directories, times are stored in the form: Second/2 in bits 0-4, minute in bits 5-10, and hour (0..23) in bits 11-15. (Bits are counted from the right. Only seconds/2 can be stored because there are only 5 bits left.) Suppose that Timel and Time2 are words containing such times and that Minute is also a word. 
    1. Write assembly code to extract the minute from Time1 and store it as a number between 0 and 59 in Minute. 
    2. Write assembly code to store a number in Minute between 0 and 59 into the minute position of Time 2.
    3. Write code which jumps to the label Later defined elsewhere if Time2 represents a later time than Time 1. (Careful!)
  84. As you may recall, each of the (2000) characters on the normal IBM PC color display screen has color characteristics controlled by an attribute byte whose format is: bits 0-2, foreground color; bit 3, intensity bit for foreground color; bits 4-6, background color; bit 7, the blink bit. Bits are numbered right to left and colors are in the form red-green-blue from left to right. Attr1 and Attr2 are such attribute bytes and Color is a word containing such a color as a number in the range 0..7
    1. Write an assembly instruction to turn on (set to 1) the blink bit in Attr1. 
    2. Write an assembly instruction to turn off (set to 0) the intensity bit in Attr1. 
    3. Write an assembly instruction to complement the bits of the foreground color in Attrl. 
    4. Write assembly code to test the intensity bit in Attr1 and jump to label High if it is on. 
    5. Write assembly code to extract the background color from Attr1 and store it as a number between 0 and 7 in Color.
    6. Write assembly code to store a number in Color between 0 and 7 into the background color position of Attr2.
  85. The following code sets cx equal to the number of trailing zeroes in ax. For instance, if ax started at 48 =110000B this code sets cx to 4.
                mov  cx, 0
    CountLoop:
                shr  ax, 1
                jc   Done         ; Jump if carry bit set
                inc  cx
                jmp              CountLoop
      
    1. Turn this code into a separately assembled procedure called TrailZ which takes as input a number in ax and returns as output also in ax the number of trailing zeroes that were in the input number. Preserve all registers except ax.
    2. Show what code would be necessary to use this procedure to set the word variable Pow equal to the number of trailing zeroes in the word variable X
    3. The original code doesn't work correctly if ax was originally zero. How does it fail?
    4. Fix the original code so that it works correctly for ax initially zero.
  86. Suppose we have declared  SomeWds DW 73,14, -22, 25, 8, 3, 27 what is in ax at the specified points in the code below?
            mov  bx, OFFSET SomeWds+4
            mov  ax, [4 + bx]          ; ax =_____________________
    
            mov  ax, [-4 + bx]         ; ax =_____________________
            mov  bx, 8
            mov  ax, [SomeWds + bx]    ; ax =_____________________
    
            mov  ax, [SomeWds+4 + bx]  ; ax =_____________________
    
            mov  ax, [SomeWds-2 + [bx] ; ax =_____________________
    
            mov  ax, [SomeWds+1+bxl    ; ax =_____________________
    
    (NOTE: the last one is a trick question, but it does have an
    answer!)
      
  87. Suppose we have declared SomeWds DW 010Ah, 020Bh, 030Ch, 040Dh, 050Eh, 060Fh, 0700h what is in ax at the specified points in the code below?
           mov bx, OFFSET SomeWds+4
           mov ax, [4+bx]              ; ax = _____________________
    
           mov ax, [-4+bx]             ; ax = _____________________
           mov bx, 8
           mov ax, [SomeWds+bx]        ; ax = _____________________
    
           mov ax, [SomeWds+4+bx]      ; ax = _____________________
    
           mov ax, [SomeWds-2+bx]      ; ax = _____________________
    
           mov ax. BYTE PTR SomeWds    ; ax = _____________________
    
           mov ax, SomeWds+1           ; ax = _____________________
      
  88. Alpha is an array of 26 characters. Write a MASM code fragment to set Alpha[0] = 'a', Alpha[1] ='b', ..., Alpha[25] ='z'.
  89. Suppose that the following data-defining pseudo-instructions are given:
    A     DB 98h
    
    B     DB 76h
    
    C     DW 5432h
      
    What will the contents of the following bytes of memory be?
      A:     B:       C:      D:
    _________________________________
    |       |       |       |       |
    _________________________________
      
  90. What are the contents of the specified registers at the specified points?
    
    A    DB    0Ah, lAh, 2Ah, 3Ah, 4Ah, 5Ah
    B    DW    0Bh, 1Bh, 2Bh, 3Bh, 4Bh
         mov   al, [A]           ; al = ________________
    
         mov   al, [A + 3]       ; al = ________________
    
         mov   ax, [B + 2]       ; ax = ________________
    
         mov   ax, [B + 6]       ; ax = ________________
    
         mov   ax, [B - 2]       ; ax = ________________
         mov   al, 11001010B
         shr   al, 1             ; al = ________________
         mov   al, 11001010B
         sar   al, 1             ; al = ________________
         mov   al, 11001010B 
         ror   al, 1             ; al = ________________
         mov   al, 11001010B
         shl   al, 1             ; al = ________________
         mov   al, 11001010B
         sal   al, 1             ; al = ________________
         mov   al, 11001010B
         rol   al, 1             ; al = ________________
         mov   cl, 5
         mov   al, 11001010B
         rol   al, cl            ; al = ________________
         mov   al, Ofh
         shl   al, 1             ; al = ________________
         mov   al, 11001010B
         and   al, 01111000B     ; al = ________________
         mov   al, 11001010B
         or    al, 01111000B     ; al = ________________
         mov   al, 11001010B
         xor   al, 01111000B     ; al = ________________
      
  91. Suppose that the following data-defining pseudo-instructions are given:
    A    DB    98h
    B    DB    76h
    C    DW    5432h
      
    What will the contents of ax be after the following combinations of mov instructions have been executed?
         mov   ax, 1234h         ; ax = ______________
    
         mov   al, A             ; ax = ______________
         mov   ax, 1234h         ;
         mov   ax, C             ; ax = ______________
         mov   ax, 1234h
         mov   ax, WORD PTR A    ; ax = ______________
         mov   ax, 1234h
         mov   ax, WORD PTR B    ; ax = ______________
         mov   ax, 1234h
         mov   ah, BYTE PTR C    ; ax = ______________
      
  92. Suppose we have defined
    P    DW    5, 18, 4, 23, -7, 432, 277, 1
      
    What is AX after executing the following instructions?
         mov   bx, OFFSET P
         mov   ax, [4 + bx]       ; ax = ______________
         mov   bx, OFFSET P+6
         mov   ax, [4 + bx]       ; ax = ______________
    
         mov   ax, [-4 + bx]      ; ax = ______________
         mov   bx, 6
         mov   ax, [P + bx]       ; ax = ______________
    
         mov   ax, [P - 2 + bx]   ; ax = ______________
    
         mov   ax, [P + 6 + bx]   ; ax = ______________
      
  93. Suppose that A is an array of 20 words. What does the following code do (generally)?
         sub   ax, ax 
         mov   bx, OFFSET A 
         mov   cx, 20 
         mov   dx, 1 
    Aloop: 
         mov   [bx], ax 
         add   bx, 2 
         add   dx, 2 
         loop Aloop
      
  94. GLARG is an array of 25 words. Write assembly code to set the word variable BIGGEST to the largest number in the GLARG array.
  95. The array int flub[ 6 ] is to be represented in assembly code as flub dw     6 DUP (?) I and N are defined as integer (signed word) variables. Write assembly code to perform N = flub[I], i.e., to have the same effect as the C code N = flub[ I ];
  96. Let the FIB array be defined by FIB DW 15 DUP (?) Write Assembly language code which sets FIB to the first 15 Fibonacci numbers; i.e., FIB(0) = 0, FIB(1)= 1, and FIB(N) = FIB(N - 1 ) + FIB(N - 2)
  97. Given the data definition X DB     0Ah, 0Fh Fill in the contents of ax after the instruction       mov ax, WORD PTR X    ; ax = ______________
  98. Suppose we have defined
    A     DW     0A00h, 0A0lh, 0A02h, 0A03h
    B     DW     0B00h, 0B0lh, 0B02h
    C     DW     0C00h, 0C0lh, 0C02h, 0C03h, 0C04h
    N     DW     3
      
    What are the contents of the specified registers after executing the following instructions?
           mov   ax, [B]            ; ax = ______________
    
           mov   ax, [B+4]          ; ax = ______________
    
           mov   ax, [B - 4]        ; ax = ______________
    
           mov   al, BYTE PTR [B+1] ; ax = ______________
    
           mov   ax, [A+16]         ; ax = ______________
           mov   bx, 4
           mov   ax, [A + bx]       ; ax = ______________
    
           mov   ax, [A + 2 + bx]   ; ax = ______________ 
           mov   bx, OFFSET B
           mov   ax, [bx]           ; ax = ______________
    
           mov   ax, [2 + bx]       ; ax = ______________
    
           mov   ax, [C - B + bx]   ; ax = ______________
           mov   si, 2
           mov   ax, [bx + si]      ; ax = ______________
    
           mov   ax, [2 + bx + si]  ; ax = ______________
           mov   bx, N
           shl   bx, 1
           mov   ax, [A + bx]       ; ax = ______________
    
           mov   ax, [A - 2 + bx]   ; ax = ______________
      
  99. Suppose that A is an array of 100 words, subscripted 0..99, and that I is a word variable. Write an assembly language instruction to set A[3] := 44. Write assembly language code to set A[I] := 44. Write assembly language code to set A[I+3] := 44.
  100. A and B are arrays of 50 words. Write assembly code to copy the contents of the B array into the A array. Write assembly code to set the word variable BIG equal to the largest (signed) element in the A array.
  101. Suppose we have declared:
    C      DB   ?
    HexDig DB   '0123456789ABCDEF'
    D      DW   ?
      
  102. Suppose that D is a number between 0 and 15. Use it as a subscript into the HexDig array to set C equal to the ASCII hex digit corresponding to the value in D.
  103. Suppose we have defined
    C      DW   0C00h, 0C01h, 0C02h, 0C03h, 0C04h, 0C05h, 0C06h
    N      DW   4
      
    What are the contents of the specified registers after executing the following instructions?
           mov  ax, [C+4]          ; ax = ________________________
           mov  si, 6
           mov  ax, [C + si]       ; ax = ________________________
           mov  ax, [C - 2 + si]   ; ax = ________________________
           mov  bx, OFFSET C
           mov  ax, [bx + si]      ; ax = ________________________
           mov  bx, N
           shl  bx, 1
           mov  ax, [C + bx]       ; ax = ________________________
                                   ;
           mov  ax, [C - 2 + bx]   ; ax = ________________________
      
  104. Suppose that A is an array of 100 words and that I is a word variable. Write assembly language code to set A[I] = 53. Write assembly language code to set the word variable LITTLE equal to the smallest (signed) element in the A array.
  105. Suppose that C is an array of 100 characters and that we have included the array UpIt in our program by making the declaration EXTRN    UpIt : BYTE in the .DATA segment.  Recall that UpIt has the property that for any character X, if X is a lower-case letter, then UpIt[X] is the upper case version of X and otherwise, UpIt is just X.  Write the code fragment which uses UpIt to convert all the lower case into upper case.
  106. In the game of Scrabble, each letter of the alphabet has an associated value.  (More common letters, such as ‘E’, have the value 1 while rare letters, such as ‘X’ have the high values, such as 10.) Suppose that SCRABVAL is an array of 256 bytes such that for any letter L, SCRABVAL[L] is the scrabble value of the letter L.  Suppose that C is an array of bytes constituting a word, terminated by the ‘$’ character.  Write code to set dx to the sum of the values of the letters in the word at C.
  107. Arrange the following segment:offset addresses in increasing order by memory location:
    023A:2130, 04413:0002, 033A:1137
    
    _________________________(lowest address)
    
    _________________________
    
    _________________________ (highest address)
      
  108. Arrange the following segment:offset addresses in increasing order:
    24A2:0123, 213B:3810, 2322:0A31
    
    low  _________________________
    
         _________________________
    
    high _________________________
      
  109. The word starting at offset 32H in the PSP contains the maximum number of open files for the program being run. Write MASM code to make the necessary declarations for the PSP segment and for the start of the .CODE segment which puts this number into ax. (Information not needed for this problem: the FILES=n entry in CONFIG.SYS gives the maximum number of open files in the system as a whole. This number can be larger or smaller than the number at offset 32H in the PSP (which is normally 20). The PSP number is the length of a table whose segment and offset is given at location 34H of the PSP. The table normally occurs at location 18H of the PSP but can be moved and enlarged using a DOS call available in DOS 3.3 and after.)
  110. The word at offset 2 of the PSP contains the segment address of the next unallocated paragraph above the current program. Write a complete assembly language subprogram to display this number in hex. This number is normally 0A000h. Explain.
  111. The program ANXMPL is executed with the command line anxmpl This is Example Code Show what will be contained in the program’s PSP, starting from the byte containing the command length:
    Cmd Len
       |
       \/
    _____________________________________________________________
    |     |     |     |     |     |     |     |     |     |     |
    _____________________________________________________________
    |     |     |     |     |     |     |     |     |     |     |
    _____________________________________________________________
    |     |     |     |     |     |     |     |     |     |     |
    _____________________________________________________________
        
  112. Write a complete assembly language program UPCASE to do the following: upcase Any old Thing produces output consisting of its command line, less UPCASE itself, all in upper case. i.e., in this case the output would be ANY OLD THING
  113. Suppose we have the following declarations:
    SegA   SEGMENT PUBLIC
    A      DW      ?
    SegA   ENDS
    
    SegB   SEGMENT PUBLIC
    B      DW      ?
    SegB   ENDS
    
    SegC   SEGMENT PUBLIC
    C      DW      ?
    SegC   ENDS
      
    and the ASSUME
           ASSSUME ds : SegA, es : SegB
      
    For each of the following instructions, fill in the segment override byte, if any, that the assembler would supply for the memory address. Answer 'dg, 'es', 'none', if no segment override is used, or 'error' if the assembler would detect an error.
           mov  A, ax         ; override = _________________________
    
           mov  B, ax         ; override = _________________________
    
           mov  C, ax         ; override = _________________________
    
           mov  [B+bx], ax    ; override = _________________________
           mov  bx, OFFSET B
           mov[2+bx], ax      ; override = _________________________
      
  114. Word 44Ah contains the width of the video screen in characters. Write a Segment declaration for the BIOSData segment which names this word ScreenWidth, and write code to place this number in ax. (You will have to load a segment register and do an ASSUME.)
  115. Discuss the PSP. In particular, what is it, where is it, who inserts its contents, and how the command line is represented in it.
  116. Suppose we have the following declarations:
    SegA   SEGMENT PUBLIC
    A      DW      ?
           SegA    ENDS
    
    SegB   SEGMENT PUBLIC
    B      DW      ?
    SegB   ENDS
    
    SegC   SEGMENT PUBLIC
    C      DW      ?
    SegC   ENDS
    
      
    and we have ASSUMEd that ds contains SegA and es contains SegB. For each of the following instructions, fill in the segment override byte, if any, that the assembler would supply for the memory address. Answer `ds', 'es, 'none', if no segment override is used, or 'error' if the assembler would detect an error.
           mov  A, ax          ; override = _________________________
    
           mov  B, ax          ; override = _________________________
    
           mov  C, ax          ; override = _________________________
           mov  bx, OFFSET B
           mov  [2+bx], ax     ; override = _________________________
           mov  bx, 2 
           mov  [B+bx], ax     ; override = _________________________
      
  117. Write a complete assembly language program TAILLEN, including the necessary declarations of the PSP segment which displays the length of its command tail. Thus the call c:\> taillen various parameters will produce the output The command tail had 19 characters.
  118. Write MASM code for the following C function:
    int absdif( int x, int y)
    {
        if ( x > y )
        {
              return ( x - y );
        }
        else
        {
              return ( y - x );
        }
    }
      
    Assume small model.
  119. ) Write a MASM code fragment for the C code z = absdif(x+3, 14);
  120. If we execute the code
         mov  ax, 104
         push ax
         mov  ax, -86
         push ax
         call TestProc;     assuming small model
         ...
         ...
    TestProc  PROC
         push bp
         mov  bp, sp
         mov  ax, 77
         push ax
         <you are here>
      
    fill in the values you can determine or their descriptions in the following diagram of the stack. Assume small model. Also show where SP is pointing.
            _________________________ high addresses
    
            _________________________
    
            _________________________
    
            _________________________
    
    
    BP-> _________________________
    
            _________________________
    
            _________________________
    
            _________________________
    
            _________________________ low addresses
      
  121. Fill in the blanks in the following MASM code segment, whose purpose is to implement the following C procedurel:
    void SetIt( int *x, int y )
    {
        x= y;
    }
    
           .MODEL SMALL
    x      EQU DWORD PTR
    y      EQU WORD PTR
    
    SetIT  PROC
           push bp
           mov  bp, sp
           push _________________________
    
           push _________________________
    
           push _________________________
    
           ___  si, x
    
           mov  ax, ___
    
           mov  __ , ax
    
           pop  _________________________
    
           pop  _________________________
    
           pop  _________________________
    
           pop  _________________________
           ret
     SetIt ENDP
      
  122. We have a procedure called aProc called by executing
           mov  ax, 18
           push ax
           mov  ax, -7
           push ax
           call aProc
      
    Suppose that aProc starts with the code
           push bp 
           mov  bp, sp 
           mov  ax, 234 
           push ax
      
    and that aProc is small model. Describe the contents of the following memory locations after the last push is executed:
    [ -2 + bp] _________________________
    
    [bp]       _________________________
    
    [2 + bp]   _________________________
    
    [4 + bp]   _________________________
      
  123. Write MASM code for the C function
    int sign( int x )
    {
         if ( x < 0 )
         {
             return -1;
         }
         else if ( x == 0 )
         {
             return 0;  
         }
         else
         {
             return 1
         }
    }
      
    Assume SMALL model.
  124. Write MASM code for the following C fragment:     x = sign(z - 18);
  125. Assuming that bp and sp are as originally given below, fill in the contents of the stack as much as possible as it will be after the following code is executed:
           mov  ax, 123
           push ax
           mov  ax, -22
           push ax
           call Subr
    L1:
            ....
    Subr   PROC
           push bp
           mov  bp,sp
           sub  sp,4
           mov  [bp - 4], 44
    
    orig. bp  -> _________________________
    
    orig. sp  -> _________________________
    
                 _________________________
    
                 _________________________
    
                 _________________________
    
                 _________________________
    
                 _________________________
     
                 _________________________
    
                 _________________________
    
                 _________________________
      
  126. At what address is the interrupt vector for the INT 10H function? What is at that address i.e., how is it used?
  127. Describe what is found at the address 0:84h in 80x86 memory?
  128. Give the code for the world's shortest interrupt handler.
  129. The two words starting at 46ch contain the time of day in clock ticks since midnight. Write a Segment declaration for the BIOSData segment which names this doubleword Clock, and write code to place the first word in ax and the second in dx. (You will have to load a segment register and do an ASSUME.) Explain why it is necessary to surround part of the code above with sti and cli instructions which enable and disable interrupts.
  130. How does the CPU decide where to go when the instruction int 21h is executed?
  131. Under MSDOS, every .EXE file starts with two signature bytes 4Dh and 5Ah indicating that it is indeed an EXE file. Write a complete MASM program ISITEXE which is invoked by the command line isitexe filename and prints the message 'EXE file' or 'non EXE file' as appropriate. Any DOS errors should result in printing the second message.

UMBC | CSEE |