Author Topic: Equivalent of PB CodePtr function  (Read 1088 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
Equivalent of PB CodePtr function
« on: March 19, 2018, 01:21:56 PM »
in PB there is a CODEPTR function,     

CODEPTR retrieves the address of a Label, Sub, Function, or FastProc.

according to http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/CODEPTR_function.html   

what would be the equivalent function in O2?


Charles Pegge

  • Guest
Re: Equivalent of PB CodePtr function
« Reply #1 on: March 19, 2018, 02:15:45 PM »
Our universal @ (address of) operator. - Can be used for labels, variables, and functions. You can also use &, as in C.

PS:

You can define codeptr and varptr:

def codeptr @ %1
def varptr @ %1
« Last Edit: March 19, 2018, 02:42:34 PM by Charles Pegge »

chrisc

  • Guest
Re: Equivalent of PB CodePtr function
« Reply #2 on: March 19, 2018, 02:52:49 PM »
thanxx Charles

can you please give me an exmple on how to use def codeptr @ %1

chrisc

  • Guest
Re: Equivalent of PB CodePtr function
« Reply #3 on: March 19, 2018, 06:17:21 PM »
Hello Charles

i have the below code which needs to have the CODEPTR define
how to do this?

Code: [Select]
FUNCTION mystr() AS STRING
    LOCAL mlabnum  AS SYS
    LOCAL Secnum  AS SYS
    LOCAL ThdSt

    mlabnum = CODEPTR(mainlab)

    ThdSt = nuls 19
    Secnum = STRPTR(ThdSt)

     MOV rsi, mlabnum
     MOV rdi, Secnum
     MOV rcx, 19
     REP MOVSB

    mlabnum = CODEPTR(seclab)


     MOV rsi, Secnum
     MOV rbx, 19
     MOV rdi, mlabnum
     ADD rsi, rbx
     ADD rdi, rbx
     NEG rbx

  dest1:
     MOVZX rax, BYTE PTR [rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX rax, BYTE PTR [rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX rax, BYTE PTR [rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX rax, BYTE PTR [rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JNZ dest1

  dest2:
    FUNCTION = ThdSt
    EXIT FUNCTION

  NOP
  NOP

  mainlab:
     DB 212,84,249,14,51,10,51,105,185,124,111,140,101,116,200,44
     DB 255,120,28,0

  NOP
  NOP
  seclab:
     DB 128,60,144,125,19,99,64,73,214,4,22,235,0,26,138,77
     DB 140,17,127,0

END FUNCTION
           

Charles Pegge

  • Guest
Re: Equivalent of PB CodePtr function
« Reply #4 on: March 19, 2018, 10:29:53 PM »
Hi Chris,

With o2's automatic register downsize, this will work in both 32bit and 64bit

A few minor alterations:

Code: [Select]
'2018-03-20 T 06:23:55
'
%filename "t.exe"
uses RTL64

FUNCTION mystr() AS STRING
    LOCAL mlabnum  AS SYS
    LOCAL Secnum  AS SYS
    LOCAL string ThdSt
    local mrbx as sys

    def codeptr @ %1

    mlabnum = CODEPTR(mainlab)
    mov mrbx,rbx

    ThdSt = nuls 19
    Secnum = STRPTR(ThdSt)

     MOV rsi, mlabnum
     MOV rdi, Secnum
     MOV rcx, 19
     REP MOVSB

    mlabnum = CODEPTR(seclab)

     MOV rsi, Secnum
     MOV rbx, 19
     MOV rdi, mlabnum
     ADD rsi, rbx
     ADD rdi, rbx
     NEG rbx

  dest1:
     MOVZX AL, [rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX AL,[rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX AL,[rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JZ dest2
     MOVZX AL,[rdi+rbx]
     XOR [rsi+rbx], AL
     ADD rbx, 1
     JNZ dest1

  dest2:

    mov rbx,mrbx

    FUNCTION = ThdSt
    EXIT FUNCTION

  NOP
  NOP

  mainlab:
     DB 212,84,249,14,51,10,51,105,185,124,111,140,101,116,200,44
     DB 255,120,28,0

  NOP
  NOP
  seclab:
     DB 128,60,144,125,19,99,64,73,214,4,22,235,0,26,138,77
     DB 140,17,127,0

END FUNCTION

print mystr           

chrisc

  • Guest
Re: Equivalent of PB CodePtr function
« Reply #5 on: March 20, 2018, 06:50:49 AM »
Charles
You are a maestro of Asm, i salute you

it took me an entire day searching high and low to correct my code and still not sucessful
especially at the  MOVZX  ....  BYTE PTR   line which could not compile
i'm a beginner programmer and an infant in ASM,  i learn a lot here in this forum

Thanxx a lot Charles