quartz/content/notes/07-6809-advanced.md
2022-08-01 11:30:26 +12:00

74 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "07-6809-advanced"
aliases:
tags:
- lecture
- cosc204
---
# addressing modes
- implied `inca`
- immediate `lda #$00`
- extended `LDA $31FE`
- extended indirect `LDA [$31FE]` or `LDA [HERE]` points to a memory location which specifies another memory location
- direct `LDA $ff` or `lda <HERE`
- register `trf X,Y`
- indexed `LDA $3111E, X` use memory location that is the sum of the operands
- `LDA ,X`
- `LDA $23,X`
- etc
- indexed indirect `LDA [$10, X]`
- relative `BEQ HERE`
- BEQ does a short branch
- LBEQ does a long branch
- the value is relative to HERE
- program counter relative `LDA TABLE,PCR ; A = the value stored at TABLE`
- if all memory references are relative, then the program cna be loaded anywhere is memory, and will still work. It is said to be **relocatable**
![operand cheat sheet](https://i.imgur.com/mA7Y8bE.png)
# Calling conventions
all global vars. this is discouraged in high level languages
The calling convention is the set of rules that describe
- How to pass parameters
- How to return a result
- Which registers a routine may alter
## CMOC
a 6809 C compiler
callling conventions
- A routine must preserve Y, U, S and DP
- A routine may change A, B, X and CC
- Parameters are pushed on the stack in the reverse order
- The caller pops them off the stack after the call
- char parameters are promoted to int
- unsigned char are promoted to unsigned int
- Return 8-but values in B
- Return 16-bit values in D
- Were not going to talk about passing a struct by value
### example in C
``` c
uint16_t two_params(uint8_t first, uint16_t second) {
return first + second;
}
uint16_t call_one(void) {
return two_params(204, 431);
}
```
```
LDD #$01AF ;
decimal 431 PSHS B,A ;
argument 2, int CLRA LDB #$CC ;
decimal 204 PSHS B,A ;
argument 1, int LBSR _two_params
```