Page 1 of 1
long jump failure in MASM5.0 of windows XP OS
Posted: Mon Nov 22, 2010 2:38 am
by Jerry
Supposing there is a section code at 0x00600h, I want long jump to there in my programme as follows. But in fact, I can't do that. Why?
Code: Select all
code segment
org 100h
assume cs: code
start:
jmp begin
dest dw 600h
begin:
xor ax, ax
mov ds, ax
mov si, dest
jmp dword ptr [si]
code ends
end start
I take a screenshot as follows.
Re: long jump failure in MASM5.0 of windows XP OS
Posted: Mon Nov 22, 2010 3:03 am
by Combuster
Because you are using colors, and you are not using code tags, so I can't possibly see what your code is?
Also, you are not debugging the code you wrote. The last few lines assemble to:
Code: Select all
0000000A BE0401 mov si,0x104 ; not that exact number, but close
0000000D 66FF24 jmp dword near [si]
Re: long jump failure in MASM5.0 of windows XP OS
Posted: Tue Nov 23, 2010 1:07 pm
by b.zaar
Jerry wrote:
begin:
xor ax, ax
mov ds, ax
mov si, dest
jmp dword ptr [si]
You set DS to 0 (zero) before reading your data at SI so unless your code is loaded at 0x0000:0100 you will read garbage.
Re: long jump failure in MASM5.0 of windows XP OS
Posted: Mon Dec 13, 2010 8:17 pm
by Casm
For a far jump (which is what dword implies), you need to give both an offset and a segment address - for example,
dest dw 600h, 0
But you have only specified an offset. If you don't know what the seg address should be at compile time, you will need to load it dynamically. For example:
xor ax,ax
mov dest[2], ax
An assume for the ds register probably wouldn't be out of place either: assume ds:code
Code: Select all
code segment
org 100h
assume cs: code, ds:code
start:
jmp begin
dest dw 600h, 0 ;or whatever seg address you want
begin:
xor ax, ax
mov ds, ax
mov si, offset dest ;(or alternatively lea si, dest)
jmp dword ptr [si]
code ends
end start
Re: long jump failure in MASM5.0 of windows XP OS
Posted: Tue Dec 14, 2010 1:08 am
by iLewis
MASM of ANY version does not natively support long jumps. you must either hard code them or do this
Code: Select all
.data
FarDesc dd 0 ; this is the address you want to jump to
dw 10h ; this is the CODE SEGMENT... if your in userland, best of to set this to the current CS value
.code
----- snip -----
jmp fword ptr FarDesc