Page 2 of 2
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 2:47 pm
by renovatio
in fact, i didn't write all the combinations i tried but believe me, i tried...
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 2:53 pm
by Combuster
Let me do the google stuff for you:
Tasm wont let you
do a far call, so we have to go around silly tasm. The opcode for a far call
is is 9ah. So where you would normally put call far 900h:100h you instead:
Code: Select all
db 9ah ; opcode for call far
dw 0100h ; when doing it in machine code, offset comes first.
dw 0900h
Now you know how to do that with far jumps too
But seriously, that has been a frequently asked question. Do ask google more often, the above is a first hit.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 3:40 pm
by renovatio
thanks, from now on i will search google before asking...
Re: loading and running programs from turbo c++
Posted: Tue Aug 05, 2008 8:26 am
by inflater
BTW in addition to my post to provide a working example (I think...) this can be used, too:
JMP FAR 2000h:0
Code: Select all
mov ax,2000h ;CS for the jmp = 0x2000
push ax ;put it into stack
xor ax,ax ;zero the AX a bit faster way, the IP = 0
push ax ;put it into stack
retf ;pop two words off the stack and jump to them
But it's weird that TASM couldn't accept
PUSH 2000h. Maybe it needs some of the weird prefixes "offset" or "word ptr", not sure about which one though.
Re: loading and running programs from turbo c++
Posted: Tue Aug 05, 2008 1:56 pm
by renovatio
now the far call issue is solved but now my problem is that after running the program and returning to the address call pushed onto the stack, lots of spaces are written on the screen and nothing happens then.
here are the steps i do to load and run a program:
1) load the program from a sector to memory (2000h:0h)
2) push es, ds
3) set es and ds to 2000h
4) far call to 2000h:0h
5) pop es ds
6) and the program SHOULD continue
do you find anything wrong??
EDIT: SOLVED, i was returning with a RET and i needed a RETF. Thanks. Now my kernel is done, i only need my bootloader.
Re: loading and running programs from turbo c++
Posted: Tue Aug 05, 2008 2:34 pm
by Combuster
inflater wrote:But it's weird that TASM couldn't accept PUSH 2000h. Maybe it needs some of the weird prefixes "offset" or "word ptr", not sure about which one though.
Keep in mind that the TASM that comes with Turbo C supported up to the 286... "push immediate" may very well have been a 386 instruction. (Can't be bothered to check that right now)