hi folks,
i have seen many examples of c++/C calling assembly in divers, but I want to
do the other way round, the only example I found at google doesnt seem to
work, so any pointers?
Thnks
–
- amitr0
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I want to
do the other way round, the only example I found at google doesnt seem to
work, so any pointers?
Thnks
–
Suggest you use the /Fa compiler option to generate an assembly
listing of a C/C++ file you’re compiling, this should show you what
is required.
You’ll need to declare the C function as extern in the asm
file. Where you will have to be careful is in the calling
convention. Is the C function actually compiled __cdecl ? Or is it
Pascal calling convention, or even __fastcall ?
As the asm component these differences are your problem to get right.
Mark.
At 20:10 04/12/2008, amitr0 wrote:
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I
want to do the other way round, the only example I found at google
doesnt seem to work, so any pointers?Thnks
–
mark,
thanks for the reply.
Thanks
amitr0
On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards wrote:
>
> Suggest you use the /Fa compiler option to generate an assembly listing of
> a C/C++ file you’re compiling, this should show you what is required.
>
> You’ll need to declare the C function as extern in the asm file. Where you
> will have to be careful is in the calling convention. Is the C function
> actually compiled cdecl ? Or is it Pascal calling convention, or even
> fastcall ?
>
> As the asm component these differences are your problem to get right.
>
> Mark.
>
>
>
> At 20:10 04/12/2008, amitr0 wrote:
>
>> hi folks,
>>
>> i have seen many examples of c++/C calling assembly in divers, but I want
>> to do the other way round, the only example I found at google doesnt seem to
>> work, so any pointers?
>>
>> Thnks
>>
>> –
>>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
–
- amitr0
Not sure if name mangling is your problem.
What I would suggest is to follow the /Fa path for
investigation. Compile a C++ file that includes something that calls
your C++ function and look at the resultant .COD file. The .COD
files can sometimes be enlightening.
Mark.
At 20:24 04/12/2008, amitr0 wrote:
mark,
thanks for the reply.
- it is not C, but c++ function I want to call.
- I am sure it is the name angling causing this, but even when we
do an extern “C” it doesnt work.- In the asm file we are using PROTOS no extern, would that matter?
Thanks
amitr0
On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
<mailto:xxxxxxxxxx@muttsnuts.com> wrote:
>
>Suggest you use the /Fa compiler option to generate an assembly
>listing of a C/C++ file you’re compiling, this should show you what
>is required.
>
>You’ll need to declare the C function as extern in the asm
>file. Where you will have to be careful is in the calling
>convention. Is the C function actually compiled cdecl ? Or is it
>Pascal calling convention, or even fastcall ?
>
>As the asm component these differences are your problem to get right.
>
>Mark.
>
>
>
>At 20:10 04/12/2008, amitr0 wrote:
>hi folks,
>
>i have seen many examples of c++/C calling assembly in divers, but I
>want to do the other way round, the only example I found at google
>doesnt seem to work, so any pointers?
>
>Thnks
>
>–
>
>
>
>—
>NTDEV is sponsored by OSR
>
>For our schedule of WDF, WDM, debugging and other seminars visit:
>http:http://www.osr.com/seminars
>
>To unsubscribe, visit the List Server section of OSR Online at
>http:http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
>–
>
>- amitr0
>— NTDEV is sponsored by OSR For our schedule of WDF, WDM,
>debugging and other seminars visit: http://www.osr.com/seminars To
>unsubscribe, visit the List Server section of OSR Online at
>http://www.osronline.com/page.cfm?name=ListServer</http:></http:></mailto:xxxxx>
amitr0 wrote:
- it is not C, but c++ function I want to call.
- I am sure it is the name angling causing this, but even when we do
an extern “C” it doesnt work.- In the asm file we are using PROTOS no extern, would that matter?
Please don’t make us guess. Post your assembler code and the C++
function declaration. Remember to include the .model directive and your
“proto”.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Kind of scary, thinking about writing anything in assembly code in 2008
(almost 2009!). Any day now, we’ll be saddling horses for the daily
commute.
Since you have not shown any of the code, such as the call that doesn’t work
or the declaration of the function that isn’t found, it is going to be
difficult to figure out what you are doing.
Take the advice of looking in the .cod files!
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark S. Edwards
Sent: Thursday, December 04, 2008 3:32 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] asm to c++
Not sure if name mangling is your problem.
What I would suggest is to follow the /Fa path for investigation. Compile a
C++ file that includes something that calls your C++ function and look at
the resultant .COD file. The .COD files can sometimes be enlightening.
Mark.
At 20:24 04/12/2008, amitr0 wrote:
mark,
thanks for the reply.
Thanks
amitr0
On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
wrote:
Suggest you use the /Fa compiler option to generate an assembly listing of a
C/C++ file you’re compiling, this should show you what is required.
You’ll need to declare the C function as extern in the asm file. Where you
will have to be careful is in the calling convention. Is the C function
actually compiled cdecl ? Or is it Pascal calling convention, or even
fastcall ?
As the asm component these differences are your problem to get right.
Mark.
At 20:10 04/12/2008, amitr0 wrote:
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I want to
do the other way round, the only example I found at google doesnt seem to
work, so any pointers?
Thnks
–
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
- amitr0
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.
hello folks,
i spent some time making those .COD files and debugging. Well, the problem
is fixed now, thanks for the valuable suggestions.
Best,
AB
On Thu, Dec 4, 2008 at 1:46 PM, Joseph M. Newcomer wrote:
> Kind of scary, thinking about writing anything in assembly code in 2008
> (almost 2009!). Any day now, we’ll be saddling horses for the daily
> commute.
>
>
>
> Since you have not shown any of the code, such as the call that doesn’t
> work or the declaration of the function that isn’t found, it is going to be
> difficult to figure out what you are doing.
>
>
>
> Take the advice of looking in the .cod files!
>
>
> joe
>
>
> ------------------------------
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On* Behalf Of *Mark S. Edwards
> Sent: Thursday, December 04, 2008 3:32 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] asm to c++
>
>
>
> Not sure if name mangling is your problem.
>
> What I would suggest is to follow the /Fa path for investigation. Compile
> a C++ file that includes something that calls your C++ function and look at
> the resultant .COD file. The .COD files can sometimes be enlightening.
>
> Mark.
>
> At 20:24 04/12/2008, amitr0 wrote:
>
> mark,
>
> thanks for the reply.
>
> 1. it is not C, but c++ function I want to call.
> 2. I am sure it is the name angling causing this, but even when we do an
> extern “C” it doesnt work.
> 3. In the asm file we are using PROTOS no extern, would that matter?
>
> Thanks
>
> amitr0
>
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
> wrote:
>
> Suggest you use the /Fa compiler option to generate an assembly listing of
> a C/C++ file you’re compiling, this should show you what is required.
>
> You’ll need to declare the C function as extern in the asm file. Where you
> will have to be careful is in the calling convention. Is the C function
> actually compiled cdecl ? Or is it Pascal calling convention, or even
> fastcall ?
>
> As the asm component these differences are your problem to get right.
>
> Mark.
>
>
> At 20:10 04/12/2008, amitr0 wrote:
>
> hi folks,
>
> i have seen many examples of c++/C calling assembly in divers, but I want
> to do the other way round, the only example I found at google doesnt seem to
> work, so any pointers?
>
> Thnks
>
> –
>
>
>
> —
>
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> –
>
> - amitr0
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner http:</http:>, and is
> believed to be clean.
–
- amitr0
Hey Jo, Quite! I feel this is like, a bit of an hmm that’s a bit
interesting question, but then, I remember my age, and the decade, and I
just cant figure out why anyone would want do it in the first place. Oh take
me back, oh, must be 20 years now, and the idea made sense, lots of sense,
to a young man at the time ![]()
But you’ve said something even more interesting? Don’t you think it would be
great to be able to go to work by horse? I mean, fresh air, exercise, man at
one with nature, all that … it sounds great to me and I cant even stand
(or sit) horses.
Cheers!
“Joseph M. Newcomer” wrote in message
news:xxxxx@ntdev…
Kind of scary, thinking about writing anything in assembly code in 2008
(almost 2009!). Any day now, we’ll be saddling horses for the daily
commute.
Since you have not shown any of the code, such as the call that doesn’t work
or the declaration of the function that isn’t found, it is going to be
difficult to figure out what you are doing.
Take the advice of looking in the .cod files!
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark S. Edwards
Sent: Thursday, December 04, 2008 3:32 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] asm to c++
Not sure if name mangling is your problem.
What I would suggest is to follow the /Fa path for investigation. Compile a
C++ file that includes something that calls your C++ function and look at
the resultant .COD file. The .COD files can sometimes be enlightening.
Mark.
At 20:24 04/12/2008, amitr0 wrote:
mark,
thanks for the reply.
1. it is not C, but c++ function I want to call.
2. I am sure it is the name angling causing this, but even when we do an
extern “C” it doesnt work.
3. In the asm file we are using PROTOS no extern, would that matter?
Thanks
amitr0
On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
wrote:
Suggest you use the /Fa compiler option to generate an assembly listing of a
C/C++ file you’re compiling, this should show you what is required.
You’ll need to declare the C function as extern in the asm file. Where you
will have to be careful is in the calling convention. Is the C function
actually compiled cdecl ? Or is it Pascal calling convention, or even
fastcall ?
As the asm component these differences are your problem to get right.
Mark.
At 20:10 04/12/2008, amitr0 wrote:
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I want to
do the other way round, the only example I found at google doesnt seem to
work, so any pointers?
Thnks
–
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
- amitr0
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
I wrote device drivers 43 years ago (I didn’t know they were called “device
drivers” then; my boss handed me a hardware manual and said “get this thing
to talk to the machine”). With one exception, a research system in 1975,
every driver I wrote was in assembly code. Spending 10 hours in front of a
machine examining memory by flipping address switches and hitting the
“examine” button, in a cold computer room, was State Of The Art debugging.
I have written a bit of assembler since, for example, to support an embedded
system on a 68020, to build a debugger interface on an TMX30C90, and to do
some really weird and wondrous things that no compiler could ever generate.
But the last time I wrote anything like assembly code was using an __asm
insertion to insert a weird x86 instruction inline (it was in a C function).
This is not at all “writing in assembly code”. You can even write code like
WRITE_REGISTER_xxx entirely in “C”, by using no-prolog and _asm insertions,
which again is not really “writing in assembly code” but you need to get
down-and-dirty to get that ‘lock’ prefix in place. But note that you don’t
call anything from it; it is a “leaf” of the call tree. You need
occasionally to deal with close-to-the-metal phenomena, but
assembly-code-as-a-way-of-life is not a healthy place to be.
But today, there is no justification for writing anything in the driver
world in assembler except the extremely rare-and-exotic couple lines. And
even then, compilers have intrinsics for most of the extremely rare
situations where you need high-performance instructions. If someone came to
me and wanted to write a driver in assembler, I’d require a “justification
document” that would be about half an order of magnitude harder to write
than the assembly code itself before giving permission. It would pay off in
the long run. It keeps the macho types who think “real programmers write in
assembly code” under some semblance of control.
Except for device drivers (and except for using a C-like language 1975-1977
for drivers), I have worked in high-level languages for everything I’ve done
at the application level for most of the last 40 years. The longer I
program, the less I believe anyone who says that you have to write in
assembly code for performance, except in some VERY rare and extreme
situations which always involve inner loops of computationally intense
functions. Drivers are almost never computationally intense. The tricks we
had to play on 0.1MIPS machines (or 40KIPS machines) no longer apply when
were are up at the range of 2-5GIPS and that’s per core.
Let’s see: horses. You think pollution from *cars* is bad? Have you seen
the descriptions of what the equine pollution would be in New York if we
traveled by horse? Have you ever had to stay up all night with a sick car?
Do emergency surgery on a car? Walk your car for an hour after you get home
while it cools down? I have friends who have had or still have horses, and
I hear the stories. No, I cannot imagine ever wanting to do this, under any
conditions imaginable. Have you ever biked in the rain? Think of riding a
horse in the rain as being like biking in the rain, except for the
additional smell of wet horse. And did you ever need a giant pooper-scooper
for your bike? Or your car? Note that you don’t need to feed your car
several times a day, make sure it has water, or curry it (the only thing I
curry is chicken), and clean up after it whether you use it or not.
Exercise is for people who can move without pain (I think hard before
walking over to the printer, ten feet away).
I love the outdoors, see my office site http://www.flounder.com/office.htm
(last two photos), but I also have wireless connectivity; I don’t program
using a keypunch on the back porch and send the cards off to be run
overnight, and I don’t write in assembly code.
joe
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Thursday, December 04, 2008 6:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] asm to c++
Hey Jo, Quite! I feel this is like, a bit of an hmm that’s a bit
interesting question, but then, I remember my age, and the decade, and I
just cant figure out why anyone would want do it in the first place. Oh take
me back, oh, must be 20 years now, and the idea made sense, lots of sense,
to a young man at the time ![]()
But you’ve said something even more interesting? Don’t you think it would be
great to be able to go to work by horse? I mean, fresh air, exercise, man at
one with nature, all that … it sounds great to me and I cant even stand
(or sit) horses.
Cheers!
“Joseph M. Newcomer” wrote in message
news:xxxxx@ntdev…
Kind of scary, thinking about writing anything in assembly code in 2008
(almost 2009!). Any day now, we’ll be saddling horses for the daily
commute.
Since you have not shown any of the code, such as the call that doesn’t work
or the declaration of the function that isn’t found, it is going to be
difficult to figure out what you are doing.
Take the advice of looking in the .cod files!
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark S. Edwards
Sent: Thursday, December 04, 2008 3:32 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] asm to c++
Not sure if name mangling is your problem.
What I would suggest is to follow the /Fa path for investigation. Compile a
C++ file that includes something that calls your C++ function and look at
the resultant .COD file. The .COD files can sometimes be enlightening.
Mark.
At 20:24 04/12/2008, amitr0 wrote:
mark,
thanks for the reply.
1. it is not C, but c++ function I want to call.
2. I am sure it is the name angling causing this, but even when we do an
extern “C” it doesnt work.
3. In the asm file we are using PROTOS no extern, would that matter?
Thanks
amitr0
On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
wrote:
Suggest you use the /Fa compiler option to generate an assembly listing of a
C/C++ file you’re compiling, this should show you what is required.
You’ll need to declare the C function as extern in the asm file. Where you
will have to be careful is in the calling convention. Is the C function
actually compiled cdecl ? Or is it Pascal calling convention, or even
fastcall ?
As the asm component these differences are your problem to get right.
Mark.
At 20:10 04/12/2008, amitr0 wrote:
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I want to
do the other way round, the only example I found at google doesnt seem to
work, so any pointers?
Thnks
–
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
- amitr0
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
hi folks,
i have a portion of assembly in my driver. So I moved it out into a .asm
file for easier compilation with 64 bits. the compiler gives me erros fro
INVOKE, pushad, popad. what are the equivalents in 64 bits please?
thanks
AB
On Thu, Dec 4, 2008 at 8:33 PM, Joseph M. Newcomer wrote:
> I wrote device drivers 43 years ago (I didn’t know they were called “device
> drivers” then; my boss handed me a hardware manual and said “get this thing
> to talk to the machine”). With one exception, a research system in 1975,
> every driver I wrote was in assembly code. Spending 10 hours in front of a
> machine examining memory by flipping address switches and hitting the
> “examine” button, in a cold computer room, was State Of The Art debugging.
> I have written a bit of assembler since, for example, to support an
> embedded
> system on a 68020, to build a debugger interface on an TMX30C90, and to do
> some really weird and wondrous things that no compiler could ever generate.
> But the last time I wrote anything like assembly code was using an __asm
> insertion to insert a weird x86 instruction inline (it was in a C
> function).
> This is not at all “writing in assembly code”. You can even write code
> like
> WRITE_REGISTER_xxx entirely in “C”, by using no-prolog and _asm insertions,
> which again is not really “writing in assembly code” but you need to get
> down-and-dirty to get that ‘lock’ prefix in place. But note that you don’t
> call anything from it; it is a “leaf” of the call tree. You need
> occasionally to deal with close-to-the-metal phenomena, but
> assembly-code-as-a-way-of-life is not a healthy place to be.
>
> But today, there is no justification for writing anything in the driver
> world in assembler except the extremely rare-and-exotic couple lines. And
> even then, compilers have intrinsics for most of the extremely rare
> situations where you need high-performance instructions. If someone came
> to
> me and wanted to write a driver in assembler, I’d require a “justification
> document” that would be about half an order of magnitude harder to write
> than the assembly code itself before giving permission. It would pay off
> in
> the long run. It keeps the macho types who think “real programmers write
> in
> assembly code” under some semblance of control.
>
> Except for device drivers (and except for using a C-like language 1975-1977
> for drivers), I have worked in high-level languages for everything I’ve
> done
> at the application level for most of the last 40 years. The longer I
> program, the less I believe anyone who says that you have to write in
> assembly code for performance, except in some VERY rare and extreme
> situations which always involve inner loops of computationally intense
> functions. Drivers are almost never computationally intense. The tricks
> we
> had to play on 0.1MIPS machines (or 40KIPS machines) no longer apply when
> were are up at the range of 2-5GIPS and that’s per core.
>
> Let’s see: horses. You think pollution from cars is bad? Have you seen
> the descriptions of what the equine pollution would be in New York if we
> traveled by horse? Have you ever had to stay up all night with a sick car?
> Do emergency surgery on a car? Walk your car for an hour after you get
> home
> while it cools down? I have friends who have had or still have horses, and
> I hear the stories. No, I cannot imagine ever wanting to do this, under
> any
> conditions imaginable. Have you ever biked in the rain? Think of riding a
> horse in the rain as being like biking in the rain, except for the
> additional smell of wet horse. And did you ever need a giant
> pooper-scooper
> for your bike? Or your car? Note that you don’t need to feed your car
> several times a day, make sure it has water, or curry it (the only thing I
> curry is chicken), and clean up after it whether you use it or not.
>
> Exercise is for people who can move without pain (I think hard before
> walking over to the printer, ten feet away).
>
> I love the outdoors, see my office site http://www.flounder.com/office.htm
> (last two photos), but I also have wireless connectivity; I don’t program
> using a keypunch on the back porch and send the cards off to be run
> overnight, and I don’t write in assembly code.
> joe
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
> Sent: Thursday, December 04, 2008 6:40 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] asm to c++
>
> Hey Jo, Quite! I feel this is like, a bit of an hmm that’s a bit
> interesting question, but then, I remember my age, and the decade, and I
> just cant figure out why anyone would want do it in the first place. Oh
> take
>
> me back, oh, must be 20 years now, and the idea made sense, lots of sense,
> to a young man at the time ![]()
>
> But you’ve said something even more interesting? Don’t you think it would
> be
>
> great to be able to go to work by horse? I mean, fresh air, exercise, man
> at
>
> one with nature, all that … it sounds great to me and I cant even stand
> (or sit) horses.
>
> Cheers!
>
> “Joseph M. Newcomer” wrote in message
> news:xxxxx@ntdev…
> Kind of scary, thinking about writing anything in assembly code in 2008
> (almost 2009!). Any day now, we’ll be saddling horses for the daily
> commute.
>
> Since you have not shown any of the code, such as the call that doesn’t
> work
>
> or the declaration of the function that isn’t found, it is going to be
> difficult to figure out what you are doing.
>
> Take the advice of looking in the .cod files!
> joe
>
>
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark S. Edwards
> Sent: Thursday, December 04, 2008 3:32 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] asm to c++
>
> Not sure if name mangling is your problem.
>
> What I would suggest is to follow the /Fa path for investigation. Compile
> a
>
> C++ file that includes something that calls your C++ function and look at
> the resultant .COD file. The .COD files can sometimes be enlightening.
>
> Mark.
>
> At 20:24 04/12/2008, amitr0 wrote:
>
>
> mark,
>
> thanks for the reply.
>
> 1. it is not C, but c++ function I want to call.
> 2. I am sure it is the name angling causing this, but even when we do an
> extern “C” it doesnt work.
> 3. In the asm file we are using PROTOS no extern, would that matter?
>
> Thanks
>
> amitr0
>
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
> wrote:
> Suggest you use the /Fa compiler option to generate an assembly listing of
> a
>
> C/C++ file you’re compiling, this should show you what is required.
> You’ll need to declare the C function as extern in the asm file. Where you
> will have to be careful is in the calling convention. Is the C function
> actually compiled__cdecl ? Or is it Pascal calling convention, or even
> __fastcall ?
> As the asm component these differences are your problem to get right.
> Mark.
>
>
>
> At 20:10 04/12/2008, amitr0 wrote:
> hi folks,
> i have seen many examples of c++/C calling assembly in divers, but I want
> to
>
> do the other way round, the only example I found at google doesnt seem to
> work, so any pointers?
> Thnks
> –
>
> —
> NTDEV is sponsored by OSR
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
> –
>
> - amitr0
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
–
- amitr0
amitr0 wrote:
i have a portion of assembly in my driver. So I moved it out into a
.asm file for easier compilation with 64 bits. the compiler gives me
erros fro INVOKE, pushad, popad. what are the equivalents in 64 bits
please?
It’s not that easy. The assembly language is different. Similar, but
different. Tell us more about what the assembler does, or even post the
whole clip here, and we can advise you on how best to proceed. There
are intrinsic functions available for many such tasks.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
‘pushad’ and ‘popad’ aren’t supported for x86_64. I’m not exactly sure
what ‘INVOKE’ is, but given that it’s in all CAPITALS, I assume that it
is a ML directive that does something shorthand form of a call or
whatnot. If so, I would say that the odds are excellent that it isn’t
supported by ML64, though you’d have to check the documentation,
assuming that it can be found, to be certain.
In the case of the two instructions, while conceptually you could
replace pushad/popfd with a sequence of push/pops, it almost certainly
would not make any sense due to differences between the architectures.
You might want to read up on the calling convention for x86_64:
http://msdn.microsoft.com/en-us/library/ms235286(VS.80).aspx
Assembler does not port (correctly) the way it sounds like you are going
about it.
Good luck,
mm
amitr0 wrote:
hi folks,
i have a portion of assembly in my driver. So I moved it out into a .asm
file for easier compilation with 64 bits. the compiler gives me erros
fro INVOKE, pushad, popad. what are the equivalents in 64 bits please?thanks
AB
On Thu, Dec 4, 2008 at 8:33 PM, Joseph M. Newcomer
> wrote:
>
> I wrote device drivers 43 years ago (I didn’t know they were called
> “device
> drivers” then; my boss handed me a hardware manual and said “get
> this thing
> to talk to the machine”). With one exception, a research system in
> 1975,
> every driver I wrote was in assembly code. Spending 10 hours in
> front of a
> machine examining memory by flipping address switches and hitting the
> “examine” button, in a cold computer room, was State Of The Art
> debugging.
> I have written a bit of assembler since, for example, to support an
> embedded
> system on a 68020, to build a debugger interface on an TMX30C90, and
> to do
> some really weird and wondrous things that no compiler could ever
> generate.
> But the last time I wrote anything like assembly code was using an __asm
> insertion to insert a weird x86 instruction inline (it was in a C
> function).
> This is not at all “writing in assembly code”. You can even write
> code like
> WRITE_REGISTER_xxx entirely in “C”, by using no-prolog and _asm
> insertions,
> which again is not really “writing in assembly code” but you need to get
> down-and-dirty to get that ‘lock’ prefix in place. But note that
> you don’t
> call anything from it; it is a “leaf” of the call tree. You need
> occasionally to deal with close-to-the-metal phenomena, but
> assembly-code-as-a-way-of-life is not a healthy place to be.
>
> But today, there is no justification for writing anything in the driver
> world in assembler except the extremely rare-and-exotic couple
> lines. And
> even then, compilers have intrinsics for most of the extremely rare
> situations where you need high-performance instructions. If someone
> came to
> me and wanted to write a driver in assembler, I’d require a
> “justification
> document” that would be about half an order of magnitude harder to write
> than the assembly code itself before giving permission. It would
> pay off in
> the long run. It keeps the macho types who think “real programmers
> write in
> assembly code” under some semblance of control.
>
> Except for device drivers (and except for using a C-like language
> 1975-1977
> for drivers), I have worked in high-level languages for everything
> I’ve done
> at the application level for most of the last 40 years. The longer I
> program, the less I believe anyone who says that you have to write in
> assembly code for performance, except in some VERY rare and extreme
> situations which always involve inner loops of computationally intense
> functions. Drivers are almost never computationally intense. The
> tricks we
> had to play on 0.1MIPS machines (or 40KIPS machines) no longer apply
> when
> were are up at the range of 2-5GIPS and that’s per core.
>
> Let’s see: horses. You think pollution from cars is bad? Have
> you seen
> the descriptions of what the equine pollution would be in New York if we
> traveled by horse? Have you ever had to stay up all night with a
> sick car?
> Do emergency surgery on a car? Walk your car for an hour after you
> get home
> while it cools down? I have friends who have had or still have
> horses, and
> I hear the stories. No, I cannot imagine ever wanting to do this,
> under any
> conditions imaginable. Have you ever biked in the rain? Think of
> riding a
> horse in the rain as being like biking in the rain, except for the
> additional smell of wet horse. And did you ever need a giant
> pooper-scooper
> for your bike? Or your car? Note that you don’t need to feed your car
> several times a day, make sure it has water, or curry it (the only
> thing I
> curry is chicken), and clean up after it whether you use it or not.
>
> Exercise is for people who can move without pain (I think hard before
> walking over to the printer, ten feet away).
>
> I love the outdoors, see my office site
> http://www.flounder.com/office.htm
> (last two photos), but I also have wireless connectivity; I don’t
> program
> using a keypunch on the back porch and send the cards off to be run
> overnight, and I don’t write in assembly code.
> joe
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> mailto:xxxxx
> [mailto:xxxxx@lists.osr.com
> mailto:xxxxx] On Behalf Of Lyndon J Clarke
> Sent: Thursday, December 04, 2008 6:40 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] asm to c++
>
> Hey Jo, Quite! I feel this is like, a bit of an hmm that’s a bit
> interesting question, but then, I remember my age, and the decade, and I
> just cant figure out why anyone would want do it in the first place.
> Oh take
>
> me back, oh, must be 20 years now, and the idea made sense, lots of
> sense,
> to a young man at the time
>
> But you’ve said something even more interesting? Don’t you think it
> would be
>
> great to be able to go to work by horse? I mean, fresh air,
> exercise, man at
>
> one with nature, all that … it sounds great to me and I cant even
> stand
> (or sit) horses.
>
> Cheers!
>
> “Joseph M. Newcomer” > mailto:xxxxx> wrote in message
> news:xxxxx@ntdev…
> Kind of scary, thinking about writing anything in assembly code in 2008
> (almost 2009!). Any day now, we’ll be saddling horses for the daily
> commute.
>
> Since you have not shown any of the code, such as the call that
> doesn’t work
>
> or the declaration of the function that isn’t found, it is going to be
> difficult to figure out what you are doing.
>
> Take the advice of looking in the .cod files!
>
> joe
>
>
>
>
> From: xxxxx@lists.osr.com
> mailto:xxxxx
> [mailto:xxxxx@lists.osr.com
> mailto:xxxxx] On Behalf Of Mark S. Edwards
> Sent: Thursday, December 04, 2008 3:32 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] asm to c++
>
> Not sure if name mangling is your problem.
>
> What I would suggest is to follow the /Fa path for investigation.
> Compile a
>
> C++ file that includes something that calls your C++ function and
> look at
> the resultant .COD file. The .COD files can sometimes be enlightening.
>
> Mark.
>
> At 20:24 04/12/2008, amitr0 wrote:
>
>
> mark,
>
> thanks for the reply.
>
> 1. it is not C, but c++ function I want to call.
> 2. I am sure it is the name angling causing this, but even when we do an
> extern “C” it doesnt work.
> 3. In the asm file we are using PROTOS no extern, would that matter?
>
> Thanks
>
> amitr0
>
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
> >
> wrote:
> Suggest you use the /Fa compiler option to generate an assembly
> listing of a
>
> C/C++ file you’re compiling, this should show you what is required.
> You’ll need to declare the C function as extern in the asm file.
> Where you
> will have to be careful is in the calling convention. Is the C function
> actually compiled__cdecl ? Or is it Pascal calling convention, or even
> __fastcall ?
> As the asm component these differences are your problem to get right.
> Mark.
>
>
>
> At 20:10 04/12/2008, amitr0 wrote:
> hi folks,
> i have seen many examples of c++/C calling assembly in divers, but I
> want to
>
> do the other way round, the only example I found at google doesnt
> seem to
> work, so any pointers?
> Thnks
> –
>
> —
> NTDEV is sponsored by OSR
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
> –
>
> - amitr0
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
> debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe,
> visit the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> –
>
> - amitr0</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>
tim,
here is the routine…
T_vp_malloc PROTO len:DWORD
XMemAlloc PROC
push rcx
INVOKE T_vp_malloc , rcx
pop rcx
mov rdi, rax
or rax, rax
jz bad
clc
jmp exit
bad:
stc
exit:
ret
XMemAlloc ENDP
in the above snippet, i get a syntax error in the INVOKE line (A2008)
second instance…
myCopy PROC
pushad
mov rsi, RCX
mov RCX, [rsi] ; number of DWords to copy, not including the initial length
DWord
inc RCX ; add 1 for initial length DWord
cld
rep movsd [rdi], [rsi]
popad
ret
myCopy ENDP
here pushad complains…
On Thu, Dec 18, 2008 at 4:12 PM, Tim Roberts wrote:
> amitr0 wrote:
> >
> > i have a portion of assembly in my driver. So I moved it out into a
> > .asm file for easier compilation with 64 bits. the compiler gives me
> > erros fro INVOKE, pushad, popad. what are the equivalents in 64 bits
> > please?
>
> It’s not that easy. The assembly language is different. Similar, but
> different. Tell us more about what the assembler does, or even post the
> whole clip here, and we can advise you on how best to proceed. There
> are intrinsic functions available for many such tasks.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
–
- amitr0
For amd64, the registers should be individually saved and you should create .pdata entries as appropriate (e.g. rush rbx; .pushreg rbx). See the WDK documentation on the amd64 calling convention.
? S
-----Original Message-----
From: Tim Roberts
Sent: Thursday, December 18, 2008 16:12
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] asm to c++
amitr0 wrote:
>
> i have a portion of assembly in my driver. So I moved it out into a
> .asm file for easier compilation with 64 bits. the compiler gives me
> erros fro INVOKE, pushad, popad. what are the equivalents in 64 bits
> please?
It’s not that easy. The assembly language is different. Similar, but
different. Tell us more about what the assembler does, or even post the
whole clip here, and we can advise you on how best to proceed. There
are intrinsic functions available for many such tasks.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
It is probably a masm maco to push registers and call. It won’t directly translate to x64.
? S
-----Original Message-----
From: Martin O’Brien
Sent: Thursday, December 18, 2008 16:14
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] asm to c++
‘pushad’ and ‘popad’ aren’t supported for x86_64. I’m not exactly sure
what ‘INVOKE’ is, but given that it’s in all CAPITALS, I assume that it
is a ML directive that does something shorthand form of a call or
whatnot. If so, I would say that the odds are excellent that it isn’t
supported by ML64, though you’d have to check the documentation,
assuming that it can be found, to be certain.
In the case of the two instructions, while conceptually you could
replace pushad/popfd with a sequence of push/pops, it almost certainly
would not make any sense due to differences between the architectures.
You might want to read up on the calling convention for x86_64:
http://msdn.microsoft.com/en-us/library/ms235286(VS.80).aspx
Assembler does not port (correctly) the way it sounds like you are going
about it.
Good luck,
mm
amitr0 wrote:
> hi folks,
>
> i have a portion of assembly in my driver. So I moved it out into a .asm
> file for easier compilation with 64 bits. the compiler gives me erros
> fro INVOKE, pushad, popad. what are the equivalents in 64 bits please?
>
> thanks
>
> AB
>
>
>
>
> On Thu, Dec 4, 2008 at 8:33 PM, Joseph M. Newcomer
> > wrote:
>
> I wrote device drivers 43 years ago (I didn’t know they were called
> “device
> drivers” then; my boss handed me a hardware manual and said “get
> this thing
> to talk to the machine”). With one exception, a research system in
> 1975,
> every driver I wrote was in assembly code. Spending 10 hours in
> front of a
> machine examining memory by flipping address switches and hitting the
> “examine” button, in a cold computer room, was State Of The Art
> debugging.
> I have written a bit of assembler since, for example, to support an
> embedded
> system on a 68020, to build a debugger interface on an TMX30C90, and
> to do
> some really weird and wondrous things that no compiler could ever
> generate.
> But the last time I wrote anything like assembly code was using an __asm
> insertion to insert a weird x86 instruction inline (it was in a C
> function).
> This is not at all “writing in assembly code”. You can even write
> code like
> WRITE_REGISTER_xxx entirely in “C”, by using no-prolog and _asm
> insertions,
> which again is not really “writing in assembly code” but you need to get
> down-and-dirty to get that ‘lock’ prefix in place. But note that
> you don’t
> call anything from it; it is a “leaf” of the call tree. You need
> occasionally to deal with close-to-the-metal phenomena, but
> assembly-code-as-a-way-of-life is not a healthy place to be.
>
> But today, there is no justification for writing anything in the driver
> world in assembler except the extremely rare-and-exotic couple
> lines. And
> even then, compilers have intrinsics for most of the extremely rare
> situations where you need high-performance instructions. If someone
> came to
> me and wanted to write a driver in assembler, I’d require a
> “justification
> document” that would be about half an order of magnitude harder to write
> than the assembly code itself before giving permission. It would
> pay off in
> the long run. It keeps the macho types who think “real programmers
> write in
> assembly code” under some semblance of control.
>
> Except for device drivers (and except for using a C-like language
> 1975-1977
> for drivers), I have worked in high-level languages for everything
> I’ve done
> at the application level for most of the last 40 years. The longer I
> program, the less I believe anyone who says that you have to write in
> assembly code for performance, except in some VERY rare and extreme
> situations which always involve inner loops of computationally intense
> functions. Drivers are almost never computationally intense. The
> tricks we
> had to play on 0.1MIPS machines (or 40KIPS machines) no longer apply
> when
> were are up at the range of 2-5GIPS and that’s per core.
>
> Let’s see: horses. You think pollution from cars is bad? Have
> you seen
> the descriptions of what the equine pollution would be in New York if we
> traveled by horse? Have you ever had to stay up all night with a
> sick car?
> Do emergency surgery on a car? Walk your car for an hour after you
> get home
> while it cools down? I have friends who have had or still have
> horses, and
> I hear the stories. No, I cannot imagine ever wanting to do this,
> under any
> conditions imaginable. Have you ever biked in the rain? Think of
> riding a
> horse in the rain as being like biking in the rain, except for the
> additional smell of wet horse. And did you ever need a giant
> pooper-scooper
> for your bike? Or your car? Note that you don’t need to feed your car
> several times a day, make sure it has water, or curry it (the only
> thing I
> curry is chicken), and clean up after it whether you use it or not.
>
> Exercise is for people who can move without pain (I think hard before
> walking over to the printer, ten feet away).
>
> I love the outdoors, see my office site
> http://www.flounder.com/office.htm
> (last two photos), but I also have wireless connectivity; I don’t
> program
> using a keypunch on the back porch and send the cards off to be run
> overnight, and I don’t write in assembly code.
> joe
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> mailto:xxxxx
> [mailto:xxxxx@lists.osr.com
> mailto:xxxxx] On Behalf Of Lyndon J Clarke
> Sent: Thursday, December 04, 2008 6:40 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] asm to c++
>
> Hey Jo, Quite! I feel this is like, a bit of an hmm that’s a bit
> interesting question, but then, I remember my age, and the decade, and I
> just cant figure out why anyone would want do it in the first place.
> Oh take
>
> me back, oh, must be 20 years now, and the idea made sense, lots of
> sense,
> to a young man at the time ![]()
>
> But you’ve said something even more interesting? Don’t you think it
> would be
>
> great to be able to go to work by horse? I mean, fresh air,
> exercise, man at
>
> one with nature, all that … it sounds great to me and I cant even
> stand
> (or sit) horses.
>
> Cheers!
>
> “Joseph M. Newcomer” > mailto:xxxxx> wrote in message
> news:xxxxx@ntdev…
> Kind of scary, thinking about writing anything in assembly code in 2008
> (almost 2009!). Any day now, we’ll be saddling horses for the daily
> commute.
>
> Since you have not shown any of the code, such as the call that
> doesn’t work
>
> or the declaration of the function that isn’t found, it is going to be
> difficult to figure out what you are doing.
>
> Take the advice of looking in the .cod files!
>
> joe
>
>
>
>
> From: xxxxx@lists.osr.com
> mailto:xxxxx
> [mailto:xxxxx@lists.osr.com
> mailto:xxxxx] On Behalf Of Mark S. Edwards
> Sent: Thursday, December 04, 2008 3:32 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] asm to c++
>
> Not sure if name mangling is your problem.
>
> What I would suggest is to follow the /Fa path for investigation.
> Compile a
>
> C++ file that includes something that calls your C++ function and
> look at
> the resultant .COD file. The .COD files can sometimes be enlightening.
>
> Mark.
>
> At 20:24 04/12/2008, amitr0 wrote:
>
>
> mark,
>
> thanks for the reply.
>
> 1. it is not C, but c++ function I want to call.
> 2. I am sure it is the name angling causing this, but even when we do an
> extern “C” it doesnt work.
> 3. In the asm file we are using PROTOS no extern, would that matter?
>
> Thanks
>
> amitr0
>
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, Mark S. Edwards
> >
> wrote:
> Suggest you use the /Fa compiler option to generate an assembly
> listing of a
>
> C/C++ file you’re compiling, this should show you what is required.
> You’ll need to declare the C function as extern in the asm file.
> Where you
> will have to be careful is in the calling convention. Is the C function
> actually compiled__cdecl ? Or is it Pascal calling convention, or even
> __fastcall ?
> As the asm component these differences are your problem to get right.
> Mark.
>
>
>
> At 20:10 04/12/2008, amitr0 wrote:
> hi folks,
> i have seen many examples of c++/C calling assembly in divers, but I
> want to
>
> do the other way round, the only example I found at google doesnt
> seem to
> work, so any pointers?
> Thnks
> –
>
> —
> NTDEV is sponsored by OSR
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
> –
>
> - amitr0
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
> debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe,
> visit the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> –
>
> - amitr0
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>
Wouldn’t it have been easier to write RtlCopyMem? This looks like a prime
example of a really bad use of assembly code.
It has been 20 years since I have found it necessary to write assembly code
in a device driver, and in those days it was only required because C didn’t
have the intrinsics to write low-level code in MS-DOS.
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of amitr0
Sent: Thursday, December 18, 2008 7:29 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] asm to c++
tim,
here is the routine…
T_vp_malloc PROTO len:DWORD
XMemAlloc PROC
push rcx
INVOKE T_vp_malloc , rcx
pop rcx
mov rdi, rax
or rax, rax
jz bad
clc
jmp exit
bad:
stc
exit:
ret
XMemAlloc ENDP
in the above snippet, i get a syntax error in the INVOKE line (A2008)
second instance…
myCopy PROC
pushad
mov rsi, RCX
mov RCX, [rsi] ; number of DWords to copy, not including the initial length
DWord
inc RCX ; add 1 for initial length DWord
cld
rep movsd [rdi], [rsi]
popad
ret
myCopy ENDP
here pushad complains…
On Thu, Dec 18, 2008 at 4:12 PM, Tim Roberts wrote:
amitr0 wrote:
>
> i have a portion of assembly in my driver. So I moved it out into a
> .asm file for easier compilation with 64 bits. the compiler gives me
> erros fro INVOKE, pushad, popad. what are the equivalents in 64 bits
> please?
It’s not that easy. The assembly language is different. Similar, but
different. Tell us more about what the assembler does, or even post the
whole clip here, and we can advise you on how best to proceed. There
are intrinsic functions available for many such tasks.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
- amitr0
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.
amitr0 wrote:
tim,
here is the routine…
T_vp_malloc PROTO len:DWORD
XMemAlloc PROC
push rcxINVOKE T_vp_malloc , rcx
pop rcx
mov rdi, rax
or rax, rax
jz bad
clc
jmp exit
bad:
stc
exit:
ret
XMemAlloc ENDPin the above snippet, i get a syntax error in the INVOKE line (A2008)
It’s ridiculous to code something like this in assembler. All this does
is call T_vp_malloc, and set the carry flag based on whether it returns
zero. Since C code cannot detect the carry flag, this is useless,
unless it is called from yet more assembler.
You could replace this with:
void * XMemAlloc( size_t Size )
{
void * ptr = T_vp_malloc( Size );
if( !ptr )
{
// Do some error handling here – set a flag, throw an
exception.
}
return ptr;
}
second instance…
myCopy PROC
pushad
mov rsi, RCX
mov RCX, [rsi] ; number of DWords to copy, not including the initial
length DWord
inc RCX ; add 1 for initial length DWord
cld
rep movsd [rdi], [rsi]
popad
ret
myCopy ENDPhere pushad complains…
You do not need this at all. RtlMoveMemory expands to memmove, which
expands inline to a rep movsd, and it works in all of the build
environments.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
No one as asked the critical question: What could possibly justify
using two questionable techniques in a single driver?
As Joe and Tim have pointed out the assembly code is questionable in
a driver (or any program). There is seldom an efficiency gain from
coding in assembly code. I have never heard a claim that portability
is improved by coding in assembly before (it is not).
The use of C++ in a driver has been a frequent topic on this with the
use of C++ considered questionable by many of us. I will not repeat
the arguments, but there are issues in avoiding any C++ functions
which will cause background activity such as allocation and release
of memory unless the programmer provides the necessary custom support
routines and can guarantee that the routines will not be called at
inappropriate times (in the original driver and in any change made by
a subsequent maintenance programmer).
A single driver with both assembly code and C++ code seems to be a
textbook example of a development strategy with excessive risk and
very expensive long term maintenance. Remember that the maintenance
programers who work on this driver in the future must be experts in
not only device drivers (of the appropriate type), but also C++ and
assembly code.
30 years ago I used to be an application programmer working on a
large application program written entirely in PDP-11 assembler. It
was the first email program targeted for use by non-technical
users. The program included user interface code and an internal
attribute-value database. I spent years working on this program. I
was a good assembly language programmer. In a later job (27 years
ago) I was part of a team porting and optimizing a large (between
500,000 and 750,000 lines) FORTRAN system from IBM FORTRAN to VAX
FORTRAN and optimizing it for the VAX environment. One of the little
optimizations I did was rip out the bubble sorts of nearly sorted
data and put in calls to a little Quicksort routine I wrote. When I
finished the result was an order of magnitude increase in the
performance of parts of the system. My superiors on the project
decided that sorting was so important that I should spend some time
and write the Quicksort in VAX assembly and optimize it as much as
possible. I spent several days writing and debugging and tweaking
out instructions in a Quicksort implementation in assembly. It was
late the day I declared the routine done but before heading home I
decided to compile the FORTRAN version with the assembly listing
option turned on. The code produced by the FORTRAN compiler had two
instructions difference from my hand crafted version. A few minutes
with the VAX reference manual showed that the number of machine
cycles for the FORTRAN compilers instruction and my instructions was
identical. We used the FORTRAN Quicksort and abandoned all efforts
at assembly optimization everywhere in the port. The compiler
technology 27 years ago was good enough that the compiler could
produce code as good as an assembly programmer. (The BLISS-11
compiler years before this was better than a human assembly
programmer. It would come up with instruction optimizations that no
human would ever use.)
Since that project I have always had a good reason for writing
assembly code rather than a higher level language. It usually
amounts to a few inline machine code instructions dropped inline. (On
an 8088 based embedded system I used an embedded instructions with
the LOCK instruction prefix.) The only exception to the ‘few
instructions’ limit was drivers for RSX-11M and VMS since these
device drivers were traditionally written in assembly code.
At 03:10 PM 12/4/2008, amitr0 wrote:
hi folks,
i have seen many examples of c++/C calling assembly in divers, but I
want to do the other way round, the only example I found at google
doesnt seem to work, so any pointers?Thnks
–
- amitr0
— NTDEV is sponsored by OSR For our schedule of WDF, WDM,
debugging and other seminars visit: http://www.osr.com/seminars To
unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer