News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Immediate operands in MASM

Started by AeroASM, March 19, 2005, 08:14:18 AM

Previous topic - Next topic

AeroASM

In MASM, the following two pieces of code do exactly the same thing, but only the second one assembles. Why?


mov eax,[403000]
jmp 4010FF



mov ebx,403000
mov eax,[ebx]
mov edx,4010FF
jmp edx

hutch--

If I remember correctly you don't have that JMP opcode available in win32 so you move the value into a register and jump to that address.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

roticv


hutch--

 :bg

Victor,

I am not sure anything else can use that opcode either, if all else fails,


    push 12345678
    ret
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ratch

AeroASM,

INTEL CPUs use a jump instruction that is controlled by an offset RELATIVE to the EIP.  Therefore, you need to specify a label so MASM knows how to calculate the offset.  If you code JMP 12345, the question is 12345 from  what?  If you code JMP BEGIN+12345, where BEGIN coulld be a label at the beginning of the code segment, then MASM has a reference to calculate.  There is no immediate absolute jump instruction for the INTEL CPU.  MASM has no way of checking a jump specified by a register, so anything goes in that case.  Ratch

roticv,

QuoteLousy masm?

Can't blame MASM because INTEL does not have a immediate absolute jump instruction.  Ratch

roticv

I mean lousy masm in recongnising the address and encode the jmp properly.

Ratch

roticv,

QuoteI mean lousy masm in recongnising the address and encode the jmp properly.

Masm can't encode it because there is no immediate absolute jump instruction. MASM has to work with what is avaibable.   And an absolute address cannot be converted into a relative address unless a relative point of reference like a label is known.  Ratch

roticv

I know that there is no absolute jmp. My point is that masm is unable to think of the address as relative and encode it as a relative jmp.

Ratch

roticv,

QuoteI know that there is no absolute jmp. My point is that masm is unable to think of the address as relative and encode it as a relative jmp.

Sure it can.  Simply code JMP $+12345 , and it will code a jump relative from the current location of the EIP.  Ratch

AeroASM

There is an absolute jump, with the EA opcode.

roticv

That's far jmp if I remember correctly.

Ratch

AeroASM,

QuoteThere is an absolute jump, with the EA opcode.

What is 'EA'?  Please define the acronym upon first usage.  Also please post a coding example of a absolute jump.  Ratch

roticv,

QuoteThat's far jmp if I remember correctly.

No way!  It stays within the code segment.  Ratch

AeroASM

EA as in 0EAh, is the hex opcode for an absolute jump. Like this:


db 66h,67h
db 0EAh
dd 12345678h
dw 08h
;equals jmp 08h:12345678h

MichaelW

I spent several hours trying to encode a JMP rel32 to an absolute address with a macro, and I could not make it work. But if you know the address of the destination and the address of the next instruction, it's easy enough to calculate the displacement as the address of destination minus the address of next instruction.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    db    0E9h
    ;dd    401040h-401005h
    dd    OFFSET there - ($+4)
  back:
    print chr$("back")
    mov   eax,input(13,10,"Press enter to exit...")
    exit
  there:
    print chr$("there and ")
    jmp   back
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

MazeGen

QuoteI spent several hours trying to encode a JMP rel32 to an absolute address with a macro, and I could not make it work.

What exactly is not working, Michael?