Hi All,
This is Manesh from India. Later on i have been assigned to a porting
task of a 32-bit application(x86) to 64-bit version of Vista(AMD64).
I'm very new to
this & now facing problems with 32-bit Inline assembly code.
1) I have a situation where my 32-bit inline assembly code looks like
this
long int var;
__asm mov var, EAX
table->g[0] = var;
__asm mov var,EBX
table->g[1] = var;
__asm mov var, ECX
table->g[2] = var;
where this table->g[] is something specific to my application.
As far as i know, the only way to get around this is to completely
rewrite this to a .asm file & link it seperately using ml64 and call
it thru a function defined in my source file.
1) Now while moving this to a seperate .asm file, is it possible to
pass these registers values(EAX,EBX) as the parameter to the
function(defined in d source file) and handle it seperately in
the .asm file( since i need to assign the return value of VAR to
table-
>g[]).
Ex: in source file:
============
testFunc(var, EAX);
in .asm file:
========
************************************
..code
testFunc PROC x:QWORD, y:SDWORD
cmp y, 'eax'
je FOR_EAX
cmp y, 'ebx'
je FOR_EBX
FOR_EAX:
mov x, rax
RET
FOR_EBX:
mov x, RBX
RET
testFunc ENDP
END ; // This is what i was able to write as a sample. I know this
wont work. But want to confirm whether my approach is right..
*****************************
2) Now if need to move this to a seperate .asm file, whether i should
use the 32-bit register like EAX,ABX or the 64-bit register like RAX,
RBX..
I'm very new to assembly coding & couldn't find any manual on the
Assembly coding in AMD64.
It would have been great if could help me by writing a sample .asm
file with my above scenario. That would help me a lot.
Any reply will be hugely appreciated!!
-Manesh
|
|
0
|
|
|
|
Reply
|
spamtrap2 (1628)
|
6/2/2008 4:50:37 PM |
|
On Jun 2, 6:50 pm, Manesh S <spamt...@crayne.org> wrote:
> Hi All,
>
> This is Manesh from India. Later on i have been assigned to a porting
> task of a 32-bit application(x86) to 64-bit version of Vista(AMD64).
> I'm very new to
> this & now facing problems with 32-bit Inline assembly code.
>
> 1) I have a situation where my 32-bit inline assembly code looks like
> this
>
> long int var;
> __asm mov var, EAX
> table->g[0] = var;
> __asm mov var,EBX
> table->g[1] = var;
> __asm mov var, ECX
> table->g[2] = var;
>
> where this table->g[] is something specific to my application.
>
> As far as i know, the only way to get around this is to completely
> rewrite this to a .asm file & link it seperately using ml64 and call
> it thru a function defined in my source file.
>
> 1) Now while moving this to a seperate .asm file, is it possible to
> pass these registers values(EAX,EBX) as the parameter to the
> function(defined in d source file) and handle it seperately in
> the .asm file( since i need to assign the return value of VAR to
> table-
>
> >g[]).
>
> Ex: in source file:
> ============
>
> testFunc(var, EAX);
>
> in .asm file:
> ========
> ************************************
> .code
>
> testFunc PROC x:QWORD, y:SDWORD
>
> cmp y, 'eax'
> je FOR_EAX
>
> cmp y, 'ebx'
> je FOR_EBX
>
> FOR_EAX:
> mov x, rax
> RET
>
> FOR_EBX:
> mov x, RBX
> RET
> testFunc ENDP
>
> END ; // This is what i was able to write as a sample. I know this
> wont work. But want to confirm whether my approach is right..
> *****************************
>
> 2) Now if need to move this to a seperate .asm file, whether i should
> use the 32-bit register like EAX,ABX or the 64-bit register like RAX,
> RBX..
>
> I'm very new to assembly coding & couldn't find any manual on the
> Assembly coding in AMD64.
>
> It would have been great if could help me by writing a sample .asm
> file with my above scenario. That would help me a lot.
>
> Any reply will be hugely appreciated!!
>
> -Manesh
Hello Manesh,
first of all, keep in mind that ML64 does support PROC directive in
very limited way. See this:
http://www.masm32.com/board/index.php?topic=7932.0
In other words, you can use PROC, but without function arguments. You
must address the arguments directly. First four arguments go in RCX,
RDX, R8, and R9. See this for detailed description:
http://msdn.microsoft.com/en-us/magazine/cc300794.aspx
And your function:
testFunc PROC
cmp rcx, 12345678h ; first parametr goes in RCX (QWORD)
je x_is_equal
cmp edx, -12345678h ; second in EDX (SDWORD)
jl y_is_less
mov rax, -1 ; return value
ret
y_is_less:
mov rax, -12345678h
ret
x_is_equal:
mov rax, 12345678h
ret
testFunc ENDP
As for the manual: Learn 32-bit assembly first, there are lots of
books. All you need to learn 64-bit assembly are different calling
conventions.
|
|
0
|
|
|
|
Reply
|
MazeGen
|
6/3/2008 7:49:32 AM
|
|
Manesh wrote:
> I'm very new to assembly coding & couldn't find any manual on the
> Assembly coding in AMD64.
The System V ABI is an interesting read.
( http://www.x86-64.org/documentation/abi.pdf )
I don't know how much it has in common with the Win64 ABI.
|
|
0
|
|
|
|
Reply
|
Noob
|
6/4/2008 10:46:00 AM
|
|
Noob wrote:
> Manesh wrote:
>
>> I'm very new to assembly coding & couldn't find any manual on the
>> Assembly coding in AMD64.
>
> The System V ABI is an interesting read.
>
> ( http://www.x86-64.org/documentation/abi.pdf )
>
> I don't know how much it has in common with the Win64 ABI.
>
Very little.
For Win64, see:
http://msdn.microsoft.com/en-us/library/ms794533.aspx
-hpa
|
|
0
|
|
|
|
Reply
|
H
|
6/4/2008 11:46:03 PM
|
|
Hi All,
Thanks a lot for helping with ur valuable comments..
MazeGen,
First things first.. ur reply were extremely helpful for me. I was
able to write the PROC function into the new .asm file. But i have
some doubts & need some clarifications.
In my source file, i have changed the function call to be
void Assembly64(var, RAX); // Also declared the fucntio in the
corresponding header file
table->g[0] = var;
void Assembly64(var, RBX);
table->g[1] = var;
Now in my .asm file, since the first argument goes in RCX & the 2nd
argument to RDX; i have written like this:
..code
Assembly64 PROC
cmp RDX, 'RAX' // here i try to compare the value in RDX(RAX) & the
string 'RAX'( is it posssible or does it look stupid :))
je FOR_EAX
cmp RDX, 'RBX'
je FOR_EBX
FOR_EAX:
mov RCX, RDX // since RCX has var, i'm moving RDX value(RAX) to RCX
RET
FOR_EBX:
mov RCX, RDX
RET
Assembly64 ENDP
END ;
Whether this will work?? waiting for ur reply..
- Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/5/2008 8:10:00 AM
|
|
Hi All,
Can i use String MOV Intrinsic Functions like (__movsb, __movsw,
__movsd, __movsq)for translating this assembly code "__asm mov var,
EAX "??
This is more a general question...
-Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/6/2008 6:05:11 AM
|
|
Manesh, if I got you right, all you need is a function which loads
"var" with a value from specified register? In theory, it would look
like this:
C part:
#define RAX_REGISTER 0
#define RBX_REGISTER 1
void Assembly64(&var, RAX_REGISTER);
Asm part:
RAX_REGISTER EQU 0
RBX_REGISTER EQU 1
Assembly64 PROC ; RCX holds "var" address in memory, RDX register code
cmp rdx, RAX_REGISTER
je FOR_EAX
cmp rdx, RBX_REGISTER
je FOR_EBX
FOR_EAX:
mov [rcx], rax
ret
FOR_EBX:
mov [rcx], rbx
ret
Assembly64 ENDP
However, I'm not sure if this code can work for you - are you sure
that while you do this:
void Assembly64(var, RAX_REGISTER);
table->g[0] = var;
The RBX (EBX) remains the same so you can do this?
void Assembly64(var, RBX_REGISTER);
I mean, the compiler can generate code which destroys RBX.
The best solution would be to completely rewrite the code so that you
can get rid of machine registers.
If it is not possible, another way would be porting the complete part
of code where you use __asm to assembly. This would need porting the
"table" structure to assembly, too.
|
|
0
|
|
|
|
Reply
|
MazeGen
|
6/6/2008 6:50:42 AM
|
|
On Jun 5, 11:05 pm, Manesh S <spamt...@crayne.org> wrote:
> Hi All,
>
> Can i use String MOV Intrinsic Functions like (__movsb, __movsw,
> __movsd, __movsq)for translating this assembly code "__asm mov var,
> EAX "??
>
> This is more a general question...
>
> -Manesh
Depends on what you mean by "translating". If you intend to replace
MOV [memory], EAX by a string instruction, then only STOSB/W/D/Q has a
memory destination operand (var's address should go to rDI) and a
register source operand (AL/rAX).
Alex
|
|
0
|
|
|
|
Reply
|
Alexei
|
6/6/2008 8:17:38 AM
|
|
On Jun 6, 11:50�am, MazeGen <spamt...@crayne.org> wrote:
> Manesh, if I got you right, all you need is a function which loads
> "var" with a value from specified register? In theory, it would look
> like this:
>
> C part:
>
> #define RAX_REGISTER 0
> #define RBX_REGISTER 1
>
> void Assembly64(&var, RAX_REGISTER);
>
> Asm part:
>
> RAX_REGISTER EQU 0
> RBX_REGISTER EQU 1
>
> Assembly64 PROC ; RCX holds "var" address in memory, RDX register code
> �cmp rdx, RAX_REGISTER
> �je FOR_EAX
>
> �cmp rdx, RBX_REGISTER
> �je FOR_EBX
>
> FOR_EAX:
> �mov [rcx], rax
> �ret
>
> FOR_EBX:
> �mov [rcx], rbx
> �ret
> Assembly64 ENDP
>
> However, I'm not sure if this code can work for you - are you sure
> that while you do this:
>
> void Assembly64(var, RAX_REGISTER);
> table->g[0] = var;
>
> The RBX (EBX) remains the same so you can do this?
>
> void Assembly64(var, RBX_REGISTER);
>
> I mean, the compiler can generate code which destroys RBX.
>
> The best solution would be to completely rewrite the code so that you
> can get rid of machine registers.
>
> If it is not possible, another way would be porting the complete part
> of code where you use __asm to assembly. This would need porting the
> "table" structure to assembly, too.
Hi MazeGen,
Let me exaclty show my 32-bit inline code. It looks like this:
void *evLoadReg (struct evCpuRegisters *table)
{
long int var;
__asm mov var, EAX
table->g[0] = var;
__asm mov var, EBX
table->g[1] = var;
__asm mov var, ECX
table->g[2] = var;
__asm mov var, EDX
table->g[3] = var;
__asm mov var, ESI
table->g[4] = var;
__asm mov var, EDI
table->g[5] = var;
__asm mov var, EBP
table->g[6] = var;
return (void *)NULL;
}
This is what my exact code looks like. Now the previous approach is
what i could think of. Please let me know ur comments after seeing the
code.
I need more one help from u. I know i'm disturbng u a lot.
I have compiled the asm file using the following paramaters, "ml64 /c
Assembly64.asm". Now i have to add this to my make file & gets it
compiled. I hope i'll do that soon. Since this .c file gets linked to
a seperate exe, how do i link this .asm file? I have worked on this
before, that time i do wrote some dump code & tried progressing on my
build. At some point while linking one exe(where this particular .c
file was used), got some liniking error. Since it had the Assembly64
function call in that, it generated a linker error stating "
unresolved symbol : Assembly64".
Any idea on this?
-Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/10/2008 7:45:29 AM
|
|
On Jun 10, 12:45 am, Manesh S <spamt...@crayne.org> wrote:
> Hi MazeGen,
>
> Let me exaclty show my 32-bit inline code. It looks like this:
>
> void *evLoadReg (struct evCpuRegisters *table)
> {
> long int var;
> __asm mov var, EAX
> table->g[0] = var;
> __asm mov var, EBX
> table->g[1] = var;
> __asm mov var, ECX
> table->g[2] = var;
> __asm mov var, EDX
> table->g[3] = var;
> __asm mov var, ESI
> table->g[4] = var;
> __asm mov var, EDI
> table->g[5] = var;
> __asm mov var, EBP
> table->g[6] = var;
>
> return (void *)NULL;
>
> }
>
> This is what my exact code looks like. Now the previous approach is
> what i could think of. Please let me know ur comments after seeing the
> code.
You know what? In C there're two functions: setjmp() and longjmp().
The structure of type jmp_buf (which these functions use) contains
fields for most if not all general-purpose registers of the CPU.
If you want to read from the registers, just do setjmp() and look at
what you got in the structure.
If you want to write to the registers, first populate the structure
with the desired register values and then do longjmp(). Beware,
longjmp() changes rIP and rSP, so you can't have complete junk in the
respective fields of the structure. You should also make sure that you
don't corrupt non-volatile registers (consult your C/C++ compiler's
documentation) when you're done with what you're trying to do.
Otherwise you won't be able to resume execution in the C/C++ code.
Alex
|
|
0
|
|
|
|
Reply
|
Alexei
|
6/11/2008 5:38:51 AM
|
|
Manesh S <spamtrap@crayne.org> wrote:
>
>Let me exaclty show my 32-bit inline code. It looks like this:
>
>void *evLoadReg (struct evCpuRegisters *table)
>{
> long int var;
> __asm mov var, EAX
> table->g[0] = var;
> __asm mov var, EBX
> table->g[1] = var;
> __asm mov var, ECX
> table->g[2] = var;
> __asm mov var, EDX
> table->g[3] = var;
> __asm mov var, ESI
> table->g[4] = var;
> __asm mov var, EDI
> table->g[5] = var;
> __asm mov var, EBP
> table->g[6] = var;
>
> return (void *)NULL;
>}
>
>This is what my exact code looks like. Now the previous approach is
>what i could think of. Please let me know ur comments after seeing the
>code.
This code does not do what you think it does. Remember that the compiled
code has to use registers just to do its normal job. By the time you get
to EBX, the compiler has already trashed eax and ecx in order to do the
first save. By the time you get to ECX, it has also trashed edx.
What are you really trying to do here? What good does it do you to
snapshot the CPU registers?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
6/11/2008 5:55:08 AM
|
|
On Jun 11, 10:55�am, Tim Roberts <spamt...@crayne.org> wrote:
> Manesh S �<spamt...@crayne.org> wrote:
>
>
>
>
>
>
>
> >Let me exaclty show my 32-bit inline code. It looks like this:
>
> >void *evLoadReg (struct evCpuRegisters *table)
> >{
> > � �long int var;
> > � � � � __asm mov � � � � �var, � EAX
> > � �table->g[0] = var;
> > � � __asm mov � � � � var, � EBX
> > � �table->g[1] = var;
> > � � __asm mov � � � � var, � ECX
> > � �table->g[2] = var;
> > � � __asm mov � � � � var, � EDX
> > � �table->g[3] = var;
> > � � __asm mov � � � � var, � ESI
> > � �table->g[4] = var;
> > � � __asm mov � � � � var, � EDI
> > � �table->g[5] = var;
> > � � __asm mov � � � � var, � EBP
> > � �table->g[6] = var;
>
> > � �return (void *)NULL;
> >}
>
> >This is what my exact code looks like. Now the previous approach is
> >what i could think of. Please let me know ur comments after seeing the
> >code.
>
> This code does not do what you think it does. �Remember that the compiled
> code has to use registers just to do its normal job. �By the time you get
> to EBX, the compiler has already trashed eax and ecx in order to do the
> first save. �By the time you get to ECX, it has also trashed edx.
>
> What are you really trying to do here? �What good does it do you to
> snapshot the CPU registers?
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.- Hide quoted text -
>
> - Show quoted text -
Hi Tim,
I'm working on porting a 32-bit application to 64-bit in Vista 64. So
the previous 32-bit inline code works fine in the 32-bit mode.
So rite now, i'm stuck with these inline codes & tryin to rewrite this
into a asm file & get thru with this. Due to my minimal knowledge in
assembly language, the above approach was i could think of. Previously
in the thread, Mazegen have already hinted on this problem.
Any help will be appreciated..
Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/11/2008 7:46:50 AM
|
|
On Jun 11, 10:38�am, "Alexei A. Frounze" <spamt...@crayne.org> wrote:
> On Jun 10, 12:45 am, Manesh S �<spamt...@crayne.org> wrote:
>
>
>
>
>
> > Hi MazeGen,
>
> > Let me exaclty show my 32-bit inline code. It looks like this:
>
> > void *evLoadReg (struct evCpuRegisters *table)
> > {
> > � � long int var;
> > � � � � �__asm mov � � � � �var, � EAX
> > � � � � table->g[0] = var;
> > � � � � �__asm mov � � � � var, � EBX
> > � � � � table->g[1] = var;
> > � � � � �__asm mov � � � � var, � ECX
> > � � � � table->g[2] = var;
> > � � � � �__asm mov � � � � var, � EDX
> > � � � � table->g[3] = var;
> > � � � � �__asm mov � � � � var, � ESI
> > � � � � table->g[4] = var;
> > � � � � �__asm mov � � � � var, � EDI
> > � � � � table->g[5] = var;
> > � � � � �__asm mov � � � � var, � EBP
> > � � � � table->g[6] = var;
>
> > � � � � return (void *)NULL;
>
> > }
>
> > This is what my exact code looks like. Now the previous approach is
> > what i could think of. Please let me know ur comments after seeing the
> > code.
>
> You know what? In C there're two functions: setjmp() and longjmp().
> The structure of type jmp_buf (which these functions use) contains
> fields for most if not all general-purpose registers of the CPU.
>
> If you want to read from the registers, just do setjmp() and look at
> what you got in the structure.
>
> If you want to write to the registers, first populate the structure
> with the desired register values and then do longjmp(). Beware,
> longjmp() changes rIP and rSP, so you can't have complete junk in the
> respective fields of the structure. You should also make sure that you
> don't corrupt non-volatile registers (consult your C/C++ compiler's
> documentation) when you're done with what you're trying to do.
> Otherwise you won't be able to resume execution in the C/C++ code.
>
> Alex- Hide quoted text -
>
> - Show quoted text -
Hi Alex,
As many suggested in this thread, the above approach didnt worked. And
i'm stuck again. I was looking at setjmp() & longjmp routines for the
past two days. I understood the concept behind it, but i'm finding it
very difficult to implement on my above code.
Can u help me in this by writting a sample code of how i should be
approaching the above code by using these routines?
Any help will be appreciated..
-Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/22/2008 1:46:09 PM
|
|
In message
<cece2601-372a-449b-b3db-e79465a5e4b5@t54g2000hsg.googlegroups.com>, Manesh
S <spamtrap@crayne.org> wrote:
>> >Let me exaclty show my 32-bit inline code. It looks like this:
>>
>> >void *evLoadReg (struct evCpuRegisters *table)
>> >{
>> > long int var;
>> > __asm mov var, EAX
>> > table->g[0] = var;
>> > __asm mov var, EBX
>> > table->g[1] = var;
>> > __asm mov var, ECX
>> > table->g[2] = var;
>> > __asm mov var, EDX
>> > table->g[3] = var;
>> > __asm mov var, ESI
>> > table->g[4] = var;
>> > __asm mov var, EDI
>> > table->g[5] = var;
>> > __asm mov var, EBP
>> > table->g[6] = var;
>>
>> > return (void *)NULL;
>> >}
> Hi Tim,
>
> I'm working on porting a 32-bit application to 64-bit in Vista 64. So
> the previous 32-bit inline code works fine in the 32-bit mode.
> So rite now, i'm stuck with these inline codes & tryin to rewrite this
> into a asm file & get thru with this. Due to my minimal knowledge in
> assembly language, the above approach was i could think of. Previously
> in the thread, Mazegen have already hinted on this problem.
>
> Any help will be appreciated..
This function has undefined behaviour, and it's behaviour liable to change
depending on the compiler version and options. And even if it were to be
determined what it did, the effect of calling it from a high level language
(eg C/C++) are likely to be undefined and unpredictable. Is this used in
generating a random number? Or are the results unused?
I suggest you give up trying to convert this function, and instead examine
it's callers to work out what needs to be done to make them work.
|
|
0
|
|
|
|
Reply
|
Timothy
|
6/22/2008 8:12:43 PM
|
|
On Jun 22, 6:46 am, Manesh S <spamt...@crayne.org> wrote:
> On Jun 11, 10:38 am, "Alexei A. Frounze" <spamt...@crayne.org> wrote:
>
>
>
> > On Jun 10, 12:45 am, Manesh S <spamt...@crayne.org> wrote:
>
> > > Hi MazeGen,
>
> > > Let me exaclty show my 32-bit inline code. It looks like this:
>
> > > void *evLoadReg (struct evCpuRegisters *table)
> > > {
> > > long int var;
> > > __asm mov var, EAX
> > > table->g[0] = var;
> > > __asm mov var, EBX
> > > table->g[1] = var;
> > > __asm mov var, ECX
> > > table->g[2] = var;
> > > __asm mov var, EDX
> > > table->g[3] = var;
> > > __asm mov var, ESI
> > > table->g[4] = var;
> > > __asm mov var, EDI
> > > table->g[5] = var;
> > > __asm mov var, EBP
> > > table->g[6] = var;
>
> > > return (void *)NULL;
>
> > > }
>
> > > This is what my exact code looks like. Now the previous approach is
> > > what i could think of. Please let me know ur comments after seeing the
> > > code.
>
> > You know what? In C there're two functions: setjmp() and longjmp().
> > The structure of type jmp_buf (which these functions use) contains
> > fields for most if not all general-purpose registers of the CPU.
>
> > If you want to read from the registers, just do setjmp() and look at
> > what you got in the structure.
>
> > If you want to write to the registers, first populate the structure
> > with the desired register values and then do longjmp(). Beware,
> > longjmp() changes rIP and rSP, so you can't have complete junk in the
> > respective fields of the structure. You should also make sure that you
> > don't corrupt non-volatile registers (consult your C/C++ compiler's
> > documentation) when you're done with what you're trying to do.
> > Otherwise you won't be able to resume execution in the C/C++ code.
>
> > Alex- Hide quoted text -
>
> > - Show quoted text -
>
> Hi Alex,
>
> As many suggested in this thread, the above approach didnt worked. And
> i'm stuck again. I was looking at setjmp() & longjmp routines for the
> past two days. I understood the concept behind it, but i'm finding it
> very difficult to implement on my above code.
>
> Can u help me in this by writting a sample code of how i should be
> approaching the above code by using these routines?
>
> Any help will be appreciated..
>
> -Manesh
You need to find out the layout of the jmp_buf structure. For that
you'll probably need to disassembly setjmp() and/or longjmp() to find
where each register goes. Sorry, I don't have the microsoft compiler
handy to provide more info here.
Then you do something like this:
#include <setjmp.h>
#include <stdio.h>
#include <string.h>
jmp_buf b;
jmp_buf b2;
// your assembly function
#if 0
#ifdef __cplusplus
extern "C" {
#endif
extern void asmFxn(void);
#ifdef __cplusplus
}
#endif
#else
void asmFxn(void)
{
// must have ret at the end.
}
#endif
// or you could generate the asm code on the fly and
// set this ptr to point to the instruction buffer
// (under windows the buffer's page must be executable)
void (*pAsmFxn)(void) = &asmFxn;
void ret(void)
{
// save register state after executing pAsmFxn():
// NOTE: not all registers can be saved by setjmp().
setjmp(b);
// return to C code in main():
longjmp(b2, 1);
}
void f(void)
{
// save register state for returning to C code in main():
memcpy(&b2, &b, sizeof(b));
// set registers for pAsmFxn():
//
// this code is based on the following jmp_buf layout
// of my 16-bit compiler:
// sp,ss,flags,cs,ip,bp,di,es,si,ds
//
// NOTE: not all registers can be set by longjmp().
// rSP[0] = &ret -- pAsmFxn() will return to ret()
**( (void(***)(void)) &b ) = &ret;
// rIP = pAsmFxn
*( (void(**)(void)) (4+(short*)&b) ) = pAsmFxn;
// rDI = 0xdede
*( (short*) (6+(short*)&b) ) = 0xdede;
// rSI = 0xcece
*( (short*) (8+(short*)&b) ) = 0xcece;
// execute pAsmFxn():
longjmp(b, 1); // 1 will go to rAX
}
int main(void)
{
int r;
r = setjmp(b);
if (r)
{
printf("executed asmFxn()\n");
}
else
{
printf("about to execute asmFxn()\n");
f();
}
return 0;
}
Alex
|
|
0
|
|
|
|
Reply
|
Alexei
|
6/23/2008 2:11:39 AM
|
|
Manesh S <spamtrap@crayne.org> wrote:
>
>I'm working on porting a 32-bit application to 64-bit in Vista 64. So
>the previous 32-bit inline code works fine in the 32-bit mode.
>So rite now, i'm stuck with these inline codes & tryin to rewrite this
>into a asm file & get thru with this. Due to my minimal knowledge in
>assembly language, the above approach was i could think of. Previously
>in the thread, Mazegen have already hinted on this problem.
The KEY problem, as I see it, is that you have not presented even the
slightest clue as to what this code is supposed to do. WHY are you saving
the register? What is eventually going to be done with those values?
The more we know about what you are really trying to do, the better the
advice we can offer. You will never find a solution by focussing very
narrowly on converting this one routine.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
6/24/2008 3:18:57 AM
|
|
On Jun 24, 8:18�am, Tim Roberts <spamt...@crayne.org> wrote:
> Manesh S �<spamt...@crayne.org> wrote:
>
>
>
> >I'm working on porting a 32-bit application to 64-bit in Vista 64. So
> >the previous 32-bit inline code works fine in the 32-bit mode.
> >So rite now, i'm stuck with these inline codes & tryin to rewrite this
> >into a asm file & get thru with this. Due to my minimal knowledge in
> >assembly language, the above approach was i could think of. Previously
> >in the thread, Mazegen have already hinted on this problem.
>
> The KEY problem, as I see it, is that you have not presented even the
> slightest clue as to what this code is supposed to do. �WHY are you saving
> the register? �What is eventually going to be done with those values?
>
> The more we know about what you are really trying to do, the better the
> advice we can offer. �You will never find a solution by focussing very
> narrowly on converting this one routine.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
Hi Tim,
I dont have much idea of what this resigters has to do with the
application. I was not working for this application, but got assigned
to this project very recently. So i dont have much inside details. But
whatever code that was given by me, was the assembly code for memory
management in the application.
I'll look into the code & let you know more information..
Thanks
Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/25/2008 7:41:28 AM
|
|
On Wed, 25 Jun 2008 00:41:28 -0700 (PDT)
Manesh S <spamtrap@crayne.org> wrote:
> I was not working for this application, but got assigned
> to this project very recently.
The routine itself simply stores the six general purpose registers in a
table designed for that purpose, and, by itself, is very easy to
convert. However, since the 64-bit registers are not only larger than
their 32-bit versions, but also there are 8 additional registers which
will need to be saved, you must upgrade the table definition, and
therefore every routine which refers to that table must also be
converted. Until you have located all such references, there is no way
to scope the size of the project.
--
Chuck
http://www.pacificsites.com/~ccrayne/charles.html
|
|
0
|
|
|
|
Reply
|
Charles
|
6/25/2008 8:21:10 PM
|
|
On Jun 26, 1:21�am, Charles Crayne <spamt...@crayne.org> wrote:
> On Wed, 25 Jun 2008 00:41:28 -0700 (PDT)
> Manesh S �<spamt...@crayne.org> wrote:
>
> > I was not working for this application, but got assigned
> > to this project very recently.
>
> The routine itself simply stores the six general purpose registers in a
> table designed for that purpose, and, by itself, is very easy to
> convert. However, since the 64-bit registers are not only larger than
> their 32-bit versions, but also there are 8 additional registers which
> will need to be saved, you must upgrade the table definition, and
> therefore every routine which refers to that table must also be
> converted. Until you have located all such references, there is no way
> to scope the size of the project.
>
> --
> Chuckhttp://www.pacificsites.com/~ccrayne/charles.html
Thanks charles..
So it's not just 6 or 7 registers that needs to be saved to the table
definition. So i need to upgrade the size of the table.
So do i need to convert all the registers or just the non-volatile
one's??
Thanks
Manesh
|
|
0
|
|
|
|
Reply
|
Manesh
|
6/26/2008 8:51:54 AM
|
|
On Thu, 26 Jun 2008 01:51:54 -0700 (PDT)
Manesh S <spamtrap@crayne.org> wrote:
> So do i need to convert all the registers or just the non-volatile
> one's??
Until you tell my why the application needs to save any registers at
all, I can't tell you which ones it does need to save. However, since
the 32-bit version saves all the 32-bit registers except eip and esp,
it would be reasonable to assume that the 64-bit version should save
all the 64-bit registers except rip and rsp.
Nevertheless, the point which I am still not sure that you understand
is, if your changes to the save routine do not match the changes which
somebody has to make to the restore routine, then thn converted
application will not work, and you will have to share the blame.
--
Chuck
http://www.pacificsites.com/~ccrayne/charles.html
|
|
0
|
|
|
|
Reply
|
Charles
|
6/26/2008 9:48:25 PM
|
|
|
19 Replies
436 Views
(page loaded in 0.204 seconds)
Similiar Articles: Writing Assembly Code in x64 - comp.lang.asm.x86Hi All, This is Manesh from India. Later on i have been assigned to a porting task of a 32-bit application(x86) to 64-bit version of Vista(AMD64). I... assembly for 64 bit processors - comp.lang.asm.x86All you need to learn 64-bit assembly are different calling conventions. ... ... comp.lang.asm.x86 Writing Assembly Code in ... to write assembly for 64-bit processors ... Anyone interested in x86-64 assembly? - comp.lang.asm.x86 ...Writing Assembly Code in x64 - comp.lang.asm.x86 Anyone interested in x86-64 assembly? - comp.lang.asm.x86 ... Writing Assembly Code in x64 - comp.lang.asm.x86 Grammar for ... NASM on WINXP x64 creating EXE - comp.lang.asm.x86Writing Assembly Code in x64 - comp.lang.asm.x86 NASM on WINXP x64 creating EXE - comp.lang.asm.x86 Writing Assembly Code in x64 - comp.lang.asm.x86 NASM on WINXP x64 ... 64 bit assembly m.s.bit and l.s.bit - comp.lang.asm.x86Writing Assembly Code in x64 - comp.lang.asm.x86 Hi All, This is Manesh from India. Later on i have been assigned to a porting task of a 32-bit application(x86) to 64-bit ... How to use Inline assembly on C64x+ - comp.dspWriting Assembly Code in x64 - comp.lang.asm.x86 How to use Inline assembly on C64x+ - comp.dsp Writing Assembly Code in x64 - comp.lang.asm.x86 I'm very new to this & now ... Return-Code of "system" on a 64-bit system - comp.lang.perl.misc ...Writing Assembly Code in x64 - comp.lang.asm.x86 Return-Code of "system" on a 64-bit system - comp.lang ... Writing Assembly Code in x64 - comp.lang.asm.x86 the .asm file ... Grammar for x86 assembly - comp.lang.asm.x86Writing Assembly Code in x64 - comp.lang.asm.x86 Grammar for x86 assembly - comp.lang.asm.x86 Writing Assembly Code in x64 - comp.lang.asm.x86 Writing Assembly Code in x64 ... MiniDumpWriteDump called from x64 process can generate x86 dump ...Hello, when calling MiniDumpWriteDump in a x64 process with the target process ... memset() bug for 32-bit code with sun4v ? - comp.unix.solaris ... MiniDumpWriteDump ... Problem in porting from 32 bit to 64 bit application - comp.os.ms ...Writing Assembly Code in x64 - comp.lang.asm.x86 Hi All, This is Manesh from India. Later on i have been assigned to a porting task of a 32-bit application(x86) to 64-bit ... How do I prevent parts passing through one another? Assembly ...How do I prevent parts passing through one another? Assembly I have created a damper, the constraints that I have used are pin for the axis of the p... Are newbie questions OK in here? - comp.lang.asm.x86The only time I ever used inline assembly was when I was writing code for the 21164 using ... Compiler intrinsics still work, so you can write 64-bit SSE2+ code, >> and by ... Optimize Assembly with Conditional Moves - comp.lang.asm.x86 ...improve strlen - comp.lang.asm.x86... pay off to write in assembly.. Optimizing x86 ... can be used to enable/disable such checks, for optimization ... to 64 bit code we ... How to encode an unconditional jump in 64-bit mode? - comp.lang ...What is the machine code of this instruction? I have referenced Intel and AMD ... asm.x86 How to encode an unconditional jump in 64-bit mode? - comp.lang ... 64 bit assembly ... Re: Recent 'Stuck in power save mode' issue. - comp.sys.ibm.pc ...Writing Assembly Code in x64 - comp.lang.asm.x86 I'm very new to this & now facing problems with ... trashed eax and ecx in order to do the first save. ... 32-bit ... Re: Writing Assembly Code in x64 - Der Keiler CodingOn Jun 2, 6:50 pm, Manesh S <spamt...@xxxxxxxxxx> wrote: Hi All, This is Manesh from India. Later on i have been assigned to a porting task of a 32-bit application ... Writing Assembly Code in x64 - Application Forum at ObjectMix.comWriting Assembly Code in x64 - ASM x86 ASM 370 . This is a discussion on Writing Assembly Code in x64 - ASM x86 ASM 370; Hi All, This is Manesh from India. 7/24/2012 10:31:18 AM
|