72 lines
1.1 KiB
Z80 Assembly
72 lines
1.1 KiB
Z80 Assembly
func_fs:
|
|
;input
|
|
;hl = function to call
|
|
;ix = data range to operate over
|
|
;de = output area
|
|
;b = length of data range
|
|
|
|
push bc
|
|
ld (smc_fs+1),hl
|
|
ld a,(ix+0)
|
|
smc_fs:
|
|
call 0 ;overwritten with the function address passed in HL
|
|
|
|
ld (de),a
|
|
inc ix
|
|
inc de
|
|
pop bc
|
|
djnz func_fs
|
|
ret
|
|
|
|
f: ;dummy function - returns input as-is
|
|
ret
|
|
|
|
f1:
|
|
;returns A times 2
|
|
sla a
|
|
ret
|
|
|
|
f2:
|
|
;returns A squared
|
|
ld b,a
|
|
jp square_small
|
|
;ret
|
|
|
|
data1:
|
|
db 0,1,2,3
|
|
|
|
data2
|
|
db 2,4,6,8
|
|
|
|
output:
|
|
ds 4
|
|
|
|
;these libraries allow us to write the output to the screen
|
|
read "\SrcCPC\winape_monitor.asm"
|
|
read "\SrcCPC\winape_stringop.asm"
|
|
read "\SrcCPC\winape_showhex.asm"
|
|
|
|
square_small:
|
|
;returns a*a into a
|
|
LD C,B
|
|
mul8_small:
|
|
;multiplies two 8-bit regs, product is also 8 bit.
|
|
;no overflow protection!
|
|
;computes A = c * b
|
|
ld a,c
|
|
or a
|
|
ret z
|
|
|
|
djnz skip_return_C
|
|
;ADVANCED TRICKERY:
|
|
; we need to decrement B anyway.
|
|
; also if B = 1, then A = C.
|
|
; C is already in A, which we need for the multiplication regardless.
|
|
; This does the job for us in one instruction!
|
|
; Most DJNZs are backward but this one is FORWARD!
|
|
ret
|
|
skip_return_C:
|
|
add C
|
|
djnz skip_return_C
|
|
ret
|