Studying pointers: Can we say that asterisk operator * in C is analog to parenthesis in assembler of Z80?
In other words, are this two sentences have similar meaning:
LOAD (HL),a; VS *HL=a;
Studying pointers: Can we say that asterisk operator * in C is analog to parenthesis in assembler of Z80?
In other words, are this two sentences have similar meaning:
LOAD (HL),a; VS *HL=a;
I suggest you to not make such assumptions because they're not always correct. Although what you say might be true in some circumstances, this cannot be generalized, so I wouldn't think it is correct. This is because C is a higher level language than assembly and thus has some abstractions assembly does not have. What happens if the pointer is pointing to data that cannot fit into one register? What happens when pointer to a struct or union?
I suggest you use your compiler to check the assembly generated for different pointer types and see by yourself.
A pointer is a memory address. In C when you dereference a pointer you fetch or store an item of the referenced type from or to the address stored in the pointer. In C when you perform LD (HL), A
you fetch a byte from the address stored in HL
. So in that regard the two things are strongly related.
However the brackets are used inconsistently in Z80 assembler so as not really to be meaningfully an operator. For example, the following:
JP (HL)
Is the usual way of expressing the operation that loads HL
to the program counter. Nothing is fetched from memory, it's just a direct assignment — I guess the confusing syntax arises because that implies that what's at HL will be read in the future by virtue of program execution.
As a second example, see:
OUT (C), A
That stores the byte in A
to the port BC
. So the brackets are acting to say that the thing inside them will be read or written to, but the thing inside the brackets is an abbreviation (technically because the original 8080 only did 8-bit port addressing so Zilog didn't want to confuse things).
Certainly. another examples (there should be type-casts in real programs!):
LD DE,HL -- DE=HL
LD DE,(HL) -- DE=*HL (add typecast: DE=(int *)*HL
LD DE,((HL)) -- DE=**HL (add typecasts: DE=(int *)**(int **)HL