Author Topic: More than just the win32 api development... (assembly rules!).  (Read 821 times)

felipe

  • Member
  • *****
  • Posts: 1010
  • Eagles are just great!
More than just the win32 api development... (assembly rules!).
« on: December 30, 2017, 04:20:44 PM »
 :biggrin: While i'm learning about the development of win32api applications i'm also having fun with simple creation of functions and adding this to a library  :P. My approach is treat this function calls like the ones of the win32 api: trashing and preserving the same registers of this api. Here it is the first work of this project, which btw, is just for fun and learning and practice assembly programming leaving for a moment the win32api world:

This function returns the length of a zero terminated string in eax, the param to the function will be a pointer to the string:

Code: [Select]
.386
.model flat,stdcall
option casemap:none

public strlen@4

.code
align 4
strlen@4:
push ebp
mov ebp,esp
mov edx,[ebp+8] ; Address of the string.
xor eax,eax

align 4
strloop:
cmp byte ptr[edx],0
je endloop
inc edx
inc eax
jmp strloop

align 4
endloop:
mov esp,ebp
pop ebp
ret 4
end

Attached are the lib and the obj files, just for the curious. Those of you (probably the majority here  :redface:) know this things better than me (actually this is my first lib  :bgrin:). Btw, i downloaded and installed the build tools (not the ide) of the vs2017 (just a few files, with developer command prompts with enviromental variables and path set just for the momment of use, and for x86 and x64 with ml and ml64). I like it  :icon_cool:. Here are the command lines that i used:
Code: [Select]
ml /c /coff uno.asm and then
Code: [Select]
lib /out:lib0.lib uno.obj. I know that this is not new for those of you (you all know who you are) but i post this here for anyone who want to destroy all this with some cool optimized code, or a better method or aproach for the construction of a library with assembly functions.  :t
Felipe.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5944
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: More than just the win32 api development... (assembly rules!).
« Reply #1 on: December 30, 2017, 05:27:16 PM »
You will have a ton of fun with libraries once you get the swing of them, make sure you use the Intel ABI so that your modules are reliable and can be easily mixed with other higher level code like API functions. You have 3 formats you can use, normal stack frames for higher level code, leaf style procedures with no stack frame for lower call overhead and you can emulate FASTCALL by using eax, ecx and edx where you really need to keep the call overhead down.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: More than just the win32 api development... (assembly rules!).
« Reply #2 on: December 31, 2017, 12:57:00 AM »
Hi Felipe,

I assume you did that with your new machine, right? I think your new computer will continue to do a good job. And as Hutch has already noted: With the API you are on the safe side. Good luck for your further projects. Keep us up to date on your progress.

Gunther
Get your facts first, and then you can distort them.

felipe

  • Member
  • *****
  • Posts: 1010
  • Eagles are just great!
Re: More than just the win32 api development... (assembly rules!).
« Reply #3 on: December 31, 2017, 07:53:04 AM »
Thanks both  :icon14:.

Yes i really like this machine, has 8gb of ram  :greensml:. That's cool  :icon_cool:. And i used those tools too (the mentioned above). I have the intention to progress to the newest instruction sets and 64 bit code. Also, playing with functions, even if you don't use them (like calling them) is a good way to start writing code with new instruction sets. You can respect the abi, and at the same time, write code that can do something useful (like returning some useful value) using only the instruction sets, leaving the windows calls for a moment away. Then you can have a better understanding of this instruction sets. Then if the code complies with the abi, you can start to use this functions directly in a program or by including the library, or by doing similar operations (with the instruction sets) in other algorithm. I think that can be a good approach to make faster to learn the more complex and newer instruction sets.  :idea:
Felipe.