Use of absolute clause. 
Author Message
 Use of absolute clause.

I wrote the following program.

program vals;
var b1,b2:byte;
    w:word absolute $23A2:$0052;
begin
  writeln(ofs(b1),':',ofs(b1));
  writeln(ofs(b2),':',ofs(b2));
  writeln(ofs(w),':',ofs(w));
  for b1:=0 to 3 do begin
    for b2:=0 to 3 do begin
      writeln(w:10);
      readln;
    end;
  end;
end.

I know for a fact that w begins at the same memory location as b1, but
in the nested for loops, b1 and
b2 change, so w should change too. Shouldn't it? Yet it doesn't. Can
anyone tell me why?
TIA.

--
Patrick D. Rockwell





Thu, 01 Apr 2004 01:12:13 GMT  
 Use of absolute clause.

I wrote the following program.

program vals;
var b1,b2:byte;
    w:word absolute $23A2:$0052;
begin
  writeln(ofs(b1),':',ofs(b1));
  writeln(ofs(b2),':',ofs(b2));
  writeln(ofs(w),':',ofs(w));
  for b1:=0 to 3 do begin
    for b2:=0 to 3 do begin
      writeln(w:10);
      readln;
    end;
  end;
end.

I know for a fact that w begins at the same memory location as b1, but
in the nested for loops, b1 and
b2 change, so w should change too. Shouldn't it? Yet it doesn't. Can
anyone tell me why?
TIA.

--
Patrick D. Rockwell





Thu, 01 Apr 2004 02:03:13 GMT  
 Use of absolute clause.

I wrote the following program.

program vals;
var b1,b2:byte;
    w:word absolute $23A2:$0052;
begin
  writeln(ofs(b1),':',ofs(b1));
  writeln(ofs(b2),':',ofs(b2));
  writeln(ofs(w),':',ofs(w));
  for b1:=0 to 3 do begin
    for b2:=0 to 3 do begin
      writeln(w:10);
      readln;
    end;
  end;
end.

I know for a fact that w begins at the same memory location as b1, but
in the nested for loops, b1 and
b2 change, so w should change too. Shouldn't it? Yet it doesn't. Can
anyone tell me why?
TIA.

--
Patrick D. Rockwell





Thu, 01 Apr 2004 02:00:54 GMT  
 Use of absolute clause.
I wrote the following program.

program vals;
var b1,b2:byte;
    w:word absolute $23A2:$0052;
begin
  writeln(ofs(b1),':',ofs(b1));
  writeln(ofs(b2),':',ofs(b2));
  writeln(ofs(w),':',ofs(w));
  for b1:=0 to 3 do begin
    for b2:=0 to 3 do begin
      writeln(w:10);
      readln;
    end;
  end;
end.

I know for a fact that w begins at the same memory location as b1, but
in the nested for loops, b1 and
b2 change, so w should change too. Shouldn't it? Yet it doesn't. Can
anyone tell me why?
TIA.

--
Patrick D. Rockwell





Thu, 01 Apr 2004 02:14:43 GMT  
 Use of absolute clause.

Quote:

> I wrote the following program.

> program vals;
> var b1,b2:byte;
>     w:word absolute $23A2:$0052;
> begin
>   writeln(ofs(b1),':',ofs(b1));
>   writeln(ofs(b2),':',ofs(b2));
>   writeln(ofs(w),':',ofs(w));
>   for b1:=0 to 3 do begin
>     for b2:=0 to 3 do begin
>       writeln(w:10);
>       readln;
>     end;
>   end;
> end.

> I know for a fact that w begins at the same memory location as b1, but
> in the nested for loops, b1 and
> b2 change, so w should change too. Shouldn't it? Yet it doesn't. Can
> anyone tell me why?

The stores to memory are optimized away probably. Change the writeln line to

writeln(w:10,b1:5,b2:5);

Now the values are used, and it isn't optimized away (can't test this with
BP atm, am under Unix)



Thu, 01 Apr 2004 03:18:16 GMT  
 Use of absolute clause.

|I wrote the following program.

