home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH04 / X86.ASM < prev   
Encoding:
Assembly Source File  |  1996-02-03  |  2.7 KB  |  124 lines

  1. ; X86.ASM
  2. ;
  3. ; This is a special version of SHELL.ASM that includes macros for the x86 GET and PUT
  4. ; instructions.  It allows you to write x86 style programs for the 80x86.
  5. ;
  6. ; There are a few caveats.  
  7. ;
  8. ; First, you cannot use the HALT, BRK, or IRET instructions.
  9. ; BRK does not exist, HALT and IRET do not work the same way as they do on the x86
  10. ; hypothetical processors.
  11. ;
  12. ; Second, the memory-mapped I/O devices are not present (no switches, no LEDs).
  13. ;
  14. ; Third, use operands of the form "DS:[xxxx]" for the direct addressing mode.
  15. ; Without the "DS:" prefix, the instruction will not work the same way as the
  16. ; x86 instruction.
  17. ;
  18. ; Fourth, unlike the x86, this program uses separate segments for the code and
  19. ; data.  You cannot do self-modifying code like you did on the x86 assignments.
  20. ;
  21. ; Fifth, MASM lets you use labels that are just like the x86 labels with one exception:
  22. ; "C" is a reserved word in MASM so you cannot create a program label named "C".  MASM
  23. ; returns some bizarre error if you do.
  24. ;
  25. ; Sixth, you can use the x86 registers and addressing modes as well as the 80x86
  26. ; registers and addressing modes (8086 only). 
  27.  
  28.  
  29.         include     stdlib.a
  30.         includelib    stdlib.lib
  31.  
  32. sseg        segment    para stack 'stack'
  33. stk        byte    128 dup ("stack   ")
  34. sseg        ends
  35.  
  36. dseg        segment para public 'data'
  37. DataMemory    byte    65520 dup (?)
  38. dseg        ends
  39.  
  40.  
  41. cseg        segment    para public 'code'
  42.         assume    cs:cseg, ds:cseg
  43.  
  44.  
  45. ; The following assembly language procedure simulates the x86 GET instruction.
  46.  
  47. get        textequ    <call Gethex>
  48. GetHex        proc    near
  49.         push    es
  50.         push    bx
  51.         push    di
  52.  
  53. GHLoop:        print
  54.         byte    "Enter a hexadecimal number:",0
  55.         getsm
  56.         mov    bx, di
  57. TestHex:    mov    al, es:[bx]
  58.         inc    bx
  59.         cmp    al, 0
  60.         je    GoodHex
  61.         IsXDigit
  62.         je    TestHex
  63.         print
  64.         byte    "Illegal hexadecimal value, re-enter",cr,lf,0
  65.         jmp    GHLoop
  66.  
  67. GoodHex:    AtoH
  68.         free
  69.         pop    di
  70.         pop    bx
  71.         pop    es
  72.         ret
  73. GetHex        endp
  74.  
  75.     
  76.  
  77. ; The following assembly language procedure simulates the x86 PUT instruction.
  78.  
  79. put        textequ    <call PutHex>
  80. PutHex        proc    near
  81.         putw
  82.         putcr
  83.         ret
  84. PutHex        endp
  85.  
  86.  
  87.  
  88. ; This is where the main program goes.
  89.  
  90. Main        proc
  91.         mov    ax, dseg
  92.         mov    ds, ax
  93.         mov    es, ax
  94.         meminit
  95.  
  96.  
  97. ;*****************************************************************************************
  98. ;
  99. ; Insert your program between the two pair of asterisks below.
  100. ;
  101. ;*****************************************************************************************
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. ;*****************************************************************************************
  112.  
  113.  
  114.         ExitPgm
  115. Main        endp
  116.  
  117. cseg        ends
  118.  
  119.  
  120. zzzzzzseg    segment    para public 'zzzzzz'
  121. LastBytes    byte    16 dup (?)
  122. zzzzzzseg    ends
  123.         end    Main
  124.