asm_echo.s – Demonstrates calling C from assembly¶
Demonstrates how to call C functions from assembly lanaguage. Implements a UART1 character echo, and calls the configBasic, inChar, and outChar functions.
Include processor-specific headers
.include "xc.inc"
Data section¶
This directive causes the assember to place the following statements in PSV space (constant memory).
.section psv psv
Define a null-terminated ASCII string.
HELLO_MSG: .asciz "asm_echo.s ready!\n"
Code Section¶
This directive causes the assembler to place the following statements in program memory.
.text
;; int main() {
Make main
visible outside this file so that C startup code can call it.
.global _main
_main:
;; char c;
;;
;; W0
;; configBasic(HELLO_MSG)
mov #HELLO_MSG, W0
call _configBasic
;; while (1) {
while_top:
;; W0
;; c = inChar();
call _inChar
;; c++;
inc W0, W0
;; W0
;; outChar(c);
call _outChar
bra while_top
;; }