home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 11 / labnotes / regprint.asm < prev    next >
Assembly Source File  |  1992-02-24  |  6KB  |  193 lines

  1. ;RegPrint.asm
  2. ;Copyright (c) 1992 Jay Munro
  3. ;First Published in PC Magazine June 16, 1992
  4.  
  5. ;Prints the current register status to the Monochrome screen
  6. ;preserves all registers
  7.  
  8. .286P
  9. .Model Medium
  10.  
  11.  Public RegPrint
  12.  Extrn   __B000H :ABS           ;selector for Mono monitor
  13. .Code
  14.  
  15. RegPrint Proc Far
  16.    Push BP                      ;save BP (original)
  17.    Mov  BP,SP                   ;SP = BP + 2
  18.  
  19. ;---- All reg's saved
  20.    PushF                        ;BP - 2        ;flags
  21.    Push Word Ptr [BP + 2]       ;original IP
  22.    Sub  Word Ptr [BP-4],5       ;subtract 5 bytes for call to RegPrint
  23.    Push Word Ptr [BP + 4]       ;original CS   ;CS
  24.    Push SS                      ;BP - 6
  25.    Push ES                      ;BP - 8
  26.    Push DS                      ;BP - 10
  27.    Push DI                      ;BP - 12
  28.    Push SI                      ;BP - 14
  29.    Push Word Ptr [BP]           ;original BP that was saved
  30.    Push BP                      ;BP - 18 (sp)
  31.    Inc  Word Ptr SS:[BP-18]     ;make SP by adding 2 to BP
  32.    Inc  Word Ptr SS:[BP-18]
  33.    Push DX                      ;BP - 20
  34.    Push CX                      ;BP - 22
  35.    Push BX                      ;BP - 24
  36.    Push AX                      ;BP - 26
  37.  
  38.    Mov  BX,__B000h              ;segment of monochrome monitor
  39.    Mov  ES,BX                   ;put mono selector into ES
  40.    Xor  DI,DI                   ;clear DI
  41.    Mov  AH,7                    ;white on black attribute
  42.    Push CS
  43.    Pop  DS                      ;get DS:SI pointing to templage
  44.    Lea  SI,Template
  45.    Mov  CX,160                  ;print 160 characters
  46.    Cld                          ;forward direction
  47.    Push DI                      ;save DI location
  48.  
  49. PLoop:                          ;print template
  50.    LodSb
  51.    StoSw
  52.    Loop PLoop
  53.    Pop  DI                      ;retrive DI
  54.  
  55.    Push DI                      ;save for second line
  56.    Add  DI,6                    ;slide DI over to first column
  57.  
  58. ;---Print AX - DI               ;
  59.    Lea  SI,[BP-28]
  60.    Push SS                      ;point DS at SS
  61.    Pop  DS
  62.    Mov  CX,8                    ;do 8 words
  63.    Cld                          ;forward direction (up the stack)
  64.    
  65. DoFirstEight:
  66.    LodSw
  67.    Call Print2Bytes             ;print it
  68.    Add  DI,10                   ;skip over template data
  69.    Loop DoFirstEight
  70.  
  71.    Pop  DI
  72.    Add  DI,166                  ;point to next line
  73.    Mov  CX,5                    ;and do 5 variables
  74.    
  75. DoNextFive:
  76.    LodSw
  77.    Call Print2Bytes             ;print it
  78.    Add  DI,10                   ;skip over template data
  79.    Loop DoNextFive
  80.    
  81. DoFlags:
  82.    Sub  DI,6                    ;we're currently 6 bytes overshooting
  83.    LodSw                        ;get flag byte into AX
  84.    Mov  BX,AX
  85.    Push CS
  86.    Pop  DS
  87.    Lea  SI,FlagMnemonics        ;point DS:SI at flag mnemonics
  88.    Mov  DX,SI                   ;save value in DX also
  89.    Shl  BX,4                    ;skip over Nested task and IOP flags
  90.    Mov  CX,3
  91.  
  92. First3:
  93.    Clc                          ;clear carry first
  94.    Shl  BX,1                    ;bump a bit off the end
  95.    Jc   @F                      ;get clear word
  96.    Add  SI,2                    ;
  97. @@:
  98.    Call PrintFlagMn
  99.    Loop First3
  100.  
  101.    Shl  BX,1                    ;skip trap bit
  102.    Mov  CX,2
  103.  
  104. Next2:                          ;print Sign and Zero
  105.    Clc                          ;clear carry first
  106.    Shl  BX,1                    ;bump a bit off the end
  107.    Jc   @F                      ;get clear word
  108.    Add  SI,2                    ;
  109. @@:
  110.    Call PrintFlagMn
  111.    Loop Next2
  112.    
  113.    Mov  CX,2
  114.    
  115. Last3:
  116.    Clc                          ;clear carry first
  117.    Shl  BX,2                    ;skip space, and get AC
  118.    Jc   @F                      ;get Aux carry
  119.    Add  SI,2                    ;
  120. @@:
  121.    Call PrintFlagMn
  122.    Loop Last3
  123.  
  124. Exit:           ;retrieve registers
  125.    Pop  AX
  126.    Pop  BX
  127.    Pop  CX
  128.    Pop  DX
  129.    Add  SP,4    ;skip over SP & BP
  130.    Pop  SI
  131.    Pop  DI
  132.    Pop  DS
  133.    Pop  ES
  134.    Add  SP,6    ;skip over SS & CS
  135.    PopF
  136.  
  137.    Mov  SP,BP
  138.    Pop  BP
  139.    Ret
  140.  
  141. ;entry with   ES:DI pointing toward screen location
  142. ;             BX = Word to print
  143. ;             CX trashed
  144.  
  145. Print2Bytes:
  146.    Mov   BX,AX          ;make copy of word
  147.    Shr   AX,12          ;get left most nibble
  148.    Call  HexOut
  149.    Mov   AL,BH          ;get next nibble
  150.    And   AL,0Fh         ;
  151.    Call  HexOut
  152.    Mov   AL,BL          ;get next byte
  153.    Shr   AL,4           ;and next nibble
  154.    Call  HexOut         ;printit
  155.    Mov   AL,BL          ;and last nibble
  156.    And   AL,0Fh         ;
  157.  
  158. HexOut:
  159.    Cmp  AL,10
  160.    Jae  NotNumber
  161.    Add  AL,"0"          ;make it an ascii digit
  162.    Jmp  Short SendIt
  163. NotNumber:
  164.    Add  AL,55           ;make it a hex letter
  165.  
  166. SendIt:
  167.    StoSb                ;store byte
  168.    Inc  DI              ;and skip attribute
  169.    RetN
  170.    
  171. PrintFlagMn:
  172.    LodSb
  173.    StoSb
  174.    Inc  DI              ;skip attribute
  175.    LodSb
  176.    StoSb
  177.    Add DI,3             ;skip attribute and on to next character
  178.  
  179.    Add DX,4             ;point to next two bytes
  180.    Mov SI,DX            ;retread SI
  181.    RetN
  182.    
  183.    
  184.  
  185. Template DB  'AX=0000  BX=0000  CX=0000  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000          '
  186.          DB  'DS=0000  ES=0000  SS=0000  CS=0000  IP=0000  NV UP EI PL NZ NA PO NC            '
  187.              ;0123456789012345678901234567890123456789012345678901234567890123456789
  188.  
  189. FlagMnemonics DB 'OVNVDNUPEIDINGPLZRNZACNAPEPOCYNC'
  190.  
  191. RegPrint EndP
  192. End
  193.