News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

No XMM register changes

Started by Orzel94, January 21, 2017, 05:54:10 AM

Previous topic - Next topic

Orzel94

Hi
I have problem with XMM register. I can't change value inside them even by using MOSD or MOVLDP
I have code in C and in ASM which should do exactly the same (school project).

Could you help mi with it?

http://pastebin.com/q4Z9UzTD
http://pastebin.com/vHVp0RwE

jj2007

Hi Orzel,
1. your code assembles only if the last line is END aproxASM
2. then, it starts as follows:CPU Disasm
Address         Hex dump            Command                           Comments
<ModuleEntryPoi Ú$  55              push ebp
00401001        ³.  8BEC            mov ebp, esp
00401003        ³.  BB 00000000     mov ebx, 0
00401008        ³.  660F1265 28     movlpd xmm4, [ebp+28]
0040100D        ³.  660F1245 08     movlpd xmm0, [ebp+8]
00401012        ³.  660F124D 10     movlpd xmm1, [ebp+10]

... and all instructions work as expected. My advice: install Olly and debug your executable.

Welcome to the Forum :icon14:

Orzel94

thanks for answer
I'm using MS VS 2015 for dubbuging (Windows forms C# app with C++ & ASM .dll's)

When I add aproxASM at the end there is no changes, but when I replace my code with yours (don't know if I should actually) Ive got some errors

screenshots: https://1drv.ms/f/s!AhFXsdGfJyB21F2tZSEVSKwjDf_n

by the way: you mean
MOV eax,ebx
ret
aproxASM endp
END aproxASM


or just

MOV eax,ebx

END aproxASM

jj2007

What I showed you is the disassembly, not the source. I have used your source with one single change: the last line, which is END in your code, becomes END aproxASM

Thus, the assembler (MASM = ML.exe) knows that aproxASM is the entry point. I do not use Visual S. for assembly, it's an overkill, so I don't know what VS actually does under the hood. Try \masm32\qEditor.exe, it's a better tool.

Orzel94

When I've tried to assembly my code in QEditor I get "syntax error : xmm"

When I open .dll in Ollydbg the code is completly different...   https://1drv.ms/i/s!AhFXsdGfJyB21GAiSPipxuAKmU1o

jj2007

Mateusz,
You get the "syntax error : xmm" because Masm32 ships with a very old version of MASM. RichMasm would detect this and install automatically a new one when you hit F6, but with qEditor you will have to do it manually:
- download HJWasm32
- extract HJWasm32.exe to \Masm32\bin
- rename \Masm32\bin\ml.exe to mlv614.exe
- rename \Masm32\bin\HJWasm32.exe to ml.exe
- retry console assembly and link in qEditor

Btw you don't need screenshots to show disassemblies. Just select the lines in Olly that are interesting in Olly and hit CtrlC; then paste them here inside code tags (the # icon).

Btw in your screenshot, you show the point after LoadLibrary. The interesting part is when you call the address received by GetProcAddress.

TWell

tested with ml.exe 10

DllEntry proc
MOV EAX, 1
RET
DllEntry endp
...
...
END DllEntry
or_DllMainCRTStartup proc
MOV EAX, 1
RET
_DllMainCRTStartup endp
...
...
END _DllMainCRTStartup
and use def-file for dlls.

hutch--

Just get a later version of ML.EXE.

Orzel94

debuging is ok now and it compiles to .exe but after "create new .dll" in qEditor a pasting my code (by replacing all) I get sth like that:
ASM.asm: 50 lines, 2 passes, 69 ms, 0 warnings, 0 errors
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
ASM.def : error LNK2001: unresolved external symbol aproxASM
ASM.lib : fatal error LNK1120: 1 unresolved externals
LINK : fatal error LNK1141: failure during build of exports file
Could Not Find C:\Users\Mateusz\Documents\Visual Studio 2015\Projects\Generator fraktali 2D\ASM\masmdll\ASM.exp
Volume in drive C is OS
Volume Serial Number is 8482-C98C

Directory of C:\Users\Mateusz\Documents\Visual Studio 2015\Projects\Generator fraktali 2D\ASM\masmdll

21.01.2017  10:34             1 662 ASM.asm
21.01.2017  10:36                31 ASM.def
               2 File(s)          1 693 bytes
               0 Dir(s)  35 056 488 448 bytes free


ASM.def is:
LIBRARY ASM
EXPORTS aproxASM

TWell

LIBRARY ASM
EXPORTS aproxASM=_aproxASM@40

Orzel94

Creating library ASM.lib and object ASM.exp
ASM.exp : error LNK2001: unresolved external symbol _aproxASM@40
ASM.dll : fatal error LNK1120: 1 unresolved externals

jj2007

Your ASM.def file is OK. I would choose another file name, though ;-)