It worked for me after I modified the segment address for w to match
the segment address of b1.  In order to do this I modified the writeln
statements to write seg:ofs rather than ofs:ofs as you posted.

Also, I input w absolute address in decimal rather than hex to match
the output from the writeln.

Following is my code:

program vals;
var b1,b2:byte;
    w:word absolute 3374:82;
begin
   writeln(seg(b1),':',ofs(b1));
   writeln(seg(b2),':',ofs(b2));
   writeln(seg(w),':',ofs(w));
   for b1:=0 to 3 do begin
      for b2:=0 to 3 do begin
         writeln(w:10);
         readln;
      end;
   end;
end.

Output was: (with double spacing removed)

3374:82
3374:83
3374:82
         0
       256
       512
       768
         1
       257
       513
       769
         2
       258
       514
       770
         3
       259
       515
       771

You could also have defined w as:

w:word absolute b1;

then you don't have to wory about getting the address correct.

Phil



Thu, 01 Apr 2004 18:56:02 GMT  
 Use of absolute clause.

Quote:


> |I wrote the following program.

> It worked for me after I modified the segment address for w to match
> the segment address of b1.  In order to do this I modified the writeln
> statements to write seg:ofs rather than ofs:ofs as you posted.

> Also, I input w absolute address in decimal rather than hex to match
> the output from the writeln.

> Following is my code:

> program vals;
> var b1,b2:byte;
>     w:word absolute 3374:82;
> begin
>    writeln(seg(b1),':',ofs(b1));
>    writeln(seg(b2),':',ofs(b2));
>    writeln(seg(w),':',ofs(w));
>    for b1:=0 to 3 do begin
>       for b2:=0 to 3 do begin
>          writeln(w:10);
>          readln;
>       end;
>    end;
> end.

> Output was: (with double spacing removed)

> 3374:82
> 3374:83
> 3374:82
>          0
>        256
>        512
>        768
>          1
>        257
>        513
>        769
>          2
>        258
>        514
>        770
>          3
>        259
>        515
>        771

> You could also have defined w as:

> w:word absolute b1;

> then you don't have to wory about getting the address correct.

> Phil

Thanks. Later, I discovered that I was using the ofs statement twice in my
original right statements insted of using seg():ofs() like I should have.
Then, I discovered an error in my addressing, but it works now. Thanks
again.

Also, I apologize for my multiple posting of this message, but I had a
problem with my ISP when I wrote it.

--
Patrick D. Rockwell





Fri, 02 Apr 2004 04:31:26 GMT  
 Use of absolute clause.


Quote:

> |I wrote the following program.
...

> You could also have defined w as:

> w:word absolute b1;

Yes. Using literal constants which could change whenever you add a
line of code or boot with a different number of environment variables
is dangerous.

you could even have used Record type to overlay b1 and b2 on the word:

Var x:
  Record case integer of
    1: (b1, b2:Byte);
    2: (w : Word);
  end;

Then you could use x.b1, x.b2 and x.w to access the two bytes or the 1
word. The advantage of this is that it is safer. If you had a LongInt
field, for instance, then x would be the size of the LongInt field,
whereas if you declared

var b1,b2:byte;
    w:word absolute b1;
    li:longint absolute b1;

then it would hang over the end of b1 and b2; assigning a value to li
would then not only change b1 and b2 but whatever happened to come in
the next 2 bytes after them. And you could add the keyword "packed"
before "record" so that it might even still work if you compiled it in
Delphi.

FP



Sat, 03 Apr 2004 18:36:52 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. ?absolute path for "use" clause

2. HELP: Using Date in where clauses EDBEngineError

3. Local SQL bug using OR in WHERE clauses

4. Can you someway edit Query result set which used order by clause

5. Using column id in where clause

6. Absolute Basics on Delphi and ADO

7. Absolute Basics on Delphi and ADO

8. How to get Absolute value in SQL?

9. Var: Byte absolute CSeg:$...

10. which pascal for an absolute beginner ?

11. an absolute beginner : HEX question

12. absolute

 

 
Powered by phpBB® Forum Software