The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: alksentrs on August 03, 2006, 10:23:37 PM

Title: Just a few things...
Post by: alksentrs on August 03, 2006, 10:23:37 PM
Hello to all!

Just a few questions that have been bothering me for a while now:



; This code is NOT valid, but shows the effect of jmp (call has a push EIP in front)
; Note: these are all near jumps

add EIP,xxx   ; relative    (xxx is the displacement relative to the next instruction)
lea EIP,[xxx] ; absolute    (xxx is the memory address to jump to)
mov EIP,[xxx] ; indirect    (xxx is the memory address of the memory address to jump to)


Title: Re: Just a few things...
Post by: hutch-- on August 03, 2006, 10:41:26 PM
MASM32 has MSVCRT support. Conditional jumps are NEAR in win32 with a 32k range and SHORT if you use the form that has signed byte range. Unconditional jumps "JMP" have DWORD range.


Jxx SHORT label   ; signed BYTE range (128 byte)
Jxx NEAR label    ; signed WORD range (32k)
JMP label         ; DWORD range (4 gig)
Title: Re: Just a few things...
Post by: alksentrs on August 03, 2006, 11:19:54 PM
Fast reply!

What I meant was: there are all these different versions of jump and call instructions, yet there doesn't seem to be a way to specify which to use.
E.g.:

jmp [eax]


How do you choose between jumping to the memory address in EAX ("absolute"), and jumping to the memory address stored in the pointer that EAX points to ("absolute indirect")?

I had to copy the libmsvcrt.a file out of my C/C++ compiler's lib folder into the MASM lib folder (and rename it to msvcrt.lib), and manually write an .inc file, because they weren't there.

Is my version of MASM outdated ? ... after typing ML at the command line it came up with v. 6.14.8444 ... so that's probably a yes...
Title: Re: Just a few things...
Post by: Randall Hyde on August 04, 2006, 01:13:17 AM
Quote from: hutch-- on August 03, 2006, 10:41:26 PM
MASM32 has MSVCRT support. Conditional jumps are NEAR in win32 with a 32k range and SHORT if you use the form that has signed byte range. Unconditional jumps "JMP" have DWORD range.


Jxx SHORT label   ; signed BYTE range (128 byte)
Jxx NEAR label    ; signed WORD range (32k)
JMP label         ; DWORD range (4 gig)


Actually, NEAR jumps are 32 bits in 32-bit mode (win32).  I used to make that mistake until Frank Kotler caught me on it.
Cheers,
Randy Hyde
Title: Re: Just a few things...
Post by: gabor on August 04, 2006, 09:44:21 AM
Hello!


I quickly created a small test for the absolute and absolute indirect calls/jumps. Here is what I've got:


     dumyPTR  dd offset dumy
...
     dumy     PROC
              ret
     dumy     ENDP
...
     mov      eax,offset dumy
     call     DWORD PTR eax     ; absolute jump using a register
     call     eax               ;the DWORD PTR can be leaved off

     mov      eax,offset dumyPtr
     call     DWORD PTR [eax]   ; indirect jump using a register
                                ; the size specifier is needed and the square brackets are necessary!


I hope I didn't mess up anything :)
About the size of jumps I didn't really bother so far, I think I use 32bit absolute jump/calls in about 80% of the cases.

Greets, Gábor