[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: News from the wooden hut (n/m with n < m)



On 11/7/12 10:24 AM, Benoit0123 wrote:
a) would you initialize SP at the begining of your program by inserting an
instruction LD SP,adress

That fixed it. I assumed that was the problem, but forgot to check before I posted. I have the same problem with CP/M at times too. I just ported over another one of my codes (larger 4K code+data) without issue. Thanks!

For others, my "hello, world" (For OS portability I just need to define "echo"--not optimal, but good enough for my testing):
				
				; Assembler: Macro Assembler AS V1.42
	cpu	z80		; z80 (code was originally 8080
				;   ported to z80, so no zisms)

	org	2000h		; ZBRUN looks here
main:
				; backup stack pointer
	ld	hl,0		; load HL with 0
	add	hl,sp		; HL = HL + SP (load HL with SP)
	ld	(spback),hl	; store HL(SP) to spback:
				; set up new SP
	ld	hl,stack	; HL = address of stack:
	ld	sp,hl		; SP = HL = address of stack:

	ld	hl,hello	; HL to point to hello
	call	print		; print it

				; restore SP
	ld	hl,(spback)	; load saved SP into HL
	ld	sp,hl		; SP = HL

	ret			; back to 6502 land

hello:	db	"\rHELLO, WORLD\r\0"
spback:	db	0,0

print:	ld	a,(hl)		; A <- (HL)
	and	a		; update zero flag
	ret	z		; return if zero
	call	echo		; print char
	inc	hl		; HL++
	jp	print		; back to top

echo:	push	bc		; back up BC to stack
	or	080h		; set 8th bit high (it's an Apple thing)
	ld	c,2		; C <- 2
	rst	28h		; ZBRUN magic
	pop	bc		; restore BC from stack
	ret

	org	$+256		; set stack pointer for 256 bytes
stack: