__asm{} blocks and such stuff
well basicly i was haveing a look at someone''s source code, a bit of it actually, and i saw this wierd __asm thing. i looked on msdn and apparently it allows u to write in assembly but, as we all know msdn is not for learning but rather looking things up. i had a little search on google, 1/2 an hours worth, and found nothing really apart from that there is AT&T and INTEL versions and i think VC++.NET uses INTEL version of __asm{}. does anyone know where i can find proper matterial on this __asm{} block and how to use it?
thanx for reply.
www.programmers-unlimited.com, try it, its not too bad.
Simply :
int A = 6, B = 0;
__asm {
mov ax, A
mov B, A
}
printf("B has stored : %i\n", B);
// The output is 6
int A = 6, B = 0;
__asm {
mov ax, A
mov B, A
}
printf("B has stored : %i\n", B);
// The output is 6
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
there are plenty of assembly tuts out there enter "Assembly tutorial" or *Assembler tutorial" (both without quotes) @ google.com . But although Leyder Dylan's assembley itself may be wrong, the structure is correct
------------------------------------------------------
Regret Nothing - Learn Everything
[edited by - NeViL tHe dEVil on October 3, 2003 4:03:40 AM]
//strncpy routineint nchar *src,*dest__asm { mov ecx,n //counter mov si,offset src //source address push ds //moving ds into es pop es mov di,offset dest //destingation address rep movsb //decrement ecx, if it isn't 0, mov ds:si to es:di}
------------------------------------------------------
Regret Nothing - Learn Everything
[edited by - NeViL tHe dEVil on October 3, 2003 4:03:40 AM]
------------------------------------------------------ Regret Nothing - Learn Everything
October 03, 2003 10:56 AM
NeViL tHe dEVil wat does push es mean, i recon push is a keyword but es has not been defined, this is all very confusing like push is like assingment, and pop is delet that address right?! but why are u doing all this es di stuff?
k ill look on google.com for this assembler tutorials, but isnt assembler hardware specific, so i cant use assembler for intel on AMD?
k ill look on google.com for this assembler tutorials, but isnt assembler hardware specific, so i cant use assembler for intel on AMD?
Assembler is not very hardware-specific, since ALL programs are turned into assembler before they are turned into machine code. I myself have a AMD Duron and it all works fine. I''m not sure how it works on MACs though. Also, DOS and UNIX may have different interrupt systems. To explain what I wrote:
Command mov destination,source
moves the contents of source into destination. source and destination can be registers, addresses and labels.
command push and pop
push: moves a value onto the stack. I f you don''t know wht the stack is, read any book about programming
pop: moves the last value pushed onto the stack back off it
The stack is defined by the registers ss:sp
command rep movsb
is infact to commands:
command rep
executes the following command (wich must be from the movs,lods or stos (= movestring,loadstring or storestring) family) and decrements ecx. it repeats this until ecx is 0
command movsb
from the family movs
mov = move; s = string; b = byte
moves one byte from ds:si to es:di. Thats the reason why I moved the offsets of the strings into si and di and made es = ds. However, ''mov'' cannot be applied to ds and es at the same time, so it''s faster to use push and pop.
Hope this helped you
------------------------------------------------------
Regret Nothing - Learn Everything
Command mov destination,source
moves the contents of source into destination. source and destination can be registers, addresses and labels.
command push and pop
push: moves a value onto the stack. I f you don''t know wht the stack is, read any book about programming
pop: moves the last value pushed onto the stack back off it
The stack is defined by the registers ss:sp
command rep movsb
is infact to commands:
command rep
executes the following command (wich must be from the movs,lods or stos (= movestring,loadstring or storestring) family) and decrements ecx. it repeats this until ecx is 0
command movsb
from the family movs
mov = move; s = string; b = byte
moves one byte from ds:si to es:di. Thats the reason why I moved the offsets of the strings into si and di and made es = ds. However, ''mov'' cannot be applied to ds and es at the same time, so it''s faster to use push and pop.
Hope this helped you
------------------------------------------------------
Regret Nothing - Learn Everything
------------------------------------------------------ Regret Nothing - Learn Everything
Thanks for you infos. That was just a simple example ...
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
''assembler'' as a concept isnt hardware-specific, however the instructions used ARE hardware-specific.
The reason that code works on an AMD and an Intel chip is because both chips work to the same spec for instructions (x86).
However that code wont work on a Mac as it uses a different instruction set and the same with any other cpu which isnt "IBM compatible".
So, assembler code written for a PC wont work on a Mac, where as the C++ code will be compiled down to the native code for the platform you are compiling on.
As a side note bits of the assembler language are chip dependant, for example;
code using SSE instructions will fail on a P2 or a pre-XP AMD chip as they dont have those instuctions
The reason that code works on an AMD and an Intel chip is because both chips work to the same spec for instructions (x86).
However that code wont work on a Mac as it uses a different instruction set and the same with any other cpu which isnt "IBM compatible".
So, assembler code written for a PC wont work on a Mac, where as the C++ code will be compiled down to the native code for the platform you are compiling on.
As a side note bits of the assembler language are chip dependant, for example;
code using SSE instructions will fail on a P2 or a pre-XP AMD chip as they dont have those instuctions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement