Re: [Amforth] buffer: with memory error????

2018-11-13 Thread Matthias Trute
Am Dienstag, den 13.11.2018, 15:53 + schrieb Jan Kromhout:
> Hello,
> 
> I are struggle with the buffer:
> As you can see I create two array’s.
> I expect that when I initialize this I can read the value.
> It's not true. As you can see, values are overwritten.
> Am I doing something wrong?

I'm pretty sure that all the cells are not what
you want. At least the definition of the buffer
does not match their usage:


> \ Segment byte maps for numbers 0 to 9
>  10 buffer:  Segment_Map_Digit

This is 10 bytes, not 10 cells.

> : Segment_Map_Digit@ cells Segment_Map_Digit + c@ ;

Here you turn a number into a cell-index and access
a single byte. The upper half of the cell is not used
: initSegment_Map_Digit
>   \ Segment byte maps for numbers 0 to 9
>   $c0 0 Segment_Map_Digit!
>   $f9 1 Segment_Map_Digit!
>   $a4 2 Segment_Map_Digit!
>   $b0 3 Segment_Map_Digit!
>   $99 4 Segment_Map_Digit!

The last position inside your buffer.

>   $92 5 Segment_Map_Digit!
>   $82 6 Segment_Map_Digit!
>   $f8 7 Segment_Map_Digit!
>   $80 8 Segment_Map_Digit!
>   $90 9 Segment_Map_Digit!

A classic buffer overflow. You access
memory outside the buffer (9 cells is
18, which is beyond the 10 bytes allocated)

Matthias



___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


[Amforth] buffer: with memory error????

2018-11-13 Thread Jan Kromhout
Hello,

I are struggle with the buffer:
As you can see I create two array’s.
I expect that when I initialize this I can read the value.
It's not true. As you can see, values are overwritten.
Am I doing something wrong?

Cheers,

Jan



\ Segment byte maps for numbers 0 to 9
 10 buffer:  Segment_Map_Digit

\ Byte maps to select digit 1 to 4
4 buffer: SEGMENT_SELECT

: Segment_Map_Digit@ cells Segment_Map_Digit + c@ ;

: Segment_Map_Digit! cells Segment_Map_Digit + c! ;

: SEGMENT_SELECT@ cells SEGMENT_SELECT + c@ ;

: SEGMENT_SELECT! cells SEGMENT_SELECT + c! ;

: initSegment_Map_Digit
  \ Segment byte maps for numbers 0 to 9
  $c0 0 Segment_Map_Digit!
  $f9 1 Segment_Map_Digit!
  $a4 2 Segment_Map_Digit!
  $b0 3 Segment_Map_Digit!
  $99 4 Segment_Map_Digit!
  $92 5 Segment_Map_Digit!
  $82 6 Segment_Map_Digit!
  $f8 7 Segment_Map_Digit!
  $80 8 Segment_Map_Digit!
  $90 9 Segment_Map_Digit!
  \ Byte maps to select digit 1 to 4
  $f1 0 SEGMENT_SELECT!
  $f2 1 SEGMENT_SELECT!
  $f4 2 SEGMENT_SELECT!
  $f8 3 SEGMENT_SELECT!
;


Result :


(ATmega328P)> : test 10 0 do i Segment_Map_Digit@ . cr loop ;
 ok
(ATmega328P)> initSegment_Map_Digit
 ok
(ATmega328P)> hex test
C0
F9
A4
B0
99
F1
F2
F4
F8
90
 ok


___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel