I'm programming a procedure in Turbo Pascal with assembly to make a close job of "rset" statement in QB 4.5. "Rset" will justify a string to the last bytes in the variable by mean that the string will be saved in the variable at the end of it instead of saving in first bytes. This is the code I made but I see no reaction:
procedure rset(var s:string);
var
s_copy:string;
index,
s_size:integer;
s_offset,
s_seg,
s_copy_offset,
s_copy_seg:word;
l:byte;
label
again;
begin
l:=length(s);
if l=0 then exit;
index:=1;
while copy(s,index,1)='' do
inc(index);
s_copy:=copy(s,index,l);
s:='';
s_size:=sizeof(s);
s_offset:=ofs(s)+s_size-1;
s_copy_offset:=ofs(s_copy)+l-1;
s_copy_seg:=seg(s_copy);
s_seg:=seg(s);
asm
mov cl, [l]
mov si, [s_copy_offset]
mov di, [s_offset]
again:
mov es, [s_copy_seg]
mov al, [byte ptr es:si]
mov es, [s_seg]
mov [byte ptr es:di], al
dec si
dec di
dec cl
jnz again
end;
end;
The
RSetstatement in BASIC works with two strings. Your code works from a single string and can make sense if that string has some whitespace at its right end. Because then it is possible to RTrim the string and shift the remaining characters to the right inserting space characters on the left.In below program I have implemented this approach in the RSet procedure.
If we were to faithfully replicate how BASIC's
RSetstatement works, then we need to use two strings, for the syntax is:RSet lvalue = rvalue, where lvalue is a string variable and rvalue can be any string expression.In below program I have implemented this way of doing it in the qbRSet procedure.
Both RSet and qbRSet are pure
assemblerprocedures. They don't require the usualbeginandend;statements, justasmandend;are enough. And see how easy it is to refer to a variable via theldsandlesassembly instructions. Do notice that assembly code should:DSsegment register as well asBP,SP, andSSThe demo program is written in Turbo Pascal 6.0 and allows you to test the proposed codes with a variety of inputs. This is important so you can check out if it will work correctly in cases where strings are empty, very small, or very long.