#include "asm86.h" ;I use Asm86 to compile, so I include thisThe most important thing you need to understandis what a register is, and how to use it. A register is a 16bit (2byte) memory location, found on the CPU itself. On the Z80 you havethe following important Registers:
#include "ti86asm.inc" ;this is TI's includefile.org _asm_exec_ram ;starting point for all asm progs, $D748
; all the ASM goes in here
.end
ld a,0 ; loads the value0 into register aThe register HL, is primarly used for ADDRESSING,this means it usually points to another memory location. The videoMemory is located at $FC00, so to have hl "point" to the video memory youuse the command:
ld b,2 ; loads the value 2 intoregister b
ld de,257 ; loads the value 257 into register de
;(same as loading 1 into d and 1 into e)
ld d,$0A ; NOTE $8A represents a HEX number,
; %00100100 represents a BIN number,
; 52 just a decimal number.
; this loads $0A into d, $0A is the same as 10
ld a,d ; loads the current valueof d into a (in this case 10)
NOTE:An 8-bit regiser can only hold the values from 0-255 (%00000000-%11111111),but a 16 bit register can hold the values 0-65535.
ld hl,$FC00 ;loads the value $FC00 into registerhlNow, to copy a value into the memory locationthat HL is pointing to, we do somthing called inderect addressing. This is accomplished by placing parens around the register name.
ld a,%10101010 ;loads thevalue %10101010 into reg. aback to list of instructions
ld (hl),a ;loads the value %10101010 into the
;memory location that hl "points" to
;the value of HL is $fc00 therefore
;the value %10101010 is loaded into
;memory location $fc00, which happens
;to be the video memory :)
;IT DOES NOT CHANGE THE VALUE OF HL!!
ld a,(hl) ;similiarly this loads the value at
;mem location $fc00 into the reg. a
ld a,8 ;a=8In order to add anything to the other registers, you mustdo it inderectly:
add a,10 ;a=a+10 a=18
ld hl,$FC00 ;hl = $FC00
ld bc,$00BB ;bc = $00BB
add hl,FCBB ;hl=hl+bc hl = $fcbb
ld b,8 ;b=8Now you know how to add, what about subtracting?
ld a,b ;a=b
add a,5 ;a='b+5'
ld b,a ;b='b+5';or
ld bc,46 ;bc=46
ld h,b ;you can't do'ld hl,bc'
ld l,c ;
ld bc,52 ;
add hl,bc ;hl = bc+52
ld b,h ;.
ld c,l ;bc =bc+52
ld a,16 ;a=16ADD and SUB let you add or subtract any number, however ifyou only want to add or subract the value 1 then you can use INC/DEC
sub 5 ;a=a-5, a=11ld b,65 ;b=65
ld a,b ;a=65
sub 6 ;a=65-6, a=59
ld b,a ;b=59
ld a,5 ;a=5back to list of instructions
inc a ;a=a+1, a=6
ld b,a ;b=a, b=6
dec b ;b=b-1, b=5ld bc,568 ;bc=568
inc bc ;bc=bc+1, bc=569
inc bc ;bc=bc+1, bc=570