home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / DEBUG / REGS.ASM < prev   
Encoding:
Assembly Source File  |  1997-03-27  |  3.6 KB  |  167 lines

  1.     .386p
  2.     .model small
  3.  
  4. include  prints.ase 
  5. include  mtrap.ase 
  6. include  input.ase 
  7. include  dis.ase 
  8.  
  9.     PUBLIC    DisplayRegisters, ModifyRegisters
  10.     extrn put_msg : proc
  11.  
  12.     .data
  13. ;
  14. ; This is a list corresponding ASCII names for general purpose regs
  15. ; with the address the value can be found at;
  16. ;
  17. peax    dd    offset DGROUP:dreax
  18.     db    10,"eax:",0
  19. pebx    dd    offset DGROUP:drebx
  20.     db    "ebx:",0
  21. pecx    dd    offset DGROUP:drecx
  22.     db    "ecx:",0
  23. pedx    dd    offset DGROUP:dredx
  24.     db    "edx:",0
  25. pesi    dd    offset DGROUP:dresi
  26.     db    "esi:",0
  27. pedi    dd    offset DGROUP:dredi
  28.     db    "edi:",0
  29. pebp    dd    offset DGROUP:drebp
  30.     db    10,13,"ebp:",0
  31. pesp    dd    offset DGROUP:dresp
  32.     db    "esp:",0
  33. peip    dd    offset DGROUP:dreip
  34.     db    "eip:",0
  35.     dd    0
  36. peflags    dd    offset DGROUP:reflags
  37.     db    "eflags:",0
  38. regPrompt db    10,": ",0
  39.  
  40.     .code
  41. ;
  42. ; Print a general purpose reg and it's value
  43. ;
  44. PutDword    PROC    
  45.     lodsd            ; Get pointer to val
  46.     mov    eax,[eax]    ; Get val
  47.     push    eax        ;
  48.     mov    ebx,esi        ; Get text pointer
  49.     call    put_msg
  50.     pop    eax        ;
  51.     call    printdword    ; Print value
  52.     call    printspace    ;
  53.     ret
  54. PutDword    ENDP    
  55. ;
  56. ; Print either the GP regs or the SEG regs
  57. ;
  58.  
  59. PrintAFew    PROC    
  60.     call    edx        ; Call the print routine
  61. pf_lp:
  62.     lodsb            ; Wade past the text
  63.     or    al,al        ;
  64.     jnz    pf_lp        ;
  65.     test    DWORD PTR [esi],-1 ; See if trailer found
  66.     jnz    PrintAFew    ; Go print another
  67.     ret
  68. PrintAFew    ENDP    
  69. ;
  70. ; Read value for a register
  71. ;
  72. ReadReg    PROC    
  73. rr2:
  74.     mov    edi,ebx            ; Point at list
  75.     test    DWORD PTR [edi],-1    ; See if found trailer
  76.     jz    short rr_notfound     ; Quit if so
  77.     add    edi,4            ; Skip past value
  78.     cmp    BYTE PTR [edi],10    ; Skip past line feed, if exists
  79.     jnz    short notlf        ;
  80.     inc    edi            ;
  81. notlf:
  82.     push    ecx            ; Compare specified reg name to list
  83.     push    esi            ;
  84.     repe    cmpsb            ;
  85.     pop    esi            ;
  86.     pop    ecx            ;
  87.     jz    short rr_got        ; Got it
  88.     add    ebx,4            ; Else skip past value
  89. rr_wade:
  90.     inc    ebx            ; Skip past name
  91.     test    BYTE PTR [ebx-1],-1    ;
  92.     jnz    rr_wade            ;
  93.     jmp    rr2            ; Check next name
  94. rr_got:
  95.     add    esi,ecx             ; Point after reg name
  96.     call    WadeSpace        ; Wade through spaces
  97.     cmp    al,13            ; Don't prompt if input is here
  98.     jnz    gotinput        ;
  99.     push    ebx            ; Else put up prompt
  100.     push    ecx            ;
  101.     mov    ebx,offset regPrompt
  102.     call    put_msg
  103.     call    GetInputLine        ; Get input line
  104.     pop    ecx            ;
  105.     pop    ebx            ;
  106.     call    WadeSpace        ; Ignore spaces
  107.     cmp    al,13            ; See if CR
  108.     jz    short rr_out        ; Quit if so
  109. gotinput:
  110.     mov    ebx,[ebx]        ; Get pointer to addres
  111.     call    ReadNumber        ; Read number
  112.     jc    rr_notfound        ; Error if bad number
  113.     mov    [ebx],eax        ; Else just save offset
  114. rr_out:
  115.     clc                ; Get out no errors
  116.     ret
  117. rr_notfound:
  118.     stc                ; Get out, errors
  119.     ret
  120.  
  121. ReadReg    ENDP    
  122. ;
  123. ; main 'Reg' command
  124. ;
  125. ModifyRegisters    PROC    
  126.     call    WadeSpace        ; Wade through spaces
  127.     cmp    al,13            ; If CR
  128.     jz    short DisplayRegisters    ; Display regs
  129.     push    esi
  130.     sub    ecx,ecx            ; Point at text-1
  131.     dec     ecx
  132.     dec    esi            ;
  133. cloop:
  134.     inc    esi             ; Next text
  135.     inc    ecx            ; Next count
  136.     mov    al,[esi]        ; Get char
  137.     cmp    al,13            ; IF CR or SPACE
  138.     jz    short gotend        ;
  139.     cmp    al,' '            ;
  140.     jnz    short cloop        ;
  141. gotend:
  142.     pop    esi
  143.     cmp    cl,3            ; If not 3
  144.     jnz    badreg            ; Bad reg name
  145.     mov    ebx,offset peax        ; Read in a general purpose reg
  146.     call    ReadReg            ;
  147.     jmp    short gotdata        ;
  148. badreg:
  149.     stc                ; Error
  150. gotdata:
  151.     ret
  152. ModifyRegisters    ENDP    
  153. ;
  154. ; Display the processor regs
  155. ;
  156. DisplayRegisters    PROC    
  157.     mov    esi, offset peax    ; Print GP regs
  158.     mov    edx,offset PutDword    ; with the DWORD function
  159.     call    PrintAFew        ; Print them
  160.     mov    esi,offset DGROUP:peflags    ; Put the flags
  161.     call    PutDword        ;
  162.     mov    ebx,[dreip]        ; Dissassemble at current code pointer
  163.     call    DisOneLine        ;
  164.     clc
  165.     ret
  166. DisplayRegisters    ENDP    
  167. END