Shop OBEX P1 Docs P2 Docs Learn Events
Help Understanding a line of code — Parallax Forums

Help Understanding a line of code

bdickensbdickens Posts: 110
edited 2010-08-18 13:47 in Propeller 1
I am looking at a line in a program

if byte[long[bufp]+k] <> byte[ds+j]

I've used the byte command just like the back have of the statement (byte[ds+j]) but I am candidly a bit confused by the first one. Assuming that K = 1

Long[Bufp]+K should produce the next long address past the BufP address

Does byte[long[bufp]+k] produce the first byte of the next long address ? if so why wasn't this just byte[bufp]+(K*4) or at least byte[BufP]+4 ? Was there some benefit that I'm not seeing ?

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-08-18 12:54
    long[bufp] must contain an address. If you want to move a long, yes, multiples of 4 will need to be added. If only 1 is incremented, you will get weird combinations of the bytes in the long. But it appears you are reading bytes, so increments of 1 look like it should work. More of the code would be helpful to explain how the data is stored.
  • ErNaErNa Posts: 1,753
    edited 2010-08-18 13:37
    Addressing is a bit confusing, I agree, had the same problem.
    It is simply that way:

    Memory addresses pointing to global memory are always addressing bytes. That's all.

    Now, how to determine an address:
    if you write byte[long[bufp]+k] then the address of byte is a long, the first byte of the long located at bufp. Naturally, the next address of the next byte is located 4 bytes behind.

    Yes, it is complicated. I did it that way: testing it once fully by dumping pointers and content. And now I only copy and paste that code snipped and don't care any more ;-))

    Never want to know again, what this is doing
    if NOT StrComp (@byte[@@(Word[ObjPtr][  2])], @byte[@@(Word[ObjPtr][  2])+ StrSize(@byte[@@(Word[ObjPtr][  2])])+ 1])
    
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-18 13:47
    long[bufp] assumes that bufp contains a hub address that's a multiple of 4 and its value is the content of the long at that address (bufp).

    long[bufp]+k is the content of the long plus the value of k.

    byte[long[bufp]+k] is the content of the byte at the above address.
Sign In or Register to comment.