Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Assembly 

how can I compare a dword to an int

I want to do this
Code
point      DD ?

LBL:
cmp point,40;
add point,4;
(Oct 18, 2012 05:30 PM)c0mputer-fr0d Wrote:  I want to do this
Code
point  DD ?

LBL:
cmp point,40;
add point,4;
Exactly like you did...Its comparing a dword to an int
Why do you have semicolons after each instruction?
x86 asm - ISO & ANSI C
what have you tried?
Move them into registers and use atodw

Code
.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

.data
string db '7546754',0
format db 'eax=%u',0
.data?
buffer db 12 dup(?)
.code
start:
invoke atodw,addr string ; eax=7546754
invoke wsprintf,addr buffer,addr format,eax
invoke StdOut,addr buffer
invoke ExitProcess,0
end start
Github
Keybase
Shoot me a PM
(Oct 18, 2012 09:08 PM)DaRkReD Wrote:  Move them into registers and use atodw

Code
.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

.data
string db '7546754',0
format db 'eax=%u',0
.data?
buffer db 12 dup(?)
.code
start:
invoke atodw,addr string ; eax=7546754
invoke wsprintf,addr buffer,addr format,eax
invoke StdOut,addr buffer
invoke ExitProcess,0
end start
Ooh Darkred, where'd you learn to do MASM? I've only found books on FASM and ROSM and some other ones.
What is this DWORD being used for? If it's something numerical, like an address, you can just cmp, you don't need to call any function.
(Oct 19, 2012 07:33 AM)Amokov Wrote:  What is this DWORD being used for? If it's something numerical, like an address, you can just cmp, you don't need to call any function.

It depends on the IDE you are using (if any) and compiler. Real assembly cannot do

cmp value, 1

It has to use value as a pointer

i.e.

mov eax, dword ptr [value]

o

cmp dword ptr [value], 40
Code
mov ecx dword ptr [point]
    cmp dword ptr [point] ,40

this is what I tried but it doesn't work
(Oct 19, 2012 05:48 PM)c0mputer-fr0d Wrote:  
Code
mov ecx dword ptr [point]
    cmp dword ptr [point] ,40

this is what I tried but it doesn't work
A dword is an int. Secondly cmp only sets flags you still need a branch instruction.
e.g for MASM:
Code
cmp dword ptr [point], 40
40  jne @F  
add ecx, 40  
@@:  
add ecx, 20
@@ is just an unnamed label, @F is forward so it scans forward for @@: @B is back
just use what ever labels are valid in in your assembler
cmp dword ptr[ variable ], value is a perfectly valid instruction. That will work.

An int does not differ in size from a dword (on a 32bit machine), the only difference between the two is that an int is signed and a dword is unsigned. On a 64 bit machine an integer type might be 64 bits long, while a dword is always 32 bits long.

To test if both hold the same number (despite their signs) do this:

Code
point dd -40h

mov eax, 40
neg eax     ; negate sign

cmp point, eax
je Equal
    ;; |point| != eax
Equal:
     ;; |point| = eax
Thanks everyone and especially schim


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by SIM-2362662Mar 2, 2021 07:53 AM 7 271 Mar 2, 2021 07:53 AM
Last Post: sangita123
[Assembly] by gigajewJul 25, 2020 08:41 AM 5 278 Jul 25, 2020 08:41 AM
Last Post: gigajew
[DBMS] by VirtualFrostFeb 15, 2019 08:36 PM 4 294 Feb 15, 2019 08:36 PM
Last Post: VirtualFrost