Page 1 of 1

16-bit dynamic jump?

Posted: Thu Jul 12, 2012 6:52 pm
by xixpsychoxix
I don't know if this is what you would actually call it but I want to perform a dynamic jump in 16-bit mode assembly, sort of like a c function pointer. Here is an example of the code I am using:

Code: Select all


    mov bx,cmd_addr
    call word [bx]

    ret

cmd_addr: dw _test_funct

_test_funct:

    mov ax,0x0123
    ret

This is a very incomplete example but it gets my main point across. For some reason every time I do this my OS resets itself (I am trying to write a small 16-bit ASM OS as a second option to my main kernel.) Is there something that is wrong with calling the contents of a memory address like this? I am assembling with nasm and I have checked my stack and have all the segment registers set up appropriately.

Re: 16-bit dynamic jump?

Posted: Fri Jul 13, 2012 3:39 am
by xixpsychoxix
No sweat guys I solved it! The bootloader loads us to 0050:0000 and then jumps there, setting cs to 0x50. I was using

Code: Select all

org 0x500

start:

        xor ax,ax
        mov ds,ax
        mov es,ax

I changed my origin and segment registers to match the code segment and now it works. I guess if I am going to be jumping to a memory address loaded based off of other segments I should make those segments point to the right places...