home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / callmach.ex < prev    next >
Text File  |  1994-01-31  |  2KB  |  73 lines

  1.         -- Example of calling a machine code 
  2.         -- routine from Euphoria
  3.  
  4. include machine.e
  5. include graphics.e
  6.  
  7. sequence vc
  8. vc = video_config()
  9.  
  10. atom screen
  11. if vc[VC_COLOR] then
  12.     screen = #B8000 -- color
  13. else
  14.     screen = #B0000 -- mono
  15. end if
  16.  
  17. sequence string_copy_code, string
  18. atom code_space, string_space, screen_location
  19.  
  20. clear_screen()
  21.  
  22. string = {'E', 9, 'u', 10, 'p', 11, 'h', 12, 'o', 13, 'r', 14,
  23.       'i', 15, 'a', 2, '!', 134}
  24.  
  25. string_space = allocate(length(string)+1)
  26. screen_location = screen+11*80*2+64 -- 10 lines down
  27.  
  28.         -- String Copy machine code:
  29.         -- (will move at least one char)
  30. string_copy_code =
  31.       {#50,                   -- push eax
  32.        #53,                   -- push ebx
  33.        #52,                   -- push edx
  34.        #B8} &                   -- mov eax, 
  35.        int_to_bytes(string_space) &    -- string address (source)
  36.       {#BA} &                   -- mov edx, 
  37.        int_to_bytes(screen_location) & -- screen address (destination)
  38.       {#8A, #18,               -- L1: mov bl, [eax]
  39.        #40,                   -- inc eax
  40.        #88, #1A,               -- mov [edx],bl
  41.        #83, #C2, #01,               -- add edx, #1
  42.        #80, #38, #00,               -- cmp byte ptr [eax], #00
  43.        #75, #F3,                -- jne L1
  44.        #5A,                    -- pop edx    
  45.        #5B,                   -- pop ebx
  46.        #58,                   -- pop eax
  47.        #C3}                   -- ret
  48.  
  49. -- poke in the machine code:
  50. code_space = allocate(length(string_copy_code))
  51. for i = 1 to length(string_copy_code) do
  52.     poke(code_space+i-1, string_copy_code[i])
  53. end for
  54.  
  55. -- poke in the string:
  56. for i = 1 to length(string) do
  57.     poke(string_space+i-1, string[i])
  58. end for
  59. poke(string_space+length(string), 0) -- machine code looks for 0 terminator
  60.  
  61. puts(1, "\n  calling machine code routine ... ")
  62.  
  63. -- call the machine code:
  64. call(code_space) -- copies string to screen
  65.  
  66. -- these would be freed anyway when the program ends:
  67. free(code_space)
  68. free(string_space)
  69.  
  70. puts(1, "success\n")
  71.  
  72.  
  73.