The normal structure of a DLL source is like this:

.code
LibMain proc instance:DWORD, reason:DWORD, unused:DWORD
  mov eax, 1
  ret
LibMain endp

aproxASM proc p_real: REAL8, p_imaginary: REAL8, c_real:REAL8, c_imaginary:REAL8, four:REAL8
MOV ebx,0
...
ret
aproxASM endp

end LibMain

Orzel94

its ok know, I have some errors (exception at the exit of procedure) but I hope (or not XD) it's logic issue (I don't know yet :/ )

last thing to make sure
1) to return integer value i must put it into EAX? Is this enought or shall I do sth more with it?
2)to load library from C# app I need
[DllImport("ASM.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        static extern int aproxASM(double p_real, double p_imaginary, double c_real, double c_imaginary, double four);

or just
[DllImport("ASM.dll")]
        static extern int aproxASM(double p_real, double p_imaginary, double c_real, double c_imaginary, double four);

TWell

A small test:
using System;
using System.Runtime.InteropServices;
// c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe aproxTestCc.cs /platform:x86
class aproxTestCs
{
[DllImport("aproxC.dll")]
static extern int aproxC(double p_real, double p_imaginary, double c_real, double c_imaginary);
[DllImport("aproxASM.dll")]
static extern int aproxASM(double p_real, double p_imaginary, double c_real, double c_imaginary, double four);

static void Main()
{
double p_real = -1.5;
double p_imaginary = -1.5;
double c_real = 0.65;
double c_imaginary = -0.03;
double four = 4.0;

int ac = aproxC(p_real, p_imaginary, c_real, c_imaginary);
Console.WriteLine("ac={0}", ac);
int aa = aproxASM(p_real, p_imaginary, c_real, c_imaginary, four);
Console.WriteLine("aa={0}", aa);
}
}
C version works, but ASM version crash.

But this outputs
ac=1
aa=360#include <stdio.h>

int __stdcall aproxC(double p_real, double p_imaginary, double c_real, double c_imaginary);
#pragma comment(lib, "aproxC.lib")
int __stdcall aproxASM(double p_real, double p_imaginary, double c_real, double c_imaginary, double four);
#pragma comment(lib, "aproxASM.lib")

int __cdecl main(void)
{
double p_real = -1.5;
double p_imaginary = -1.5;
double c_real = 0.65;
double c_imaginary = -0.03;
double four = 4.0;

int ac = aproxC(p_real, p_imaginary, c_real, c_imaginary);
printf("ac=%d\n", ac);
int aa = aproxASM(p_real, p_imaginary, c_real, c_imaginary, four);
printf("aa=%d\n", aa);

return 0;
}
BTW ebx is reserved register, use ecx instead or push/pop ebx

Orzel94

#14
I changed to ECX, create project with your code and add .lib files by properties -> linker -> Additional Library Directories
and I got:
LNK2028 unresolved token (0A00003C) "int __stdcall aproxC(double,double,double,double)" (?aproxC@@$$FYGHNNNN@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test 2 C:\Users\Mateusz\documents\visual studio 2015\Projects\test 2\test 2\Source.obj 1
LNK2028 unresolved token (0A000045) "int __stdcall aproxASM(double,double,double,double,double)" (?aproxASM@@$$FYGHNNNNN@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test 2 C:\Users\Mateusz\documents\visual studio 2015\Projects\test 2\test 2\Source.obj 1
LNK2019 unresolved external symbol "int __stdcall aproxC(double,double,double,double)" (?aproxC@@$$FYGHNNNN@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test 2 C:\Users\Mateusz\documents\visual studio 2015\Projects\test 2\test 2\Source.obj 1
LNK2019 unresolved external symbol "int __stdcall aproxASM(double,double,double,double,double)" (?aproxASM@@$$FYGHNNNNN@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test 2 C:\Users\Mateusz\documents\visual studio 2015\Projects\test 2\test 2\Source.obj 1
LNK1120 4 unresolved externals test 2 C:\Users\Mateusz\documents\visual studio 2015\Projects\test 2\Debug\test 2.exe 1


edit: sory for such trivial (I think) things but it's my first touch to DLLs and Assembler (semester must be passed XD but its quite interesting)