1. Re: buffer to assember

Eduardo Uemura Okada wrote:
>
> How can I have a buffer to use in a piece of asm code?
>
> like
> atom buffer
> buffer=allocate(100)
> How can I pass the value of buffer to an asm routine ?
>
> Eduardo Uemura Okada
> e-mail: du at genius.com.br
> homepage: http://www.geocities.com/TimesSquare/Labyrinth/8480

Here's how I would do it with my asm compiler (available on the recent
contributions page or my web page)

; fpixel2.asm
; mov a sequence of pixels via memory buffer to the screen in mode 19
pusha
push ds
pop es
mov ebx, dword x
mov edx, dword y
mov ecx, dword count
mov esi, dword buffer

lea edx, [edx + edx*4]
lea edx, [edx*8 + #14000]
lea edi, [ebx + edx*8]
; ^ that means: edi = ((edx + edx*4)*8 + #14000)*8 + ebx

cld
rep movsb
; move ecx bytes from [ds:esi] to [es:edi]

popa
ret
; end fpixel2.asm


Compiling this with asm.ex gives:


-- fpixel2.inc

include machine.e

code =
   {#60,                    --    0: pusha
    #1E,                    --    1: push ds
    #07,                    --    2: pop es
    #BB,#00,#00,#00,#00,    --    3: mov ebx, dword x (4)
    #BA,#00,#00,#00,#00,    --    8: mov edx, dword y (9)
    #B9,#00,#00,#00,#00,    --    D: mov ecx, dword count (14)
    #BE,#00,#00,#00,#00,    --   12: mov esi, dword buffer (19)
    #8D,#14,#92,            --   17: lea edx, [edx + edx*4]
    #8D,#14,#D5,#00,#40,#01,#00,--   1A: lea edx, [edx*8 + #14000]
    #8D,#3C,#D3,            --   21: lea edi, [ebx + edx*8]
    #FC,                    --   24: cld
    #F3,#A4,                --   25: rep movsb
    #61,                    --   27: popa
    #C3}                    --   28: ret
global constant fpixel2 = allocate(41)
poke(fpixel2, code)

 -- my stuff inserted here
 atom x, y, count, buffer
 x = 10
 y = 20
 count = 100
 buffer = allocate(count)
 mem_set(buffer, 15, count)  -- 100 white pixels

 include graphics.e
 atom junk
 junk = graphics_mode(19)
 -- end my stuff

poke4(fpixel2 + 4, x)
poke4(fpixel2 + 9, y)
poke4(fpixel2 + 14, count)
poke4(fpixel2 + 19, buffer)

call(fpixel2)

-- end fpixel2

You basically pass the address of a memory buffer the same way as any
other 32-bit integer.  But in the asm code you must remember to use that
value as a pointer.

I hope this helps explain things.
--
                   _____         _____        _____
    ________      /\    \       /\    \      /\    \
   /   \    \    /  \____\     /  \____\    /  \____\
  /  _  \____\  /   / ___/_   /   /____/   /   / ___/_
 /  / \  |____|/   / /\____\ /    \    \  /   / /\____\
 \  \_/ /    / \   \/ / ___/_\     \    \ \   \/ / ___/_
  \    /____/   \    / /\    \\/\   \    \ \    / /\    \
   \   \    \    \   \/  \____\  \   \    \ \   \/  \____\
    \   \    \    \      /    /   \   \____\ \      /    /
     \   \____\    \    /    /     \  /    /  \    /    /
      \  /    /     \  /    /       \/____/    \  /    /
       \/____/       \/____/xseal at harborside.com\/____/

http://www.harborside.com/home/x/xseal/euphoria/

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu