Register | Login
Forum Index > RTL > MemUtils
Author Message
Pages: 1 2
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1478] - posted: 2015-01-17 14:23:34
macros output everything as is, and so uses could end up inside the middle of a function, which would be an incorrect syntax.

for macros, using or push/pop should be used.

e.g.

Code:
using(edi) {
  edi = 1;
}


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1492] - posted: 2015-01-21 12:46:44
I am a bit rewrite memfill. Currently there is "using" for save edi instead of "push \ pop". Also at now used operators "&=" and "|=".
Code:
/*
/    Fill block of memory with specified value
/    $buf -- Pointer to block of memory to fill
/    $len -- Number of bytes to set to value
/    $ch_ -- Value to be set
*/
inline function m_memFill($buf, $len, $ch_) {
//   Copyright (c) 0CodErr, KolibriOS team
  using edi {
    eax = 0;
    al  = $ch_;
    edx = $len;
    edi = $buf;
    push edi
    ecx = eax;
    ah  = al;
    ch  = cl;
    ecx << 16;
    eax |= ecx;
    ecx = edx;
    ecx >> 2;
    edx &= 3;
    rep stosd;
    ecx = edx;
    rep stosb;
    pop eax
  }
  $return eax;
}
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1496] - posted: 2015-01-21 19:24:07
* updated for next release.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1844] - posted: 2016-05-02 19:32:23
Tried to implement 16|32|64 bits compatible MemMove function.
Memory regions of the source area and the destination can be overlapped.
I hope that this will work smile
Code:
/*
/    Move memory from src to dst with specified length
/    dst -- Pointer to destination block of memory to move
/    src -- Pointer to source block of memory to move
/    len -- Count of bytes to move
/    Copyright (c) 0CodErr, KolibriOS team
*/
#set frame off;
procedure MemMove(char* dst, src; sysword len) {
uses gp_si, gp_di, gp_bx, gp_bp;

  const SIZEOF_SYSWORD_MINUS_1 = sizeof sysword - 1;
  const SIZEOF_SYSWORD_MUL_8_MINUS_1 = sizeof sysword * 8 - 1;

  gp_cx = len;
  if (gp_cx <> 0) {
    gp_di = dst;
    gp_si = src;
    gp_di == gp_si;      // cmp gp_di, gp_si
    if (ZF <> TRUE) {    // gp_di <> gp_si
      gp_bp = sizeof sysword;
      if (CF == FALSE) { // gp_di > gp_si
        // Move Up
        gp_di += gp_cx;
        gp_si += gp_cx;
        gp_si -= sizeof sysword;
        gp_di -= sizeof sysword;
        gp_dx  = SIZEOF_SYSWORD_MINUS_1;
        -gp_bp;          // neg gp_bp
      } else {           // gp_di < gp_si
        // Move Down
        gp_dx = 0;
      }

      gp_ax  = gp_cx;
      gp_ax &= SIZEOF_SYSWORD_MINUS_1;
      gp_cx >> $log2i(sizeof sysword);

    // at first copy by syswords
      repeat if (gp_cx > 0) {
        gp_bx = [gp_si];
        [gp_di] = gp_bx;
        gp_di += gp_bp;
        gp_si += gp_bp;
        gp_cx--;
      } until (ZF == TRUE)

      gp_cx  = gp_ax;
      gp_si += gp_dx;
      gp_di += gp_dx;
      [sysint]gp_bp >> SIZEOF_SYSWORD_MUL_8_MINUS_1; // if (gp_bp < 0) then (gp_bp = -1)
      gp_bp |= 1;                                    // if (gp_bp > 0) then (gp_bp = +1)

    // than copy by bytes
      repeat if (gp_cx > 0) {
        bl = [gp_si];
        [gp_di] = bl;
        gp_di += gp_bp;
        gp_si += gp_bp;
        gp_cx--;
      } until (ZF == TRUE)
    }
  }
}
#set frame on;

Some issue:
This ok sar used: Code:
[sysint]gp_bp >> SIZEOF_SYSWORD_MUL_8_MINUS_1
But this shr used: Code:
gp_bp >> [sysint]SIZEOF_SYSWORD_MUL_8_MINUS_1

Could you implement to write Code:
if (ZF)
instead of Code:
if (ZF <> TRUE)

and
Code:
if (!CF)
instead of Code:
if (CF == FALSE)

It may be not so convenient to use constants like SIZEOF_SYSWORD_MUL_8_MINUS_1 and SIZEOF_SYSWORD_MINUS_1 instead of just inline (sizeof sysword - 1) and (sizeof sysword * 8 - 1) into code but currently it not supported.

This for test: Code:
program PE32_CUI 'Test MemMove';

#include 'console.zir';

const test_str = 'Programming on ziron is very interesting!\x0';
char  buf1[64] = test_str;
char  buf2[64] = test_str;

println('Initial string: ', test_str);

eax = @buf1 + 24; edx = eax + 5;
MemMove(eax, edx, 18);
println('Move  backward: ', buf1);

eax = @buf2 + 24; edx = eax + 5;
MemMove(edx, eax, 18);
println('Move   forward: ', buf2);

wait_key();
ExitProcess(0);

This result of test:
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1851] - posted: 2016-05-03 17:32:10
This ok sar used: Code:
Code:
[sysint]gp_bp >> SIZEOF_SYSWORD_MUL_8_MINUS_1


But this shr used: Code:
Code:
gp_bp >> [sysint]SIZEOF_SYSWORD_MUL_8_MINUS_1


This works correct, Ziron uses the left member for precedence, in this case gp_bp is used, registers are default "as" uint.

This removes any confusion as to what the result should be since it is placed at the start of the line.

you could also do something along the lines of:

Code:
gp_bp as sysint;
gp_bp >> .....


However this will keep gp_bp defined as a sysint until you reset/change it.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1 2
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 2 user(s) online. 0 member(s) and 2 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd