From 494b0619d707c0c9ea8da9c395124e2cefe6f854 Mon Sep 17 00:00:00 2001 From: uz Date: Wed, 7 Dec 2011 21:08:14 +0000 Subject: [PATCH] =?utf8?q?Added=20more=20sample=20for=20the=20inline=20ass?= =?utf8?q?embler.=20Contributed=20by=20Steffen=20G=C3=B6rzig.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.cc65.org/cc65/trunk@5308 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/cc65.sgml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index a1731879a..74eb1702c 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -1200,8 +1200,8 @@ the format specifier before passing the assembly code line to the backend.

+The next example shows how to use global variables to exchange data between C +an assembler and how to handle assembler jumps: + + + unsigned char globalSubA, globalSubB, globalSubResult; + + /* return a-b, return 255 if b>a */ + unsigned char sub (unsigned char a, unsigned char b) + { + globalSubA = a; + globalSubB = b; + __asm__ ("sec"); + __asm__ ("lda %v", globalSubA); + __asm__ ("sbc %v", globalSubB); + __asm__ ("bcs %g", jumpSubNoError); + __asm__ ("lda #$FF"); + jumpSubNoError: + __asm__ ("sta %v", globalSubResult); + return globalSubResult; + } + +

+ +Arrays can also be accessed: + + + unsigned char globalSquareTable[] = { + 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, + 100, 121, 144, 169, 196, 225 + }; + unsigned char globalSquareA, globalSquareResult; + + /* return a*a for a<16, else 255 */ + unsigned char square (unsigned char a) + { + if (a>15){ + return 255; + } + globalSquareA = a; + __asm__ ("ldx %v", globalSquareA); + __asm__ ("lda %v,x", globalSquareTable); + __asm__ ("sta %v", globalSquareResult); + return globalSquareResult; + } + +

Note: Do not embed the assembler labels that are used as names of global variables or functions into your asm statements. Code like this -- 2.39.5