mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-25 13:54:05 -06:00
88 lines
2.7 KiB
Markdown
88 lines
2.7 KiB
Markdown
---
|
|
title: "6809"
|
|
aliases:
|
|
tags:
|
|
- cosc204
|
|
---
|
|
|
|
[cheatsheet](https://www.chibiakumas.com/6809/CheatSheet.pdf)
|
|
|
|
# Routines
|
|
All variables are global so there is no params or local vars.
|
|
|
|
There are three way to "Branch" to a subroutine.
|
|
- lbsr
|
|
- bsr
|
|
- jsr
|
|
|
|
There are subtle differences but we will use bsr mostly
|
|
|
|
```
|
|
bsr myroutine:
|
|
|
|
myroutine:
|
|
rts
|
|
```
|
|
|
|
# Iteration
|
|
Done using GOTOs
|
|
```
|
|
clra //A = 0
|
|
more:
|
|
cmpa #$06 //compare A to $06 (sets the equal flag in CC if true)
|
|
beq done //if the equal flag is set, branch to done
|
|
inca //increment a
|
|
bra more //branch to more
|
|
done:
|
|
```
|
|
|
|
other instructions set flags too
|
|
|
|
# Input/Output
|
|

|
|
|
|
The screen always displays whatever is in the "screens memory location" which is $0400
|
|
|
|
``` 6809 assembly
|
|
lda #'H' ; load the character (indicated by '') into the a register
|
|
sta $0400 ; store the contents of the a register in memory at location $0400
|
|
```
|
|
|
|
## printing a whole string
|
|
|
|
``` 6809 assembly
|
|
message:
|
|
.byte "HELLO WORLD", 0
|
|
|
|
START:
|
|
ldy #message ; load "message", into the y register
|
|
bsr puts ; branch to the "puts" subroutine
|
|
rts ; return
|
|
|
|
; Routine: PUTS
|
|
; Pass the address of the string in Y
|
|
;
|
|
screen EQU $0400 ; start of screen
|
|
|
|
PUTS:
|
|
pshs a,x,y ; save a, x, and y ; store the contents of the a, x, and y registers so they are not overwritten
|
|
ldx #screen ; start of screen ; load the hex value of the memory location of the screen ($0400) into the x register
|
|
more:
|
|
lda 0,y+ ; current char -> A ; load the contents of the Y register into the A register and increment Y by one
|
|
cmpa #$00 ; was it a zero? ; if the character loaded into A was a zero set the equal flag
|
|
beq done ; if it was 0 then return ; if the equal flag is set, branch to the "done" subroutine
|
|
sta 0,x+ ; write ; otherwise, store the contents of the A register into memory at the location (hex value) defined in the X register, and increment the hex value stored in the X register
|
|
bra more ; repeat ; branch to the "more" subroutine as there are more character to write
|
|
done:
|
|
puls a,x,y ; restore a, x, y ; re load the stored values of the a, x, and y registers that were saved earlier
|
|
rts ; return from this routine
|
|
```
|
|
|
|
# Assembler
|
|
- compiles assemble to machine code
|
|
- can also dissamble machine code
|
|
|
|
assembler create a listing file that gives the location, machines lcode, and assembly of the program
|
|

|
|
|