hi I'm trying to make a FarCall function for C in asm and I've tried just about everything but have yet to make something without errors so how do you do a far call like this:
"call eax:ebx"
how to do dynamic far calls in nasm(32 bit)
Re:how to do dynamic far calls in nasm(32 bit)
The Intel manuals: http://developer.intel.com. Indispensable! ;D Look up "CALL - Call Procedure" or something (from memory, look in the table of contents for the first and third volumes). Also check the NASM manual for the assembler syntax used. It's not "call eax:ebx" for example.
Good luck!
Good luck!
Re:how to do dynamic far calls in nasm(32 bit)
lo,
assuming you are in Real mode and if after a lot of trying you would nt be able to get call CS:EIP (call 16-bit segment reg:32bit offset)
you still could use the command RETF, then you simple first push it on the stack, and after that you pop it whit the RETF command
something like this, for Call simply first push current CS:IP:
this above i used for my jump into protected mode. since i also had problems whit the nasm-syntax on that point. It aint perfect but it does the job.
in protected mode you will also be able to do that, just its a bit more complicated due to Task-switching etc.
Hope this helps.
i would look at Intel manuel, 2.. CALL/RET/RETF/JMP commands..
Regards
PyroMathic
assuming you are in Real mode and if after a lot of trying you would nt be able to get call CS:EIP (call 16-bit segment reg:32bit offset)
you still could use the command RETF, then you simple first push it on the stack, and after that you pop it whit the RETF command
something like this, for Call simply first push current CS:IP:
Code: Select all
push ax ; <--- segment selector
push bx ; <--- IP, offset
; might need to be done the other way arround...
RETF ; <--- 16-bit JMP AX:BX command
in protected mode you will also be able to do that, just its a bit more complicated due to Task-switching etc.
Hope this helps.
i would look at Intel manuel, 2.. CALL/RET/RETF/JMP commands..
Regards
PyroMathic
Re:how to do dynamic far calls in nasm(32 bit)
I suck at C and interfacing it with ASM but here's my best shot:The function assumes your compiler uses a near call to call it in 32-bit mode, I'm sure that's the case. Also I think C pushes parameters in reverse order, if not then simply swap them.
Code: Select all
_FarCall: ; void FarCall ( int32 offs, int16 seg );
call pword [esp+4] ; NASM may need FAR instead of PWORD, I use FASM btw
ret
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:how to do dynamic far calls in nasm(32 bit)
yes, iirc, you cannot do something like "call eax" for a far call. You have to write down segment and offset into some memory location and then use call far [memory_reference].
E.g., from Clicker's core/control.asm
that's pmode far call, though.
E.g., from Clicker's core/control.asm
Code: Select all
; "far" call, including call of another TASK
; protocole: void _farCall(offset, segment).
Cglobal farCall
farCall:
push ebp
mov ebp,esp
call far [ebp+8]
pop ebp
ret