?? bubble.c
字號(hào):
/* * Example: Bubble Sort (bubble.c): PowerPC target. * * bubble.c Includes: * function "main" - generated in default ".text" section; * function "sort" - generated in ".text2" section; * assembler macro "get_short"; * data "array" - copied from ROM to RAM for execution; * data "input_count" at location known during compilation. * swap.s Assembly function generated in ".text2" section. * crt0.s Assembly startup and termination module. */#include <stdio.h>extern void swap (int array[]);/* "I/O registers" at address known during compilation. */#pragma section IOREG far-absolute RW address=0xf0000#pragma use_section IOREG input_count short input_count; static int test_count; /* Uninitialized variable in .sbss. */ int array[] = { /* Initialized variable in */ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 /* .data section. */ };asm short get_short (short *address_p) /* Assembler macro: read and */{ /* byte-swap a 2-byte I/O port. */% reg address_p; /* Parameter passing method. */ lha r4,0(address_p) /* I/O value *address_p to r4. */ rlwimi r3,r4,8,16,23 /* Move value's lsb into r3's msb. */ rlwimi r3,r4,24,24,31 /* Move value's msb into r3's lsb. */}/* Generate subsequent code in section ".text2". */#pragma section CODE ".text2"static void sort (int array [], int count){ int change = 1; int i; while (change) { change = 0; for (i = 0; i < count - 1; i++) { test_count ++; if (array[i] > array[i+1]) { swap (& array[i]); change = 1; } } }}/* Switch code generation back to default ".text" section, */#pragma section CODEvoid main (void){ int count; int i; count = get_short (& input_count); printf ("\nInitial array: "); for (i = 0; i < count; i++) printf ("%d ", array[i]); sort (array, count); printf ("\n\nNumber of tests: %d\n\nSorted array: ", test_count); for (i = 0; i < count; i++) printf ("%d ", array[i]); printf ("\n\n"); exit (0);}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -