home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / COMPARE.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  3.6 KB  |  149 lines

  1. ;
  2. ; GRDB
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; COMPARE.ASM
  10. ;
  11. ; Function: compare memory regions
  12. ;
  13.     ;MASM MODE
  14.     .MODEL SMALL
  15.     .386
  16.  
  17.  
  18. include eprints.inc 
  19. include einput.inc 
  20. include emtrap.inc 
  21. include eoptions.inc
  22.  
  23.     PUBLIC    compare
  24.     PUBLIC    paddr
  25.  
  26.  
  27.     .CODE
  28.  
  29. ;Set DS if valid address provided in input
  30. ; INPUT: SI points to input to parse
  31. ; OUTPUT: DX contains segment address to use
  32. ;    CY if
  33.  
  34. cra    PROC
  35.     call    ReadAddress        ; read source address
  36.     jc    crax            ; none found
  37.     test    [optdwordcommand],1    ;see if flat real mode
  38.     jnz    nomvz            ;if set, no zero extend
  39.     movzx    ebx,bx            ;else extend
  40. nomvz:
  41.     call    defDS            ; get data seg
  42. crax:
  43.     ret
  44. cra    ENDP
  45.  
  46. ;INPUT: AL has byte (two hex chars) to print
  47.  
  48. pbyte    PROC
  49.     call    PrintByte
  50.     call    printspace
  51.     ret
  52. pbyte    ENDP
  53.  
  54. ;INPUT: EDX has segment address
  55. ;    EAX has offset address
  56. ;If flat real mode, print 32-bit offset, else print 16-bit offset
  57.  
  58. paddr    PROC
  59.     xchg    eax,edx            ;now EDX=offset, EAX=segment
  60.     call    printword        ;display segment
  61.     xchg    edx,ebx            ;store offset in EBX
  62.     mov    dl,':'            ;putchar wants char in DL
  63.     call    putchar            ;print colon
  64.     mov    eax,ebx            ;put offset in EAX
  65.     test    [optdwordcommand],1    ;printing 32-bit offsets?
  66.     jnz    pdw            ;if so, do that
  67.     call    printword        ;else just 16 bits
  68.     call    printspace
  69.     ret
  70. pdw:
  71.     call    printdword        ;print 32-bit offset
  72.     call    printspace
  73.     ret
  74. paddr    ENDP
  75. ;
  76. ; compare command
  77. ; syntax is c start,end,start2
  78. ;
  79. compare    PROC
  80.     call    WadeSpace        ;find source address
  81.     jz    errx            ;not found (end of input)
  82.     call    cra             ;start seg in DX, offset in EBX
  83.     jc    errx            ;not found
  84.     push    dx            ;save segment
  85.     push    ebx            ;and starting offset
  86.     call    WadeSpace        ;see if any more
  87.     jz    errx2            ;nope, didn't find
  88.     call    ReadNumber        ; read ending offset
  89.     jc    errx2            ;not found
  90.     mov    ecx,eax            ;get ending offset into ECX
  91.     sub    ecx,ebx            ;subtract starting offset
  92.     jb    errx2            ;error if end < start
  93.     call    WadeSpace        ;else keep reading input
  94.     jz    errx2            ;need a destination
  95.     call    cra            ; read dest seg and ofs
  96.     jc    errx2            ;not found
  97.     call    WadeSpace        ;make sure no more
  98.     jnz    errx2            ;if more, syntax error
  99.     test    [optdwordcommand],1    ;flat real mode?
  100.     jnz    gotsz            ;fine if so
  101.     movzx    ebx,bx            ;else zero extend dest offset
  102.     movzx    ecx,cx            ;and length to compare
  103.     movzx    eax,word ptr [esp]    ;and starting offset (on stack)
  104.     mov    [esp],eax
  105. gotsz:
  106.     pop    esi                ;get start ofs from stack to ESI
  107.     mov    edi,ebx            ;and ending offset to EDI
  108.     push    dx            ;save segment
  109. clp:
  110.     push    ds            ;save current DS
  111.     push    es            ;and ES
  112.     mov    ds,[esp+6]        ;pushed as DX just before clp:
  113.     mov    es,[esp+4]        ;pushed as DX on line 5 of routine
  114.     db    67h            ;dword override on operand
  115.     repe    cmpsb            ;cmp ds:[esi] with es:[edi]
  116.     mov    al,ds:[esi-1]        ;differing byte from source in AL
  117.     mov    ah,es:[edi-1]        ;and dest in AH
  118.     pop    es            ;back to our ds
  119.     pop    ds            ;and ES
  120.     jz    cdone            ;no difference in this case
  121.     mov    dx,[esp+2]        ;now dest segment into DX
  122.     push    ax            ;save differing bytes
  123.     call    crlf            ;new line
  124.     mov    eax,esi            ;location where different
  125.     dec    eax            ;minus cmpsb moved ESI past it
  126.     call    paddr            ;show ESI where different
  127.     pop    ax            ;restore differing bytes
  128.     push    ax            ;and save them again
  129.     call    pbyte            ;show source byte
  130.     pop    ax            ;get them back
  131.     mov    al,ah            ;setup dest byte
  132.     call    pbyte            ;and show that
  133.     mov    eax,edi            ;get dest offset
  134.     mov    dx,[esp]        ;and dest segment still on stack
  135.     dec    eax            ;minus correction for cmps
  136.     call    paddr            ;show dest seg:ofs
  137.     jmp    clp            ;find next difference
  138.     
  139. cdone:
  140.     add    sp,4
  141.     clc                ; to clean up stack
  142.     ret
  143. errx2:
  144.     add    sp,6
  145. errx:
  146.     stc
  147.     ret
  148. compare    endp
  149. end