flat assembler
Message board for the users of flat assembler.

Index > Main > Why did not using eip for loops?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 07 Nov 2024, 10:58
I Wonder Why amd and intel not do this?
32bit and 64bit have eip/rip register.
This might do loop without label.
Example
Code:
For 0,20 ;get eip value for jif. Start from zero and do 20 times loop.
Some code
Jif 0 ;Jmp to for until flag if=0

    

For and Jif not using registers. Its good for 8 registers in 32bits programs.


Last edited by Roman on 07 Nov 2024, 13:10; edited 1 time in total
Post 07 Nov 2024, 10:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20409
Location: In your JS exploiting you and your system
revolution 07 Nov 2024, 11:10
A jmp imm instruction is equivalent to add eip, imm. So EIP is already used. Indeed it is used by every instruction.

Similarly for jcc imm --> caddcc eip,imm
Post 07 Nov 2024, 11:10
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 07 Nov 2024, 12:27
Add eip, imm You must write hands label address.
My profit asm command auto set address for jif.
For asm command coold store many addresses (64 loops in cash l0 cpu) for many nxt.
Profit not using main registers and not do push/pop
In programing cycles very often operation.
Post 07 Nov 2024, 12:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20409
Location: In your JS exploiting you and your system
revolution 07 Nov 2024, 12:36
Do you mean EFLAGS to hold the loop counter?

Using EIP for a loop counter seems to be impossible.
Post 07 Nov 2024, 12:36
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
macomics 07 Nov 2024, 12:43
Roman wrote:
Add eip, imm You must write hands label address.
For asm command coold store many addresses (64 loops in cash l0 cpu) for many nxt.
Profit not using main registers and not do push/pop
In programing cycles very often operation.
imm is not a label address, but a constant value. You don't need labels for it. The labels themselves do not take up the processor's time to calculate them, because these are just the values of the eip/rip register at a specific time. As revolution has already said, these registers are used automatically in each command.

Roman wrote:
My profit asm command auto set address for jif.
Where should сommand save this value?


Last edited by macomics on 07 Nov 2024, 12:46; edited 1 time in total
Post 07 Nov 2024, 12:43
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 07 Nov 2024, 12:44
For inc owner value. If value = 20 then set if flag =1
Jif 0 jump on for until flag if=0
Post 07 Nov 2024, 12:44
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
macomics 07 Nov 2024, 12:48
Roman wrote:
For inc owner value. If value = 20 then set if flag =1
Jif 0 jump on for until flag if=0

Where should jif jump to if the address is unknown (the eip/rip value of the command you need)
Post 07 Nov 2024, 12:48
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
macomics 07 Nov 2024, 12:51
In x86, all conditional jumps are relative anyway. You can only jmp to the absolute address
Post 07 Nov 2024, 12:51
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 07 Nov 2024, 13:06
Quote:

Where should jif jump to if the address is unknown

For get current eip address put to cash something like push eip.
Jif get address from cash. if flag if=0 do jmp to for again.
jif something like pop address.

This work logic code, from first post.
When you programing code and write only numbers (op codes and values), hard calculating many labels and offsets.
Must be asm commands do this automatically.


Last edited by Roman on 07 Nov 2024, 13:13; edited 1 time in total
Post 07 Nov 2024, 13:06
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
macomics 07 Nov 2024, 13:12
Code:
  call @f
@@:
  sub qword [rsp], 5
  Some commands
  jcс @f
  retn
@@:    
The top of the stack is already in the cache

But why do this when it's easier right away
Code:
    push 0
@@:
    Some commands
    inc dword [rsp]
    cmp dword [rsp], 20
    jc @b
    pop rax    

Roman wrote:
When you programing code and write only numbers (op codes and values), hard calculating many labels and offsets.
Must be asm commands do this automatically.
To simplify these calculations, the assembler was invented


Last edited by macomics on 07 Nov 2024, 13:18; edited 1 time in total
Post 07 Nov 2024, 13:12
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 07 Nov 2024, 13:16
Some commands could corrupted flags !
And jcc failed.

this write hands: jc @b and @@:
Its bad variant.

Let's say you created owned cpu.
And you hands writing numbers for bios.
You not have fasm or visual studio.
You only can upload in bios numbers your code.
And calculated hands for labels addresses it's not fun .
Post 07 Nov 2024, 13:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 09 Nov 2024, 05:40
Why exist call and repnz.
But we can't do repnz call some proc ?
Very usefull command.
Post 09 Nov 2024, 05:40
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
macomics 09 Nov 2024, 06:23
Code:
call someProc
loopnz $ - 5    
Post 09 Nov 2024, 06:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.