Re: Questions about makefile.wat

new topic     » goto parent     » topic index » view thread      » older message » newer message

I can explain what the problem is.

You push 4 registers on the stack, but then do not account for that in your mov or add statements. So you end up adding the values of edx and ebp (which will probably be random junk) and returning that.

jimcbrown said...

In no case do I get the correct result of 32.

I also tested on Linux.

bernie said...
 
-- Jim here is a simple example to add two numbers. 
-- It only uses stack pointer and eax register. 
-- Notice that I have pushed the registers that I 
-- think that eu could be using. 
-- 
-- Try running the program on WIN98 and note the reurn value 
-- Then comment out any push/pop of any register or all the of registers 
-- and see what the result returns. 
-- 
 
 
include std/machine.e 
include std/dll.e 
-- 
constant add_numbers = allocate(19) 
poke(add_numbers, { 
    #56,                    --    0: push esi         ; 
    #57,                    --    1: push edi         ; 
    #52,                    --    2: push edx         ; 
    #55,                    --    3: push ebp         ; 
    #8B,#44,#24,#04,        --    4: mov eax, [esp+4] ; 
    #03,#44,#24,#08,        --    8: add eax, [esp+8] ; 
    #5D,                    --    C: pop ebp          ; 
    #5A,                    --    D: pop edx          ; 
    #5F,                    --    E: pop edi          ; 
    #5E,                    --    F: pop esi          ; 
    #C2,#08,#00})           --   10: ret 8            ; 
    -- you can change above to straight -->  #C3}) -- ret 
 
integer rid1 = define_c_func("", add_numbers , {33554436,33554436}, 33554436) 
? c_func(rid1,{15,17}) 
 
-- 
integer rid2 = define_c_func("", { '+',add_numbers }, {33554436,33554436}, 33554436) 
-- 
? c_func(rid2,{15,17}) 
-- 
if getc(0) then end if -- pause 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu