Author Topic: assembly conversions  (Read 4752 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #15 on: August 22, 2020, 02:38:12 am »
Thanks Charles, ill give it another go this afternoon.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: assembly conversions
« Reply #16 on: August 22, 2020, 05:36:44 am »
mods in Tokenize:

at the start:
Code: [Select]
'    ASCIIZ PTR addrptr
'    @addrptr = (STRPTR(sourceinput))
sys addrptr=STRPTR(sourceinput)
    push ebx
    mov edi, w
    mov esi, addrptr

at the end:
Code: [Select]
storekeyword:
    inc edi
    mov a, esi
    mov c, cl
    mov l, edx
    mov w, edi
    mov k, ah
pop ebx
mbox "ok1"
    ¤UDT_SETV(dictionary, dictionary.m(w), (0), DWORD, (a), 4)
    ¤UDT_SETV(dictionary, dictionary.m(w), (4), INTEGER, (l), 2)
    ¤UDT_SETV(dictionary, dictionary.m(w), (6), BYTE, ¤BytOvf(k), 1)
    ¤PRINTSTR("=================", 1)
    ¤PRINTSTR(STR$(w, null), 1)
    ¤PRINTSTR(STR$(a, null), 1)
    ¤PRINTSTR(STR$(c, null), 1)
    ¤PRINTSTR(STR$(l, null), 1)
    ¤PRINTSTR(STR$(k, null), 1)
'    jmp checknext
'can't get here with that jump
mbox "ok2"
    RETURN ¤RETVAL
END FUNCTION

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #17 on: August 22, 2020, 02:53:32 pm »
 Ok i think i got the conversions working. I now need to convert the behavior of MOV for BASIC. It makes no sense, i think the guides are oudated...

 In some flavors MOV passes the variable byval and in order to pass its address to a register it requires LEA...  in such cases INC increases its value and you can move the value back to a variable using MOV back. Makes sense.

 In some other codes, using MOV pasess the address of the variable to a register, and using INC increases the address. It  requires a special syntax to increase its value (INC with the address directly does nothing) and LEA is not required... This also makes sense but i dont know what guide to follow.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #18 on: August 22, 2020, 03:07:07 pm »

 Yup. The sample tokenizer now compiles fine for PowerBASIC and Oxygen without tweakings required. Ill try some benchmarks later. :)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: assembly conversions
« Reply #19 on: August 22, 2020, 03:59:52 pm »
A typical direct local variable might be [ebp-108] and lea (load effective address) would resolve its absolute address by subtracting 108 from the ebp value, and storing this value in the target register.

lea ecx,[ebp-108]

you could now use [ecx] to access the variable.

mov eax,[ecx]
...
inc ecx 'next byte

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #20 on: August 22, 2020, 05:05:26 pm »
 Thanks Charles, I think I have implemented that and few other tricks. However i have a question. I can do,

Code: [Select]
mov ebx, dwordvar
 I can also do:

Code: [Select]
mov ch, [esi]
and:

Code: [Select]
mov ch, 64
 But i am having problems doing:

Code: [Select]
mov ch, bytevar
 How can i pass a byte value from a byte variable into the subregister ch and the other 8 bit ones? I imagine i can create a copy into another register, but is there a more direct way without creating a copy?
« Last Edit: August 22, 2020, 05:30:01 pm by Brian Alvarez »

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #21 on: August 22, 2020, 06:28:22 pm »

 Basically i am doing this (see image attached).

 I am backing up and restoring registers correctly between ASM/BASIC code.

 s is a byte variable.

Code: [Select]
mov ch, s
 But it doesnt seem to work.

 The whole rest works marvelously! :)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: assembly conversions
« Reply #22 on: August 23, 2020, 12:02:31 am »
How have you defined s. Is it a direct integer or byte?

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #23 on: August 23, 2020, 03:17:27 am »
It is defined as:

Code: [Select]
byte s

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: assembly conversions
« Reply #24 on: August 23, 2020, 05:39:43 am »
is s local? If not, assign to a local byte.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #25 on: August 23, 2020, 05:47:05 am »

Got it. It worked. :)

John

  • Hero Member
  • *****
  • Posts: 3966
Re: assembly conversions
« Reply #26 on: August 23, 2020, 07:55:49 am »
Watching you guys work together is better than going to the movies.  8)


Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: assembly conversions
« Reply #27 on: August 23, 2020, 08:11:43 am »
 PowerBASIC's TIMER function displays slightly different measurements, but so far Oxygen is leading the benchmarks.  :o :o :o :o

 Hopefully this keeps like this when i fiish debugging completely the conversions and i test using GetTickCount().  :)

« Last Edit: August 23, 2020, 08:48:55 am by Brian Alvarez »

John

  • Hero Member
  • *****
  • Posts: 3966
Re: assembly conversions
« Reply #28 on: August 23, 2020, 10:47:43 am »
It would be interesting to see how FreeBasic compares between PB and O2.

Would BCX be a good reference to use as a C translated BASIC?
« Last Edit: August 23, 2020, 10:57:31 am by John »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: assembly conversions
« Reply #29 on: August 23, 2020, 11:10:33 am »
In FreeBasic, Assembler blocks require asm .. end asm, and the variable names are contained within square brackets.

thus:

Code: [Select]
dim as long a
asm
  mov eax,[a]
  inc eax
  mov [a],eax
end asm
...
[code]