Author Topic: stdcall  (Read 3544 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
stdcall
« on: September 24, 2011, 07:45:17 AM »
Deleted
« Last Edit: May 05, 2015, 09:34:18 AM by Peter »

Charles Pegge

  • Guest
Re: stdcall
« Reply #1 on: September 24, 2011, 08:35:31 AM »

Hi Peter,

Call is suitable for implementing low level stdall. It stacks parameters from right to left

Code: [Select]

jmp fwd main

iSub: 'reverse add
mov  edx,[esp+4]
mov  eax,[esp+8]
sub  eax,edx
ret  8

iAdd:
mov  edx,[esp+4]
mov  eax,[esp+8]
add  eax,edx
ret 8

main:
'====

sys vRet

vRet=call iSub 12,100
print vRet

vRet=call iAdd 100,200
print vRet


'Subraction:   155 - 76           inverse method
'            = 155 + (76 * (-1)) 
'            = 155 + (-76)   

Print 155+(76* -1)
Print 155+(-76)

/*  inverse  */
vRet=call  iAdd 76,155
print vRet


param1 =1000: param2 =500
vRet=call iSub param1, param2 
Print vRet


Charles

Charles Pegge

  • Guest
Re: stdcall
« Reply #2 on: September 24, 2011, 12:02:55 PM »
Peter,

You cant push *s

instead:


def spush
mov eax,%1
push [eax]
end def



Code: [Select]
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function MessageBox    Lib "user32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Declare Sub ExitProcess        Lib "kernel32.dll" (ByVal uExitCode As Long)

% MB_ICONQUESTION = 32
% MB_YESNO        = 4
% IDYES           = 6

string mess, caption, cmd_o, cmd_e, cmd_c

caption  = "Desktop configuration"
messy = "Do you need additional place for the wine?"
cmd_o = "open cdaudio"
cmd_e = "set cdaudio door open"
cmd_c = "close cdaudio"

def spush 'indirect push for dynamic strings
'===========================================
mov eax,%1
push [eax]
end def

'call  MessageBox 0,messy,caption,36
push  36
spush caption
spush messy
push  0
call MessageBox
cmp   eax,idyes
jnz   aExit

'call  mciSendString cmd_o,0,0,0
push  0
push  0
push  0
spush  cmd_o
call  mciSendString

'call  mciSendString cmd_e,0,0,0
push  0
push  0
push  0
spush  cmd_e
call  mciSendString

'call  mciSendString cmd_c,0,0,0
push  0
push  0
push  0
spush  cmd_c
call  mciSendString

aExit:
'push 0
'call ExitProcess

print "Okay"


Charles
« Last Edit: September 24, 2011, 12:04:46 PM by Charles Pegge »

Charles Pegge

  • Guest
Re: stdcall
« Reply #3 on: September 24, 2011, 01:46:46 PM »
I blame Windows  ;D

The different string types encountered in the OS do cause complexity. Most of this is hidden when one stays within Basic with prototype declarations for API calls.

For assembler and low level stuff, I would check the pointer level of the string if you are uncertain.

For Example

p=@s
then try these until you see ascii codes:

print hex *p
print hex **p
print hex ***p


Charles




 
« Last Edit: September 24, 2011, 01:52:41 PM by Charles Pegge »

JRS

  • Guest
Re: stdcall
« Reply #4 on: September 24, 2011, 04:37:48 PM »
Thankfully Peter Verhas created a set of high level macros to hide his pointer magic.  8)

I had a lot of fun with using GTK-Server and scripting API's dynamically at runtime. It gave me a much better understanding how other languages store data in memory. Working with structures / user types in memory are a bit more challenging. (byte alignment, indirection, ...)


Charles Pegge

  • Guest
Re: stdcall
« Reply #5 on: September 24, 2011, 10:10:07 PM »

A car looks much simpler to a driver than it does to an engineer. High level languages do many hidden things and make programming tolerable for more users.

Charles

Aurel

  • Guest
Re: stdcall
« Reply #6 on: September 25, 2011, 12:41:20 AM »
Quote
I need a simple system without any problems.

Charles ...
Don't get me wrong but Peter have right in some things.
Im not basic programer from last month but many things and string types
confusing a lot.
Is really neccery to have bstring,zstring etc....
Most of other basics have type string (ebasic have istring-but this is just
a array of characters-nothing special).
You say that you dont like type pointer but many other basics have pointer as type and i dont see nothing wrong with that.

And we must write in 02 this:
sys p
int a =5

p = @a

So we need prefixes,ok if is casting needeed...
Just a thoughts.... ;)

Charles Pegge

  • Guest
Re: stdcall
« Reply #7 on: September 25, 2011, 02:53:48 AM »
Hi Aurel,

All these string types and pointers are really intended for system level programming. And we do get a bit technical on this forum :). String and Wstring are the only types most people will need to know about. These string types have automatic garbage collection as is customary in Basic. Non-expert Basic programmers should not need to know about pointers.

One issue is that I use a low-level API for Windows, MinWin.inc and Peter derived his Window.h from an early version of this and it is partly MinWin with added Basic-style declarations and procedures.

With the low level API we don't get automatic type conversion for the parameters so technical know-how is required to call these procedures correctly. To make things  more consistent and less confusing, I should provide a standard header file to use instead of MinWin. And perhaps Peter could do the same for Window.h

Charles


Aurel

  • Guest
Re: stdcall
« Reply #8 on: September 25, 2011, 11:10:18 AM »
Quote
All these string types and pointers are really intended for system level programming.
Charles...
Ok i understand this and i understand that u use assembly but im not
assembler programmer at all.
I still dont understand what exactly is :

1.zstring  ?
2.bstring ?
3. asciiz  ???

Dont get me wrong but this types looks like nightmare to me.
Do you can explain to me in short lines what is what?

About headers...
I also work on my own includes (modifying Peters window.h)
Becuse i need some things closer to other basics.

Aurel