Jump to content

Function Pointers (call si?)

- - - - -

  • Please log in to reply
3 replies to this topic

#1
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
Hello,

I have the following code: (simplefied)


Main:
 mov si,WORD[.Adr]
 call si
 cli
 hlt

.Adr: dw TTT

TTT:
 --DO SOMETHING---
 ret


But the function never gets used, if i call TTT direct i does work:

Main:
 call TTT
 cli
 hlt

Also, comparing SI with TTT show the are the same.
I'm i missing something when it comes to function pointers?

i'm using NASM in 16bit binairy mode (bootloader)

Tanx,

Joran

#2
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
If anyone wants to know, i have found a workaround.
The problem was that only 32 bit registers where allowed with jumps.
however, 16bit reletive jumps are alowed, when the distance to jump is already known:
    mov si,WORD[.adr]             ;Load absolute adress
    sub si,.After                      ;Calc relative
    mov WORD[.JumpLoc],si      ;Alter Jump code     
    db 0xE9                            ;Opcode for 16bit relative JUMPS
    .JumpLoc: db 0,0               ;Bytes to jump
    .After:


I hope it can help anyone.

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Try mov si, TTT
sudo rm -rf /

#4
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
That didn't work.
Also, cmp si,TTT and than Jump if Equeal showed that TTT was in SI.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users