From 5c974b1fa6be93943d0efd5c32628b3d08fc7ddd Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Mon, 1 Aug 2022 11:30:26 +1200 Subject: [PATCH] vault backup: 2022-08-01 11:30:26 --- content/notes/07-6809-advanced.md | 48 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/content/notes/07-6809-advanced.md b/content/notes/07-6809-advanced.md index e0683e438..c83ddec4e 100644 --- a/content/notes/07-6809-advanced.md +++ b/content/notes/07-6809-advanced.md @@ -6,7 +6,7 @@ tags: - cosc204 --- -10 addressing modes +# addressing modes - implied `inca` - immediate `lda #$00` - extended `LDA $31FE` @@ -25,6 +25,50 @@ tags: - 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 + +- We’re 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 +``` \ No newline at end of file