I am trying to work around a problem with the different types of jmp and call instructions. My basic goal is to be able to implement an intersegmentry call of jmp. However it has turned out to be a little more complicated than I thought....
If I have the code:
jmp FWORD PTR cs:@F
@@:
masm generates the code:
00401000 2EFF2D07104000 jmp FWORD PTR cs:[401007h]
This is perfectly correct, except the far pointer cs:[401007h] is not the new address of the instruction pointer!!! thus it causes an exception. Instead it is a pointer to an FWORD (as described by the operand size in the instruction) in memory which in turn contains the pointer to the address.
So if I had:
jmp FWORD PTR cs:@F
@@:
DWORD jmpaddress
WORD 015fh ;The CS descriptor
jmpaddress:
The code would work perfectly. With this I can perform a far jmp to a different code segment. But this is messy, I am using a pointer to a pointer. Is there a way under masm, to jmp to the location (Imaginary) 0987h:0287614h with the following method:
mov gs,0987h
mov ebx,0287614h
jmp DWORD PTR gs:
I think this is the opcode 09ah, CALL ptr16:32 Call far, absolute, address given in operand
.data
address dw ?
.code
mov dword ptr , 0987h
mov dword ptr , 0287614h
jmp
end
try that. i'm not sure if that will work with window, but with
dos, that's how it is.
Thanks, thats what I was trying to highlight before, that you supply a memory location which contains the address to jmp to.
I dont see it as unreasonable, can you do a far jmp, as you would do a short jmp? The address of the jump supplyied in the operand?
as such with:
mov gs,0987h ;Segment to jmp to
mov ebx,0287614h ;Address in segment to jmp to
jmp DWORD PTR gs: ;
in dos, the obvious solution doesn't work.
jmp dword far will generate error. for window, eh..
i'm not really sure. ;) i think someone with more experience
with windows can help you. ;) (specially addressing memory).
I suppose one might try
push myseg ;16 bits
push myaddr ;32 bits, e.g. push dword ptr
retf
but that looks a bit silly. When masm is too
ambiguous I sometimes make up my own opcodes in
the form of macros such as (for DOS)
jmp32 macro arg
db 0EAh
dd arg
endm
--Larry