📄 sa_call.sa
字号:
******************************************************************************* callex.sa * Copyright (c) 1998 Texas Instruments Incorporated** This is an example of using the ".call" directive in C6x linear assembly.* It initializes an array to random integer values, prints the array out,* sorts the array, then prints the array out again. While functions in* the C RTS library are used, all user code is contained in this linear* assembly source file, including the function "_main". Other than "_main",* all function names which begin with "_" are from the C RTS library.** Running this example requires full C I/O support. It will only execute* when run under a loader, simulator, or emulator provided by TI.** To compile and link ...** cl6x callex.sa -z -o callex.out -c -l rts6201.lib [link.cmd]** - rts6201.lib must be in a directory listed in C_DIR environment variable* - Optionally use link.cmd to specify custom MEMORY and SECTIONS linker* directives****************************************************************************** SIZE .set 100 ; size of the integer array .bss array,SIZE*4,4 ; declare the array .global _main ; global func defined here .global _qsort,_rand,_ltoa,_puts ; global funcs called MVK32 .macro k,reg ; macro for loading 32-bit MVKL k,reg ; constants MVKH k,reg .endm .text******************************************************************************* MAIN - Define the "main" routine the compiler environment expects.* The function "_qsort" sorts the array using the Quicksort algorithm.* For details on the arguments to "_qsort", consult the Compiler* User's Guide******************************************************************************_main .cproc .reg aptr,size,longsz,funcptr MVK32 array,aptr ; load base of the array MVK SIZE,size ; load size of the array .call init_array(aptr, size) ; initialize the array .call print_array(aptr, size) ; print array out MVK 4,longsz ; load size of a int in bytes MVK32 intcmp,funcptr ; load address of compare func .call _qsort(aptr, size, longsz, funcptr) ; sort .call print_array(aptr, size) ; print the array out .endproc ******************************************************************************* INIT_ARRAY - Initialize each element of the array by calling the C RTS* function "_rand"******************************************************************************init_array .cproc aptr, size .reg retvalloop1: .call retval = _rand() ; call _rand STW retval,*aptr++ ; store result [size] SUB size,1,size ; decrement [size] B loop1 ; branch .endproc******************************************************************************* PRINT_ARRAY - Print the array out. The function "_putstr" prints a string* and a newline to stdout. The function "_ltoa" converts a* 40-bit long to an ASCII string. ******************************************************************************;-----------------------------------------------------------------------------; Define some strings for printing out;----------------------------------------------------------------------------- .sect ".const"initstr: .string "Printing out the array", 0 marker: .string "----------------------", 10, 0 ; '10' == newline;-----------------------------------------------------------------------------; Declare an array for holding the string returned by _ltoa;----------------------------------------------------------------------------- .bss charbuf,20 .textprint_array .cproc aptr, size .reg bufptr, valhi:vallo MVK32 initstr,bufptr .call _puts(bufptr) ; print initial message MVK32 charbuf,bufptr ; load buffer addressloop2: LDW *aptr++,vallo ; load array value SHR vallo,31,valhi ; sign extend it .call _ltoa(valhi:vallo, bufptr) ; convert to string .call _puts(bufptr) ; print it out [size] SUB size,1,size ; decrement [size] B loop2 ; branch MVK32 marker,bufptr .call _puts(bufptr) ; print closing message .endproc******************************************************************************* INTCMP - The function _qsort has as one of its arguments the address of* the function for comparing two elements in the array. This is* the function which is passed. Return the difference of the two* elements. See the Compiler User's Guide for details on the* arguments.******************************************************************************intcmp .cproc p1, p2 .reg val1, val2, diff LDW *p1,val1 ; load left value LDW *p2,val2 ; load right value SUB val1,val2,diff ; subtract .return diff ; return difference .endproc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -