Author Topic: Incorrect dates  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Incorrect dates
« on: May 24, 2011, 12:16:21 PM »
Deleted
« Last Edit: May 05, 2015, 12:45:36 PM by Peter »

Charles Pegge

  • Guest
Re: Incorrect dates
« Reply #1 on: May 24, 2011, 01:24:06 PM »

Hi Peter,

There are several corrections. The main problem was that Addr is a pointer value so it was just a matter of getting the referencing correct.

Code: [Select]

indexbase 0
include "wFunc.h"

Long Addr
Dim  Mem as byte

Addr = GetMemory 100 'this is a pointer

   mov  edi,Addr
   sub  ecx,ecx
A: mov  byte [edi+ecx],255   ' I do not see a way to hand over a constant ?
   inc ecx              'loop A does not go ??
   cmp  ecx,100
   jnz  A
   
   mov  esi,Addr
   mov  ah,[esi]
   mov  Mem,ah

if Mem =255 Then Beep 440, 700
Print Hex mem  'ok

SaveFile "test.txt",*Addr,100  'some dates are incorrect in the file TEST.TXT, seems mystic like TBGL!
FreeMemory Addr               'but my SaveFile works correct! believe it!    :o

Charles

Charles Pegge

  • Guest
Re: Incorrect dates
« Reply #2 on: May 25, 2011, 07:20:36 AM »
Hi Peter,

My secrets revealed! :)

GetMemory gives low level access to initialised memory in the form of Bstrings.

Bstrings are returned to the user in the form of a base address to the string data. Bstrings also have a hidden length field in the four bytes immediately preceding the string data. Another characteristic is that they have null terminators immediately following the string data.

http://msdn.microsoft.com/en-us/library/ms221069.aspx

This is the actual run time code (FreeBasic) :

Code: [Select]
  '--------------------------------------
  function getmem(byval a as sys) as BSTR
  '======================================
  asm
    push [a]
    push 0
    call SysAllocStringByteLen
    'call [ebx+160] 'AllocString
    mov [function],eax
    push 0
    push [a]
    push [function]
    mov eax,[a]
    and al,3
    jnz nini4
      pop edx
      pop ecx
      pop eax
      shr ecx,2
      cmp ecx,0
      jz xini
      rini:
        mov [edx],eax
        add edx,4
        dec ecx
        jg rini
      jmp xini
    nini4:
      call init1
    xini:
  end asm
  'init1 p,a,0 ' BYTE NULLS
  end function



  '---------------------------
  sub FreeMem(byval a as BSTR)
  '===========================
  asm
    mov eax,[a]
    'cmp eax,0
    'jz nfreestr
      push eax
      call SysFreeString
      'call [ebx+168]
    'nfreestr:
  end asm
  end sub

Charles