Extending my jumps?
Extending my jumps?
I'm using assembly but my code has become too large that the jumps won't work because they are too far away. How can I fix this or set my code up so that it will work?
Re:Extending my jumps?
By giving your code a good structure. You shouldn't need to be jumping over huge sections of code left right and centre. That totally ruins all of the optimisation features built into the CPU to take advantage of the phenomenon of program locality.
For a start, try to split some of your lengthy bits of code into neat functions which can be called with a single instruction
For a start, try to split some of your lengthy bits of code into neat functions which can be called with a single instruction
Code: Select all
jmp start
foo:
; some code
ret
bar:
; some code
ret
start:
call foo
call bar
; and so on..
Re:Extending my jumps?
..
Last edited by Perica on Tue Dec 05, 2006 9:34 pm, edited 1 time in total.
Re:Extending my jumps?
I am using the NASM compiler and my code is part of a DOS style OS I've been working on.
I have the code to set up my commands:
MOV SI, strCommand
MOV DI, cmdCls
MOV CX, 4
REPE CMPSB
JE COMMAND_CLS
MOV SI, strCommand
MOV DI, cmdDate
MOV CX, 5
REPE CMPSB
JE COMMAND_DATE
etc.
But I have 6 functions and some of them have lengthy code so some of these tests can't reach their designated functions. I hope I make sense?
I have the code to set up my commands:
MOV SI, strCommand
MOV DI, cmdCls
MOV CX, 4
REPE CMPSB
JE COMMAND_CLS
MOV SI, strCommand
MOV DI, cmdDate
MOV CX, 5
REPE CMPSB
JE COMMAND_DATE
etc.
But I have 6 functions and some of them have lengthy code so some of these tests can't reach their designated functions. I hope I make sense?
Re:Extending my jumps?
..
Last edited by Perica on Tue Dec 05, 2006 9:34 pm, edited 1 time in total.
Re:Extending my jumps?
Maybe you should have a table with all commands and another table with the function address to each command?
That way you can have a single loop to compare the commandline against the command-table (and keep count), then call the address in the other table.
Do you understand what i mean?
That way you can have a single loop to compare the commandline against the command-table (and keep count), then call the address in the other table.
Do you understand what i mean?
Re:Extending my jumps?
instead of:
Make COMMAND_CLS a function, and call it instead. I also agree that you should do what bubach suggested.
Code: Select all
JE COMMAND_CLS
Re:Extending my jumps?
Converting them to inverse logic and using a normal jump would also work:Perica wrote: If I've understood you correctly, then placing the word NEAR after your jump instructions should do the trick. For example:Code: Select all
je NEAR jump_destination
Code: Select all
jne next_try_1
jmp jump_destination
next_try_1:
Re:Extending my jumps?
Hi,
I generally use something like this in my makefiles:
NASM = nasm -i$(INCDIR) -O99 -w+orphan-labels -f bin
It's easier than manually adding the NEAR keyword each time NASM gives an error. The optimizer doesn't change your instructions, it only finds better encodings for the instructions - the final binary will still match a disassembly line for line (useful for Bochs debugging) .
Cheers,
Brendan
Turning on NASM's multi-pass optimizer also works (or at least it does for versions released in the last few years). Check the NASM manual ("Section 2.1.16 The -On Option: Specifying Multipass Optimization").Perica wrote: If I've understood you correctly, then placing the word NEAR after your jump instructions should do the trick. For example:Code: Select all
je NEAR jump_destination
I generally use something like this in my makefiles:
NASM = nasm -i$(INCDIR) -O99 -w+orphan-labels -f bin
It's easier than manually adding the NEAR keyword each time NASM gives an error. The optimizer doesn't change your instructions, it only finds better encodings for the instructions - the final binary will still match a disassembly line for line (useful for Bochs debugging) .
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.