Problem with Inline assembly code on 64 bit architecture

Hey guys i’m on a project where i’ve to port my 32 bit driver to 64 bit platform. I’ve ported almost 95% of the code but now stuck with inline assembly code which was written for 32 Bit architecture. But now on 64 Bit Architecture when i try to build my ported driver i get ‘__asm’ keyword not >supported on this architecture error.

Can somebody help me to get through this problem please?

This is my inline asm code ,which i have to compile with 64 Bit driver.

_asm
{
Mov Ax, DiPlus11
Mov Cl, 4
Shr Ax, Cl
Mov Cx, Ax
Mov Ax, DiPlus16
Shl Ax, 1
Add Ax, Cx
Xor Cx, Cx
Cmp Ah, DiPlus18
Jnb ReturnWithError
Div Byte Ptr DiPlus18
Xchg Cl, Ah
Cmp Ah, DiPlus1A
Jnb ReturnWithError
Div Byte Ptr DiPlus1A
Mov ch, al
Mov dh, ah
Inc Cx
Mov CxR, Cx
Mov DxR , Dx
}

Please suggest me an approach to get through this problem.

There is no support for inline assembly under x64. Period. If you want to use assembly you need as separate asm file…

Anton Bassov

This is old news, there is no support for inline assembler in X64. In this
case I would decode the assembler and reproduce it in C if possible. Worst
case you will need to move the assembler code to a seperate assembler file
and build it that way.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

wrote in message news:xxxxx@ntdev…
> Hey guys i’m on a project where i’ve to port my 32 bit driver to 64 bit
> platform. I’ve ported almost 95% of the code but now stuck with inline
> assembly code which was written for 32 Bit architecture. But now on 64 Bit
> Architecture when i try to build my ported driver i get ‘__asm’ keyword
> not >supported on this architecture error.
>
> Can somebody help me to get through this problem please?
>
> This is my inline asm code ,which i have to compile with 64 Bit driver.
>
> _asm
> {
> Mov Ax, DiPlus11
> Mov Cl, 4
> Shr Ax, Cl
> Mov Cx, Ax
> Mov Ax, DiPlus16
> Shl Ax, 1
> Add Ax, Cx
> Xor Cx, Cx
> Cmp Ah, DiPlus18
> Jnb ReturnWithError
> Div Byte Ptr DiPlus18
> Xchg Cl, Ah
> Cmp Ah, DiPlus1A
> Jnb ReturnWithError
> Div Byte Ptr DiPlus1A
> Mov ch, al
> Mov dh, ah
> Inc Cx
> Mov CxR, Cx
> Mov DxR , Dx
> }
>
> Please suggest me an approach to get through this problem.
>

Sreejith writes about this in his blog here:

http://geekswithblogs.net/kernelmode/archive/2008/03/07/120340.aspx

C
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: 13 October 2008 13:35
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Problem with Inline assembly code on 64 bit architecture

There is no support for inline assembly under x64. Period. If you want to
use assembly you need as separate asm file…

Anton Bassov


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

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3517 (20081013) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3517 (20081013) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

See the article from The NT Insider on porting driver to x64, which sums up just about all the salient points:

http://www.osronline.com/article.cfm?id=265

Peter
OSR

xxxxx@gmail.com wrote:

Hey guys i’m on a project where i’ve to port my 32 bit driver to 64 bit platform. I’ve ported almost 95% of the code but now stuck with inline assembly code which was written for 32 Bit architecture. But now on 64 Bit Architecture when i try to build my ported driver i get ‘__asm’ keyword not >supported on this architecture error.

Can somebody help me to get through this problem please?

This is my inline asm code ,which i have to compile with 64 Bit driver.

_asm
{
Mov Ax, DiPlus11
Mov Cl, 4
Shr Ax, Cl
Mov Cx, Ax
Mov Ax, DiPlus16
Shl Ax, 1
Add Ax, Cx
Xor Cx, Cx
Cmp Ah, DiPlus18
Jnb ReturnWithError
Div Byte Ptr DiPlus18
Xchg Cl, Ah
Cmp Ah, DiPlus1A
Jnb ReturnWithError
Div Byte Ptr DiPlus1A
Mov ch, al
Mov dh, ah
Inc Cx
Mov CxR, Cx
Mov DxR , Dx
}

Please suggest me an approach to get through this problem.

The correct approach is to rewrite this in C, something you should have
done long ago. This is 16-bit assembler code, and the compiler could
have done this much more intelligently without your help.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> The correct approach is to rewrite this in C, something you should have done long ago.

Well, there are some things that cannot be done in C, but the OP’s code does not seem to be doing any of them. Assuming that this is a real code, the very purpose of using assembly here is, indeed, “questionable”, so to say…

Anton Bassov

Thx guys,i’ll re-write the code in C.Here is the complte asm program that i had posted earlier.

int GetOrgSector ( int Drive, unsigned char * Buff,
int * Head, int * Track, int * Sector )
{
unsigned short int DiPlus11, DiPlus16;
unsigned char DiPlus18, DiPlus1A ;
unsigned char Temp1 = 4 , Temp2 = 1 ;
unsigned short int DxR, CxR ;

DiPlus11 = * ( ( unsigned int * ) &Buff [0x0011] ) ;
DiPlus16 = * ( ( unsigned int * ) &Buff [0x0016] ) ;
DiPlus18 = Buff [0x0018] ;
DiPlus1A = Buff [0x001A] ;

if ( Drive >= 0x80 )
{
* Head = 0 ;
* Track = Buff [0x0145] ;
* Sector = Buff [0x0144] ;
return ( TRUE ) ;
}

_asm
{
Mov Ax, DiPlus11
Mov Cl, 4
Shr Ax, Cl
Mov Cx, Ax
Mov Ax, DiPlus16
Shl Ax, 1
Add Ax, Cx
Xor Cx, Cx
Cmp Ah, DiPlus18
Jnb ReturnWithError
Div Byte Ptr DiPlus18
Xchg Cl, Ah
Cmp Ah, DiPlus1A
Jnb ReturnWithError
Div Byte Ptr DiPlus1A
Mov ch, al
Mov dh, ah
Inc Cx
Mov CxR, Cx
Mov DxR , Dx
}

* Head = DxR ;
* Track = CxR ;
* Sector = CxR ;
* Head >>= 8 ;
* Track >>= 8 ;
* Sector &= 0x00FF ;

return ( TRUE ) ;
ReturnWithError:
return ( FALSE ) ;
}

I’m stuck at the last asm line (Mov DxR , Dx) Does DX register gets effected by operations done in AX register? The last line is reading the DX register and it’s being assigned to *Head. What value DX holds after all those operations? Sorry if this sounds lame,but i’ve never written anything in asm before,this is completely a new experience to me…

oops sorry i didn’t see the DH register being set…Thx for all your help guys.