Site
News
Files Visual Basic
Strings
Math
General
Properties
Memory
Methods Search
Testing Inline ASM-VB
Strings
Math
General
Memory Search
Using inline ASM
Submit!
News
Files Visual Basic
Strings
Math
General
Properties
Memory
Methods Search
Testing Inline ASM-VB
Strings
Math
General
Memory Search
Using inline ASM
Submit!
Example: Using ASM and a UDT (user defined type)This simple example will demonstrate how you can use an UDT in ASM. Right now I couldn't find a good example yet, so this is a very simple addition to the second item in the udt.
It took me a while to figure out that I shouldn't add more to [EBP+8], which is already the pointer. I had to add to the actual pointer location, which the code below demonstrates.
User contributed notes:
Public Type myUDT myLong1 As Long myLong2 As Long myLong3 As Long End Type '//Usage example: Dim I As Long Dim myType As myUDT myType.myLong1 = 1 myType.myLong2 = 2 myType.myLong3 = 4 I = mdlASM.asmUDT(myType) MsgBox "Return: " & I & " UDT myLong2, was 2 is now:" & myType.myLong2 |
Public Function asmUDT(udt As myUDT) As Long '#ASM_START ' push ebp ' mov ebp, esp ' ;This will get the first argument. UDT's are byref, so this is a POINTER to the actual UDT. ' ;Now, don't make the mistake that ebp+12 is the next item in the Type. It isn't! ' mov eax, [ebp+8] ; First argument. This is also the first long, myLong1! ' ;If we add 4.. we get to our second item in the Type.. myLong2! ' add eax, 4 ' ;Move the "pointer to value" to eax, so we get the actual value instead of our pointer! ' mov eax, [eax] ' ;We'll put 4 in ecx register, and multiply it with eax. ' mov ecx, 4 ' mul ecx ' ;The result is now in eax, which is returned by this function. But we also want to change ' ;The actual item in the udt! ' ;Move the eax contents backto our saved pointer ([ebp+8] + 4) ' mov edx, [ebp+8] ; First argument. This is also the first long, myLong1! ' add edx, 4 ;If we add 4.. we get to our second item in the Type.. myLong2! ' mov [edx], eax ' mov esp, ebp ;MOV/POP is much faster ' pop ebp ;on 486 and Pentium than Leave ' ret 8 '#ASM_END End Function |
User contributed notes: