Author Topic: Assembler Functions, Params and Variables  (Read 3730 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Assembler Functions, Params and Variables
« on: October 17, 2014, 03:02:09 PM »

Code: [Select]
include "$/inc/console.inc"
indexbase 0

! funA cdecl (sys a,b,c,d) as sys at _funA
jmp fwd nfun
._funA
push ebp
mov  ebp,esp
sub  esp,0x100
scope
  sys  a at [ebp+0x08]
  sys  b at [ebp+0x0C]
  sys  c at [ebp+0x10]
  sys  d at [ebp+0x14]
  sys  r at edx
  sys  i at ecx
  r=0
  for i=1 to 10
     r=r+a+b+c+d
  next
  =r
end scope
mov  esp,ebp
pop ebp
ret
.nfun

'print "here"
sys a
a=funA 1,2,3,4
print a
waitkey

JRS

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #1 on: October 17, 2014, 06:18:36 PM »
You know how to hurt a guy.  8)

I'm still looking for the magic hooker that knows the ins and outs of BASIC functions.

Mike Lobanovsky

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #2 on: October 18, 2014, 05:44:27 AM »
Hi Charles,

What does =r mean?

JRS

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #3 on: October 18, 2014, 05:54:37 AM »
OT - Where you been? On vacation?

Charles Pegge

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #4 on: October 18, 2014, 08:40:18 AM »
Hi Mike,

=r
-->
mov eax,r
-->
mov eax,edx




Also works with floats

float s
#show =s
-->
fld dword [ebx+0x1000]

Charles Pegge

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #5 on: October 19, 2014, 01:10:09 AM »
Another trick for improving performance in simple numeric procedures, is to use the bespoke cpu calling convention:

Instead of passing params on the stack, registers  ecx,edx,esi,edi, are used. (max 4 params.)

Code: [Select]
include "$/inc/console.inc"
indexbase 0

function funA cpu (a,b,c,d) as sys
#show return a+(b*c)+d
end function

sys a
#show a=funA 1,2,3,4
print a
waitkey


« Last Edit: October 19, 2014, 01:19:19 AM by Charles Pegge »

Emil_halim

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #6 on: February 06, 2015, 11:55:54 AM »
nice work Charles,

but why you don't use registers as a parameters

e.g.

Code: [Select]
include "$/inc/console.inc"
indexbase 0

function funA cpu (ecx,edx,esi,edi) as sys
#show return ecx+(edx*esi)+edi
end function

sys a
#show a=funA 1,2,3,4
print a
waitkey

Charles Pegge

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #7 on: February 06, 2015, 01:19:48 PM »
Hi Emil,

The registers are platform-specific.

In 64 bit mode the registers will be  rcx  rdx  r8  r9

Emil_halim

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #8 on: February 07, 2015, 07:24:50 AM »
Quote
The registers are platform-specific.

In 64 bit mode the registers will be  rcx  rdx  r8  r9

i think it is not aproblem at all , with 32bits use ecx,....  and with 64bits use rec,.....

thanks ,

just want to know how much is Oxygen basic bug free?

Charles Pegge

  • Guest
Re: Assembler Functions, Params and Variables
« Reply #9 on: February 07, 2015, 09:35:10 AM »

Hi Emil,

There are plenty more bugs. I guarantee it :)

Most of them are to be found in C/Basic mixed syntax, and the more complex constructs. But within simple Basic and Assembler, you are fairly safe.