Implicit type conversion: Difference between revisions

Line 1,643:
var b3 = b1 + b2 + 2 + "2"
System.print(b3) // 100</lang>
 
=={{header|Z80 Assembly}}==
As with other assembly languages, types don't really exist in the sense that we're used to thinking about them. All the functionality is there but there are no "rules" forbidding you from doing anything particular with data. Type "conversion" doesn't happen by itself, but there is sort of "type casting" if you will, in the sense that the programmer can decide whether a particular bit pattern represents an integer, a pointer, etc. whenever the programmer wants. Type conversion in the "modern" sense (such as an integer becoming a float or a string) will have to be done manually.
 
When a constant or 16-bit register is used as an operand and is in parentheses, it is treated as a pointer to memory for that instruction only. The type of the data pointed to depends on the instruction.
 
<lang z80>LD HL,$4000 ;load HL with the number 0x4000
LD A,(HL) ;load the byte stored at memory address 0x4000 into A.
 
LD DE,($C000) ;load DE with the 16-bit value stored at $C000.</lang>
 
'''Note:''' The Game Boy cannot use 16-bit constant pointers, with two exceptions:
* Reading/writing in the $FF00-$FFFF memory range.
* Storing the stack pointer at a constant 16-bit address. (The stack pointer can only be saved this way, it cannot be loaded this way.)
 
The individual 8-bit registers that form a register pair can be operated on separately, or as a single 16-bit value.
<lang z80>LD BC,$1234
INC B ;BC = $1334
INC C ;BC = $1335
INC BC ;BC = $1336</lang>
 
 
=={{header|zkl}}==
1,489

edits