Exercise 7            Name       _________________    Points __/10

Give the expansions for the following macros.

Example:
Macro
Definition
Use in
Program
Macro
Expansion
_Div    Macro  N
        Mov    Dx, 0
        Mov    Bx, &N    
        Div    Bx
endm
Call  ReadDec
_Div  34
Call  WriteDec   

  
Call  ReadDec
Mov   Dx, 0
Mov   Bx, 34
Div   Bx
Call  WriteDec
1.   (2)
Macro
Definition
Use in
Program
Macro
Expansion
_Swap Macro  A, B
      PushA  
      Mov    Ax, &A       
      Mov    Bx, &B
      Mov    &A, Bx
      Mov    &B, Ax
      PopA
endm
_Swap X, Y     
   

  

2.  (4)
Macro
Definition
Use in
Program
Macro
Expansion
_DCG Macro  X, Y
       local  L
  ifb <&y>
      exitm
  endif
  while&L:
       cmp    &Y, 0
       Jne    do&L
       Jmp    endwhile&L    
   do&L:
       _Swap  &X, &Y
       Jmp    while&L
  endwhile&L:
endm
_DCG A, B      

   

  

3. (4) Give the macro to compute the power of xn, x is signed and n unsigned 8 bit, both may be constants. The result is in Ax. No overflow checking is performed. Use the following real operations.

      Mov  Ax, 1
      Mov  Cx, x
      Mov  Bh, n
  while:
      Cmp  Bh, 0
      Ja   do
      Jmp  endwhile
  do: Imul Cx
      Dec  Bh
      Jmp  while
  endwhile:

Document last modified: