User Tools

Site Tools


spo600:6502_counting_loop_example

6502 Counting Loop Example

Here is a solution for part of the 64-bit Assembly Language Lab but implemented in 6502 Assembly language for use with the 6502 Emulator:

 ; ROM routines
 define		SCINIT		$ff81
 define		CHROUT		$ffd2
 START:
 	JSR SCINIT      ; Initialize and clear the screen
 	LDX #$00	; Loop index (0-9)
 LINE:
 	TXA		; Put loop index into A
 	CLC
 	ADC #$30	; Add $30 (ASCII '0')
 	STA MSG_DIGIT	; Store into the string
 	LDY #$00	; Character number to print
 CHARACTER:
 	LDA MSG,Y	; Get a character
 	BEQ DONE	; Done if it's NULL
 	JSR CHROUT	; Print character
 	INY		; Increment char number
 	JMP CHARACTER   ; Process next character
 DONE:
 	INX		; Increment loop index
 	CPX #10		; Is it 10?
 	BNE LINE	; If not, print next line
 	BRK		; Stop
 MSG:
 	DCB "L","o","o","p",$20
 MSG_DIGIT:
 	DCB "#",$0D,$00
 ; Note that MSG_DIGIT is a position in
 ; the middle of the message - not a 
 ; separate message.
spo600/6502_counting_loop_example.txt · Last modified: 2024/04/16 18:10 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki