Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section "vars", WRAM0, align[1]
- src: ds 2
- dst: ds 2
- cnt: ds 2
- section "code", ROM0
- ; After https://en.wikipedia.org/wiki/Intel_8008#Example_code
- memcpy_8008:
- ld l, low(cnt) ; ld bc, [cnt]
- ld h, high(cnt) ; (Pino) Bug fixed
- ld c, [hl]
- inc l
- ld b, [hl]
- .loop:
- ld a, c ; Return if BC is 0
- or b
- ret z
- ld a, c ; dec bc
- sub 1
- ld c, a
- ld a, b
- sbc 0
- ld b, a
- ld l, low(src) ; ld de, [src]
- ld h, high(src) ; (Pino) Bug fixed
- ld e, [hl]
- inc l
- ld d, [hl]
- ld a, c ; ld hl, de+bc
- add e
- ld l, a
- ld a, b
- adc d
- ld h, a
- ld a, [hl] ; Read the byte
- ld l, low(dst) ; ld hl, [dst]
- ld h, high(dst) ; (Pino) Bug fixed
- ld e, [hl]
- inc l
- ld d, [hl]
- ld l, e
- ld h, d
- ld d, a ; save the read byte
- ld a, c ; add hl, bc
- add l
- ld l, a
- ld a, b
- adc h
- ld h, a
- ld [hl], d ; write the byte
- jp .loop
- memcpy_8080:
- ld hl, [cnt]
- ld b, h
- ld c, l
- ld hl, [dst]
- ex de, hl
- ld hl, [src]
- .loop:
- ld a, c
- or b
- ret z
- ld a, [hl]
- inc hl
- ld [de], a
- inc de
- dec bc
- jp .loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement