long jump failure in MASM5.0 of windows XP OS

Programming, for all ages and all languages.
Post Reply
Jerry
Posts: 1
Joined: Mon Nov 08, 2010 7:37 pm

long jump failure in MASM5.0 of windows XP OS

Post 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.
screenshot_1.jpg
Last edited by Jerry on Thu Nov 25, 2010 12:03 am, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: long jump failure in MASM5.0 of windows XP OS

Post 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]
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: long jump failure in MASM5.0 of windows XP OS

Post 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.
Last edited by b.zaar on Tue Dec 14, 2010 8:47 pm, edited 1 time in total.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: long jump failure in MASM5.0 of windows XP OS

Post 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
iLewis
Posts: 22
Joined: Mon Nov 01, 2010 5:46 pm
Location: Ballarat, Victoria, Australia
Contact:

Re: long jump failure in MASM5.0 of windows XP OS

Post 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
Post Reply