View previous topic :: View next topic |
Author |
Message |
m4tek Newbie cheater
Reputation: 0
Joined: 26 Oct 2006 Posts: 22
|
Posted: Wed Jun 25, 2008 4:25 pm Post subject: [C++/C/ASM] __asm in C++/C. Basics. |
|
|
Written by me (m4tek) on 25th June 2008
Here it is, my first tutorial.
Most of you have seen a lot of codes and scripts containing '__asm'. You
could wonder what it is for in a C++ code.
The answer is simple, it's called 'inline assembly' and is used to extend
power and abilities of regular C++ applications. That's enough for an introduction I guess.
MSDN says it all:
Because the assembly code can be mixed inline with C or C++ statements, it
can do tasks that are cumbersome or impossible in C or C++.
I'm not going to explain assembly in no way here. I want to show you the
way to use asm in C++ code and how to mix them up.
Let's move on.
1. Syntax.
As you can see below there's nothing much to do. Type __asm and put assembly
code between curly braces { }.
Code: | __asm {
...code...
}
|
You could start every line (or instruction) with __asm but it's senseless
unless you're using a single instruction ( mov eax, ebx ). It would look
like this:
Code: | __asm ...code...
__asm ...code...
//or...
__asm ...code... __asm ...code...
//senseless no?
//The code below is fine
__asm add eax,ebx
cout << "We used a single instruction.";
|
It's not hard to notice that doing it this way is just a waste of your time
and there's a possibility that you forget to start every line with it.
2. Mixing C++/C with __asm.
In __asm block of code you can use ALMOST all C++/C symbols. This means
that you can use variable names, function names and labels within __asm block.
However you have to keep in mind that symbols' names cannot be the same as
MASM reserved words such as instruction names (eg PUSH). All functions
you are referring to must be declared before the beginning of __asm block.
3. C++/C data in __asm.
A great convenience of inline assembly is the ability to refer to C or C++ v
ariables by name. The easiest way to describe it is using an example so here it is:
Code: | int VariableStoringMyAge;
VariableStoringMyAge = 15;
//Here a short one-line __asm block starts and look! Our int variable is
right there. It adds VariableStoringMyAge's value (15) to eax and stores
the sum in it.
__asm add eax,VariableStoringMyAge |
I hope it's clear and easy to understand.
NOTE: However (nothing can be wonderful ;( ) if any class or structure
share the same member name (it's not unique because
there are two of them), you must place a variable or typedef name right
before the period (.) operator. No example because it's only a note! (:p)
I think it's enough for my first tutorial and it explains the basics.
Now go learn assembly and use it in your C++/C codes
yours nefykenny/m4tek.
Credits:
Me.
MSDN.
Google.
Feel free to evaluate but don't you dare to
flame me!
|
|
Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Wed Jun 25, 2008 4:35 pm Post subject: |
|
|
great job?
its a pretty freaking basic guide, but that doesn't make it bad
|
|
Back to top |
|
 |
m4tek Newbie cheater
Reputation: 0
Joined: 26 Oct 2006 Posts: 22
|
Posted: Wed Jun 25, 2008 4:38 pm Post subject: |
|
|
That's how I wanted it to be. Basic guide on how to use __asm and what to do with it, also some theoretical stuff.
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Jun 25, 2008 5:02 pm Post subject: |
|
|
My assembly might be a little rusty, but shouldn't
Code: |
int VariableStoringMyAge;
VariableStoringMyAge = 15;
//Here a short one-line __asm block starts and look! Our int variable is
right there. It adds VariableStoringMyAge's value (15) to eax and stores
the sum in it.
__asm add eax,VariableStoringMyAge
|
be
Code: |
__asm add eax, [VariableStoringMyAge]
|
?
_________________
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Wed Jun 25, 2008 6:21 pm Post subject: |
|
|
Yes, but microsoft's compiler ignore the brackets if you don't define a size. (byte/word/dword)
it should really be:
__asm add eax,dword ptr ds:[VariableStoringMyAge]
|
|
Back to top |
|
 |
m4tek Newbie cheater
Reputation: 0
Joined: 26 Oct 2006 Posts: 22
|
Posted: Thu Jun 26, 2008 1:29 am Post subject: |
|
|
It's about __asm basics and not ASM itself.. still what I wrote is fine.
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Thu Jun 26, 2008 2:38 am Post subject: |
|
|
I'm sure anyone who's aware of __asm could do that too.
|
|
Back to top |
|
 |
m4tek Newbie cheater
Reputation: 0
Joined: 26 Oct 2006 Posts: 22
|
Posted: Thu Jun 26, 2008 8:52 am Post subject: |
|
|
Exactly, that's for people who AREN'T aware of __asm. It's an extended version of 'hey, there's __asm in C++, go find about it'.
|
|
Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Jun 26, 2008 12:04 pm Post subject: |
|
|
What does dword ptr ds:[bla] even do...?
_________________
8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Thu Jun 26, 2008 1:05 pm Post subject: |
|
|
dword is 4 bytes, you could also move 2 bytes from X or 1 byte:
mov eax,dword ptr ds:[x] //Moves 4 bytes value
mov ax,word ptr ds:[x] //Moves 2 bytes value
mov al,byte ptr ds:[x] //Moves 1 byte value
mov ah,byte ptr ds:[x] //Moves 1 byte value
Cheat Engine just gets the size automatically, for example if you do:
mov eax,[x] it knows to use dword, because eax is a 32-bit register.
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jun 26, 2008 6:56 pm Post subject: |
|
|
oib111 wrote: | What does dword ptr ds:[bla] even do...? |
ds stands for data segment, the rest should be explanatory enough.
so, doing something like...
i++; might compile to inc dword ptr ds:[12345678]
|
|
Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Fri Jun 27, 2008 3:08 am Post subject: |
|
|
dword pointer - moves 4 bytes of what is stored at the location.
|
|
Back to top |
|
 |
jonnybravo Newbie cheater
Reputation: 0
Joined: 01 Dec 2007 Posts: 14
|
Posted: Fri Jun 27, 2008 9:58 am Post subject: |
|
|
mov eax,dword ptr ds:[x] //Moves 4 bytes value
mov= moving what is stored in address eax
eax = address
dword = 32 bits or 4 bytes
ptr = pointer
ds = is the pointer
[x] = array of X where X = value
mov ax,word ptr ds:[x] //Moves 2 bytes value
mov= moving what is stored in address ax
ax = address
word= 16 bits or 2 bytes
ptr = pointer
ds = is the pointer
[x] = array of X
mov al,byte ptr ds:[x] //Moves 1 byte value
mov= moving what is stored in address al
al = address
byte = 8 bits or 1 bytes
ptr = pointer
ds = is the pointer
[x] = array of X where X = value
mov ah,byte ptr ds:[x] //Moves 1 byte value
mov= moving what is stored in address ah
ah = address
byte = 8 bits or 1 bytes
ptr = pointer
ds = is the pointer
[x] = array of X where X = value
Hope this helps
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Jun 27, 2008 10:56 am Post subject: |
|
|
jonnybravo wrote: | mov eax,dword ptr ds:[x] //Moves 4 bytes value
mov= moving what is stored in address eax
eax = address <- registerdword = 32 bits or 4 bytes <- 32 bits (also 4 bytes, not "or")
ptr = pointer
ds = is the pointer <- Data Segment
[x] = array of X where X = value <- value of X, where X = address/register
Hope this helps <- It would have, if you would've done it correctly |
|
|
Back to top |
|
 |
jonnybravo Newbie cheater
Reputation: 0
Joined: 01 Dec 2007 Posts: 14
|
Posted: Fri Jun 27, 2008 11:46 am Post subject: |
|
|
mov eax,dword ptr ds:[x] //Moves 4 bytes value
mov= moving what is stored in address eax
eax = address <- registerdword = 32 bits or 4 bytes <- 32 bits (also 4 bytes, not "or") mov eax,dword ptr ds:[x] //Moves 4 bytes value
mov= moving what is stored in address eax
eax = address <- registerdword = 32 bits or 4 bytes <- 32 bits (also 4 bytes, not "or")
ptr = pointer
ds = is the pointer <- Data Segment
[x] = array of X where X = value <- value of X, where X = address/register
Hope this helps <- It would have, if you would've done it correctly
ptr = pointer
ds = is the pointer <- Data Segment
[x] = array of X where X = value <- value of X, where X = address/register
Hope this helps <- It would have, if you would've done it correctly
I LOL at your post what does also and or.. eax are registers also knows as (ADDRESS)
DS = data segment also knows as what data is being point too... [ ] = array anyone knows that x = the value of whatever is being stored in the array of X...
btw not many people write in asm mostly convery asm to a lanuage in wich i did so please fkk off...
I could of wrote it in big words to sound like you...
Moving registered dword pointer pointer to the data segment of x where it is being stored...
now who understands that??????????? fk off hoe
|
|
Back to top |
|
 |
|