flat assembler
Message board for the users of flat assembler.
Index
> Main > Store address of label in another variable |
Author |
|
revolution 23 Jun 2016, 23:56
Code: mov [block],block1.sub1 jmp [block] |
|||
23 Jun 2016, 23:56 |
|
nisargshah95 24 Jun 2016, 04:14
revolution wrote:
I know I can do that, but I was looking for a way such that I would not have to move local label's address into register every time I want to access it. |
|||
24 Jun 2016, 04:14 |
|
revolution 24 Jun 2016, 05:59
I don't understand what you mean. There are no registers used in any code posted in this thread so far.
|
|||
24 Jun 2016, 05:59 |
|
nisargshah95 24 Jun 2016, 06:19
Sorry I did not make it clear. Throughout the program, I will only be executing the code in either block1 or block2 (both have the same local label names) based on a condition (ie, one of them will not be used during the entire execution). So throughout the program instead of checking every time whether block1 is to be used or block2 I simply want to call the local labels using block.labelname
|
|||
24 Jun 2016, 06:19 |
|
nisargshah95 24 Jun 2016, 06:22
Based on a discussion with a friend, I was given the following suggestion. Keep the address of the local labels at the start of block1/block2, And access the code at that local label this way
Code: start: ;; some condition using cmp je @f mov [block], block1 jmp .forward @@: mov [block], block2 .forward: jmp [block+sub1] block1: dd .sub1 dd .sub2 .sub1: ;; code .sub2: ;; code |
|||
24 Jun 2016, 06:22 |
|
shutdownall 24 Jun 2016, 11:23
Why don't you use a direct call rather than moving into a variable ?
Code: jmp block1.sub1 or even faster jpe block2.sub1 |
|||
24 Jun 2016, 11:23 |
|
Furs 01 Jul 2016, 23:29
You can't jump to the respective block's sub by just storing one value. Jump instructions store offsets to the respective location (either relative, if direct jump, or absolute, if indirect).
Since I assume block1 and block2 are different pieces of code, then their subs are definitely different code, thus different sizes. You can't do, for example, block+x, where x is block1.sub1-block1, because then it would fail on block2.sub1, assuming it has a different offset (relative to block2) which is probably the case...? However, you can store an index to a table, or simply offset to the table as you did in your second attempt, the table holding offsets for the sub1 and sub2 for each block etc. Your discussion with a friend as you mentioned it does indeed use that method, which works fine. Any problems with it or did you just post because you found the solution? |
|||
01 Jul 2016, 23:29 |
|
nisargshah95 09 Jul 2016, 04:11
@Furs I posted it because I wanted an opinion on how effective a solution it is, and whether a better approach exists. Nevertheless, I used that approach in the end.
|
|||
09 Jul 2016, 04:11 |
|
Furs 13 Jul 2016, 16:47
Don't worry about it, it is the best solution if you have many such blocks or many conditions, that's how you can make "objects" in C or asm (which don't have abstract OOP things), because basically those offsets are "function pointers" (if you know C).
Of course in asm you have more control and they don't have to be functions (you use jmp instead), as long as they all have same entry conditions it should work fine. |
|||
13 Jul 2016, 16:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.