Changes

Jump to: navigation, search

Programming:Filling memory with a byte

1,124 bytes added, 16:12, 12 March 2007
<pre>
;; This code snippet will show one method to fill a block
;; of memory with a single data byte using Z80 assembly
;; language.

;;--------------------------------------------------

;; HL = start address of block
ld hl,&4000

;; DE = HL + 1
ld e,l
ld d,h
inc de

;; initialise first byte of block
;; with data byte (&00)
ld (hl),&00

;; BC = length of block in bytes
;; HL+BC-1 = end address of block

ld bc,&4000

;; fill memory
ldir

;;--------------------------------------------------


;; For each iteration of the LDIR command:
;;
;; 1. This command will copy the byte from the memory
;; address pointed to by HL to the memory address pointed to by DE.
;; i.e. (DE) = (HL).
;; 2. Then HL and DE will be incremented. BC will be decremented.
;;
;;
;; For the first byte:
;;
;; HL = start
;; DE = start+1
;; BC = length
;; (HL)=0
;;
;; For the second byte:
;;
;; HL = start + 1 (initialised to 0 by the previous iteration)
;; DE = start + 2
;; BC = length - 1
;;
;; For the third byte:
;;
;; HL = start + 2 (initialised to 0 by the previous iteration)
;; DE = start + 3
;; BC = length - 2
;;
;; etc....
</pre>
12,273
edits