Help Understanding a line of code
bdickens
Posts: 110
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 ?
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
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
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.