3

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;
Ilan
  • 401
  • 1
  • 8
  • 21
  • 3
    There aren't "operators" per se in assembler, but you're generally on the right track. I'd call `(HL)` a *memory operand*, which corresponds to dereferencing a pointer in C. – Kerrek SB Jul 25 '13 at 07:35
  • 1
    Whow !!! Z80 assembly ! I worked on that in the 80's ! Does those still are used nowadays ? – hivert Jul 25 '13 at 07:42
  • 1
    yes it is, many stationary phones in many countries are still z80/81 based – Ilan Jul 25 '13 at 07:44
  • 1
    @hivert: Actually, 8-bit CPUs still outnumber 16, 32, and 64 bit CPUs by a tidy margin, measured by numbers sold. ;-) – DevSolar Jul 25 '13 at 07:52
  • 1
    @DevSolar would like to get a reference about this last statement :) – m0skit0 Jul 25 '13 at 11:46
  • Ethernet components like phys and macs have 8051's buried in them. Does your computer or laptop have ethernet? Do you have a mouse or a hard drive or clock radio or other items that at least some percentage have a process or in them? For every one x86 processor you have you have dozens to hundreds of non-intel processors many arm b ased but many others as well. – old_timer Jul 25 '13 at 13:59
  • 1
    @m0skit0: http://www.extremetech.com/computing/72494-embedded-processors-part-one – DevSolar Jul 26 '13 at 06:40

3 Answers3

2

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.

m0skit0
  • 25,268
  • 11
  • 79
  • 127
0

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).

Tommy
  • 99,986
  • 12
  • 185
  • 204
-1

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
Lorinczy Zsigmond
  • 1,749
  • 1
  • 14
  • 21