GB Programming: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
m (Text replacement - "(\bld(?:|i|l|d|h) (?:.+, ?)?)\((.+)\)" to "$1[$2]")
m (Text replacement - "(hl)" to "[hl]")
Line 446: Line 446:
So now, how to access memory? With parentheses! To access memory address $CD38, you just have to use ($CD38). Yay!
So now, how to access memory? With parentheses! To access memory address $CD38, you just have to use ($CD38). Yay!


To access the memory location pointed to by HL, just do... (hl)! It's the same with BC and DE.
To access the memory location pointed to by HL, just do... [hl]! It's the same with BC and DE.


So, to retrieve the value at memory address $6511 into register A : ''ld a, [$6511]''
So, to retrieve the value at memory address $6511 into register A : ''ld a, [$6511]''
Line 494: Line 494:
!C
!C
|-
|-
|INC <nowiki>{reg8 | reg16 | (hl)}</nowiki>
|INC <nowiki>{reg8 | reg16 | [hl]}</nowiki>
|Adds one to the operand ("increments" it)
|Adds one to the operand ("increments" it)
|Affected, except for reg16
|Affected, except for reg16
|Not affected
|Not affected
|-
|-
|DEC <nowiki>{reg8 | reg16 | (hl)}</nowiki>
|DEC <nowiki>{reg8 | reg16 | [hl]}</nowiki>
|Subtracts one to the operand ("decrements" it)
|Subtracts one to the operand ("decrements" it)
|Affected, except for reg16
|Affected, except for reg16
|Not affected
|Not affected
|-
|-
|ADD A, <nowiki>{reg8 | imm8 | (hl)}</nowiki>
|ADD A, <nowiki>{reg8 | imm8 | [hl]}</nowiki>
|Adds the operand to the accumulator
|Adds the operand to the accumulator
|Affected
|Affected
Line 514: Line 514:
|Not affected
|Not affected
|-
|-
|SUB <nowiki>{reg8 | imm8 | (hl)}</nowiki>
|SUB <nowiki>{reg8 | imm8 | [hl]}</nowiki>
|Subtracts the operand from the accumulator. The syntax SUB A, <nowiki>{...}</nowiki> is also valid but less common.
|Subtracts the operand from the accumulator. The syntax SUB A, <nowiki>{...}</nowiki> is also valid but less common.
|Affected
|Affected
Line 582: Line 582:
ld b, [hl]
ld b, [hl]
sub a, b
sub a, b
inc (hl)
inc [hl]
inc hl
inc hl
ld [hl], b
ld [hl], b
Line 819: Line 819:
ld b, [hl]
ld b, [hl]
</pre>
</pre>
If (hl) equals $63, execution jumps to placeItems.
If [hl] equals $63, execution jumps to placeItems.


Otherwise, executions continues through, increments hl twice, then jumps to "someplace"
Otherwise, executions continues through, increments hl twice, then jumps to "someplace"
Line 1,074: Line 1,074:
Notice here that doing ''sub a, b'' actually increased A's value!
Notice here that doing ''sub a, b'' actually increased A's value!


inc (hl) ; (HL) = ($C004) = $DF
inc [hl] ; (HL) = ($C004) = $DF


inc hl ; HL = $C005
inc hl ; HL = $C005