| View previous topic :: View next topic |
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jun 18, 2007 2:10 pm Post subject: Math in MASM |
|
|
In MASM how do you do like +, -, *, /
is it just like in c++
or do i have to do a command like mov or something
| Code: |
include \masm32\include\masm32rt.inc
.data
MsgBoxCaption db "Addition Test",0
MsgBoxText db 6 + 5,0
.code
start:
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK
push 1000
call Sleep
invoke ExitProcess,NULL
end start |
when i "db 6 + 5" i get like the male sex symbol
lmao? _________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Jun 18, 2007 2:14 pm Post subject: |
|
|
| add, sub, mul, div |
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Mon Jun 18, 2007 2:15 pm Post subject: |
|
|
quotation marks...
@appalsap...
i think he just wants the + character to show up. _________________
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jun 18, 2007 2:18 pm Post subject: |
|
|
no i want 11 to show up lol
i dont get how i would do this
add 6,5?
what lol
if you have aim
steveskate1000 _________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Jun 18, 2007 2:21 pm Post subject: |
|
|
| Code: |
mov eax,5
add eax,6
|
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jun 18, 2007 2:25 pm Post subject: |
|
|
but now how do i get a variable to equal that?
im so fucking confused >;{
| Code: |
include \masm32\include\masm32rt.inc
.data
text db "I want eax to be displayed here" ,0
Caption db "MessageBox" ,0
.code
start:
mov eax,5
add eax,6
invoke MessageBox, NULL, addr text , addr Caption, MB_OK
push 500
call Sleep
invoke ExitProcess, NULL
end start |
i want text to be eax o.o in the invoke MessageBox or variable declare _________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Jun 18, 2007 2:30 pm Post subject: |
|
|
| high6 wrote: | | DeltaFlyer wrote: | | Code: |
mov eax,5
add eax,6
|
|
sub 10,4;6
div 10,2;5
inc 10;11
dec 20;19
mul 5,5;25
etc |
Can't do operations on two immediate values. For commands such as mul and div, specific registers must be used.
| blankrider wrote: | but now how do i get a variable to equal that?
im so fucking confused >;{
|
Your registers are your temp variables. They are the things that can be used to do operations. For longer storage, use the memory.
You really should go read a tutorial to learn ASM basics before trying these things. _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Jun 18, 2007 2:31 pm Post subject: |
|
|
1. You can use registers in function calls
2. MessageBox wants a string, don't give it a number
3. You can convert a number to string with "itoa" in msvcrt.dll |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Jun 18, 2007 2:38 pm Post subject: |
|
|
| high6 wrote: | | I was giving the syntax not working examples using regs. |
Even the most basic syntax is wrong. There is no MUL command that takes two operands. The destination is implied and varies according to the source. Similar for DIV. _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Jun 18, 2007 2:38 pm Post subject: |
|
|
| Code: |
.386
.model flat, stdcall
option casemap: none
includelib \masm32\lib\user32.lib
includelib \masm32\lib\msvcrt.lib
c_msvcrt typedef PROTO C :VARARG
externdef _imp___itoa:PTR c_msvcrt
crt__itoa equ <_imp___itoa>
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
Number dd 0 ;only 4 bytes so number cannot exceed 3 digits
Caption db 'my caption', 0
.code
start:
mov ebx, 5
add ebx, 6
invoke crt__itoa, ebx, addr Number, 10 ;base 10
invoke MessageBoxA, 0, addr Number, addr Caption, 0
ret
end start
|
Last edited by appalsap on Mon Jun 18, 2007 3:02 pm; edited 1 time in total |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jun 18, 2007 2:40 pm Post subject: |
|
|
thank you i get this now
im gonna go read more about registers now  _________________
|
|
| Back to top |
|
 |
Uzeil Moderator
Reputation: 6
Joined: 21 Oct 2006 Posts: 2411
|
Posted: Mon Jun 18, 2007 2:57 pm Post subject: |
|
|
| DeltaFlyer wrote: | | high6 wrote: | | I was giving the syntax not working examples using regs. |
Even the most basic syntax is wrong. There is no MUL command that takes two operands. The destination is implied and varies according to the source. Similar for DIV. |
IMUL can take 3 if I remember correctly. And yet at the same time I can't remember if IMUL is the signed or unsigned version of multiplication.
Easier math: LEA !
Bah hah!
| Code: | | lea eax,]eax+ecx*4+12345678] | Pure beauty. Does all that and doesn't even effect any EFlags
Thread starter: This isn't going to be much like any other language you've dealt with. Those high level (high level doesn't mean advanced / of high standard, it means... easy/simplified really ) languages hide assembly from you as it's completely different. A line like "myvar=(myvar+32)/8;" would use registers to temporarily store all the information for that math, then shove the outcome into the memory we refer to as 'myvar' here, then they would be used for your next line if needed, etc. _________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Jun 18, 2007 3:13 pm Post subject: |
|
|
Ya... I specified MUL though. IMUL should be the signed version, since MUL is the unsigned.
As for the inline multiplication, I thought it was only valid for multiples of 2? _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Uzeil Moderator
Reputation: 6
Joined: 21 Oct 2006 Posts: 2411
|
Posted: Mon Jun 18, 2007 3:22 pm Post subject: |
|
|
If that's true, it's easy to get around.
Take... eax*5 for example- | Code: | | lea eax,[eax+eax*4] |
Some may be harder to get to than others (and I think you mean exponential something or others of 2), like eax*7 for example probably needs 2 lines if this 2 rule is true (I'll test momentarily through Olly) - | Code: | lea eax,[eax+eax*4]
lea eax,[eax+eax] ;I know I could do mul 2 here since I'm using eax for my example, but that would mess with edx. See why I love lea? |
_________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Jun 18, 2007 3:34 pm Post subject: |
|
|
Yes, I did mean powers of 2... thought about one thing typed another...
I'm not sure if such exception exists or not though. I might have confused it with the shifts, which only does multiplications and divisions by powers of 2. _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
|