loading and running programs from turbo c++

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
renovatio
Member
Member
Posts: 57
Joined: Fri May 23, 2008 5:13 am

Re: loading and running programs from turbo c++

Post by renovatio »

in fact, i didn't write all the combinations i tried but believe me, i tried...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: loading and running programs from turbo c++

Post 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 :wink:

But seriously, that has been a frequently asked question. Do ask google more often, the above is a first hit.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
renovatio
Member
Member
Posts: 57
Joined: Fri May 23, 2008 5:13 am

Re: loading and running programs from turbo c++

Post by renovatio »

thanks, from now on i will search google before asking...
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: loading and running programs from turbo c++

Post 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.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
renovatio
Member
Member
Posts: 57
Joined: Fri May 23, 2008 5:13 am

Re: loading and running programs from turbo c++

Post 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. ;)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: loading and running programs from turbo c++

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply