flat assembler
Message board for the users of flat assembler.
Index
> Main > right instruction to return from subrutine |
Author |
|
JohnFound 27 Sep 2015, 05:00
Yes, it will work. But if you know the address why not use directly "call 0xf000000e"?
Another deal is what code will stay on this address. If you didn't place code on this address, the above instruction will end with exception. The subroutine must end with instruction "retn" or "retf" in order to return to the caller. |
|||
27 Sep 2015, 05:00 |
|
Trinitek 27 Sep 2015, 05:19
JohnFound wrote: Yes, it will work. But if you know the address why not use directly "call 0xf000000e"? |
|||
27 Sep 2015, 05:19 |
|
JohnFound 27 Sep 2015, 06:35
It will work. The assembler will compute the proper instruction encoding. If you need to call particular known address, it will work OK. (test it)
It is another story that such calls are never used with protected mode OS because you simply can't know where some subroutine is located. Logos is simply too beginner to realize what he really wants. |
|||
27 Sep 2015, 06:35 |
|
Logos 27 Sep 2015, 13:35
JohnFound wrote:
Ok! So what you are saying is that it would override the MMU? |
|||
27 Sep 2015, 13:35 |
|
Logos 27 Sep 2015, 18:22
JohnFound wrote: Yes, it will work. But if you know the address why not use directly "call 0xf000000e"? I'm writing a compiler, and it generates machinecode. call 0xf000000e would make a subroutine jump with a relative address. I would like to use a absolute address. If I use retn, wouldn't that leave residue data on the stack? Isn't retf the right instruction? As I'm making machine code directly, I cant depend on someone else compiler to correct stuff for me. I will hand code some machine code, tomorrow to see that everything work as it should. But just now, I'm gathering all intel I need, to make my compiler do generate working code, so I don't have to debug more than necessary. |
|||
27 Sep 2015, 18:22 |
|
Trinitek 29 Sep 2015, 02:18
Code: mov eax, 0xf000000e call eax ; Call near, absolute indirect ; ... retn ; Opcode = 0xC3, Near return to calling procedure A little note, also: RETN is also used to return from relative address calls. RETF is only used for far calls, which, in a protected mode environment, are used for jumping to locations belonging to different tasks that might be running in the same or a different privilege level. Additionally, there is a variant of RETN and RETF that allows you to specify how many bytes to pop from the stack if you have junk data from the called procedure that you don't need anymore. Check the Intel docs for that. |
|||
29 Sep 2015, 02:18 |
|
sunnysigil 03 Dec 2015, 11:19
Trinitek wrote: [code]mov eax, 0xf000000e It's simply ret imm16 where imm16 is the amount of bytes you wish to release off the stack. |
|||
03 Dec 2015, 11:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.