Difference between revisions of "6502 Counting Loop Example"

From CDOT Wiki
Jump to: navigation, search
(Created page with "Category:6502 AssemblerCategory:SPO600Here is a solution for part of the SPO600 64-bit Assembly Language Lab but implemented in 6502 Assembly language for use with...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:6502 Assembler]][[Category:SPO600]]Here is a solution for part of the [[SPO600 64-bit Assembly Language Lab]] but implemented in 6502 Assembly language for use with the [[6502 Emulator]]:
+
[[Category:6502]][[Category:SPO600]]Here is a solution for part of the [[SPO600 64-bit Assembly Language Lab]] but implemented in 6502 Assembly language for use with the [[6502 Emulator]]:
  
 
  ; ROM routines
 
  ; ROM routines
Line 6: Line 6:
 
   
 
   
 
  START:
 
  START:
 +
JSR SCINIT      ; Initialize and clear the screen
 
  LDX #$00 ; Loop index (0-9)
 
  LDX #$00 ; Loop index (0-9)
 
   
 
   
  GO:
+
  LINE:
 
  TXA ; Put loop index into A
 
  TXA ; Put loop index into A
 
  CLC
 
  CLC
Line 15: Line 16:
 
   
 
   
 
  LDY #$00 ; Character number to print
 
  LDY #$00 ; Character number to print
  DO:
+
  CHARACTER:
 
  LDA MSG,Y ; Get a character
 
  LDA MSG,Y ; Get a character
 
  BEQ DONE ; Done if it's NULL
 
  BEQ DONE ; Done if it's NULL
 
  JSR CHROUT ; Print character
 
  JSR CHROUT ; Print character
 
  INY ; Increment char number
 
  INY ; Increment char number
  JMP DO ; Process next character
+
  JMP CHARACTER  ; Process next character
 
   
 
   
 
  DONE:
 
  DONE:
 
  INX ; Increment loop index
 
  INX ; Increment loop index
 
  CPX #10 ; Is it 10?
 
  CPX #10 ; Is it 10?
  BNE GO ; If not, branch to GO
+
  BNE LINE ; If not, print next line
 
  BRK ; Stop
 
  BRK ; Stop
 
   
 
   

Latest revision as of 02:45, 18 December 2023

Here is a solution for part of the SPO600 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.