| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Sugan Subramanian TECHNICAL NOTE TN-18 INTRODUCTION Thi
Top Searches for this datasheetEMBEDDING ASSEMBLY INSTRUCTIONS INSIDE C-SOURCE CODE Sugan Subramanian TECHNICAL NOTE TN-18 INTRODUCTION This tech note embed assembly instructions inside source code. targeted towards programmers have some knowledge C-language R3000 assembly language. IDT/C5.0, assembly instructions inlined inside genuine block C-code. genuine block C-code section C-code enclosed open closed curly braces. inlined assembly include synthetic assembly instructions. These instructions expanded during compile/assembly phase compiler. format agreed IDT/ compiler depends whether inlined assembly lines require arguments, whether these arguments read, written, both. Specifically there cases consider: inline without parameters inline with read only parameters inline with write only parameters inline with read write parameters These four cases will discussed elaborately following sections. specific registers) $0,$1, Coprocessor registers (has Floating Point Accelerator specific registers) Coprocessor registers Coprocessor registers INLINE ASSEMBLY LINES WHICH WRITE-ONLY PARAMETERS Format: asm("<asm instrct1> <asm istrct2> <asm instrct2>; <asm instrctn>" "=<write-only_param1 format>" (<write-only_param1 name>), "=<write-only_param2 format>" (<write-only_param2 name>), "=<write-only_paramk format>" (<write-only_paramk name>)); e.g: i,j; void main() Intialize_Globals(); printf("value %d\n",i,j); void Initialize_Globals() asm("ori %0,$0,3 "=r" (i), "=r" (j)); INLINE ASSEMBLY LINES WITHOUT PARAMETERS Format: asm("<asm instrct1> <asm istrct2> <asm instrct2>; <asm instrctn>") e.g: unsigned get_addr() asm("li $2,0x80020000 0"); Description: "get_addr" function that takes arguments returns unsigned integer. inlined portion function body computes return value (0x80020000) that saved (or) initializes (or) with zero. Constraints: assembly instructions including synthetic instructions allowed. register names should have hardware mnemonics. i.e.: General registers Coprocessor registers (has TLB, configuration logo registered trademark IDT/C trademark Integrated Device Technology, Inc. R3000 trademark MIPS Computer Systems, Inc. ©1996 Integrated Device Technology Description: "Initialize_Globals" function that takes arguments returns nothing. inlined portion function body initializes global variables "j". Uses write-only parameters. Parameter referenced referenced "=r" format both "j". "=r" specifies that following write-only parameter general register associated with Constraints: assembly instructions including synthetic instructions allowed. register names should have hardware mnemonics. R3000, following possible hardware mnemonic: General registers (has TLB, configuration specific registers) 3123/- 2/96 EMBEDDING ASSEMBLY INSTRUCTIONS INSIDE C-SOURCE CODE TECHNICAL NOTE TN-18 Coprocessor registers (has Floating Point Accelerator specific registers) Coprocessor registers Coprocessor registers Coprocessor registers Write-only parameters either global local variables. Write-only parameters indexed from n-1, where number parameters used inlined code. Inside inlined code, write_only_parameter1 accessed write_only_parameter2 accessed These formats that allowed write-only parameters: "=r" Specifies that write-only parameter general register assigned "=f" Specifies that write-only parameter floating point register assigned INLINE ASSEMBLY LINES WHICH USES READ-ONLY PARAMETERS Format: asm("<asm instrct1> <asm istrct2> <asm instrct2>; <asm instrctn>" "<read-only_param1 format>" (<read-only_param1 name>), "<read-only_param2 format>" (<read-only_param2 name>), ."<read-only_paramk format>" (<read-only_paramk name>)); e.g: void main() print("INLINE %d\n", return_3()); return_3() asm("ori $2,$0,%0 (3), (4)); Description: 1."return_3" function that takes arguments returns integer value inlined portion function computes return value. Whenever read only parameters without write only parameters, have colons "::" preceding them specify that there write only parameters. Constraints: assembly instructions including synthetic instructions allowed. register names should have hardware mnemonics. i.e. General registers Coprocessor registers (has TLB, configuration specific registers) Coprocessor registers (has Floating Point Accelerator specific registers) Coprocessor registers Coprocessor registers Read-only parameters indexed from n-1, where number parameters used inlined code. Inside inlined code, Read-only_parameter1 accessed Read-only_parameter2 accessed These formats that allowed read-only parameters: Specifies that parameter general register assigned Specifies that parameter floating point register assigned Specifies that parameter immediate value. "m"_ Specifies that parameter memory address. Specifies that parameter offsettable memory address. Specifies that parameter above. INLINE ASSEMBLY LINES THAT USES WRITE-ONLY READ-ONLY PARAMETERS Format: asm("<asm instrct1> <asm istrct2> <asm instrct2>; <asm instrctn>" "=<output_var1 format>" (<output_var1 name>), "=<output_var2 format>" (<output_var2 name>), "=<output_vark format>" (<output_vark name>) "<input_var1 format>" (<input_var1 name>), "<input_var2 format>" (<input_var2 name>), ."<input_vark format>" (<input_vark name>)); e.g: #define ARRAY_SIZE_IN_BYTES b[20]; void main() a[10]; i,j,k; {asm .set noreorder $11,%2; addiu %0,%3; $11,0(%0); addiu $11,-4; bnez $11,1b; addiu %0,-4; %1,%4; .set reorder" EMBEDDING ASSEMBLY INSTRUCTIONS INSIDE C-SOURCE CODE TECHNICAL NOTE TN-18 (a), (j), (ARRAY_SIZE_IN_BYTES), (10*4), "$11");} printf ("return %d\n",j); i=-1; while (++i printf("a[%d] %d\n",i,a[i]); Description: This program initializes integer array with values starting from through increment displays array. inlined portion only initializes array demonstrates peculiar inline feature, read-write parameter. allowed registers inside inlined assembly lines long declare that they will clobbered. This done giving register name(s) preceded three colons (":::") there write-only read-only parameters, colon (":") following read only parameter(s) there read-only parameters, colons ("::") following write only parameter(s) there only write-only parameters. Constraints: assembly instructions including synthetic instructions allowed. register names should have hardware mnemonics. i.e. General registers Coprocessor registers (has TLB, configuration specific registers) Coprocessor registers (has Floating Point Accelerator specific registers) Coprocessor registers Coprocessor registers Whenever parameter used reading writing, declare such parameters either read-only write-only both. This convention eliminates confusion. previous example, parameter declared read-only used both reading writing. appropriate because both type (have general registers associated with them). Only read-only parameters that have registers associated with them writable. GENERAL RULES WHILE INLINING ASSEMBLY LINES Always enclose your inlined assembly lines block ".set noreorder" ".set reorder" directives that compiler leaves inlined assembly lines untouched even entire code optimized. However, some harmless warning messages generated assembler (IDT/C 5.0) when synthetic assembly instructions expanded; they simply ignored. Declare your variables that read from immediate values that used inside inlined assembly read-only parameters. Declare variables that written write-only parameters. Whenever temporary register used inside inlined assembly code always make sure gets declared clobbered. SUMMARY Inlining assembly lines inside c-code boon itself only optimizing your c-code through having different sections assembly. IDT/C 5.0, inlining assembly lines complemented ability local global variable names aliases registers assigned them. Other recent searchesSA7026 - SA7026 SA7026 Datasheet PLL130-68 - PLL130-68 PLL130-68 Datasheet PLL130-69 - PLL130-69 PLL130-69 Datasheet OS8104 - OS8104 OS8104 Datasheet MS3102 - MS3102 MS3102 Datasheet M56783AFP - M56783AFP M56783AFP Datasheet KP-1608SRC-PRV - KP-1608SRC-PRV KP-1608SRC-PRV Datasheet HGTP14N40F3VL - HGTP14N40F3VL HGTP14N40F3VL Datasheet FSAL200 - FSAL200 FSAL200 Datasheet FSAV330 - FSAV330 FSAV330 Datasheet 1001120000 - 1001120000 1001120000 Datasheet
Privacy Policy | Disclaimer |