?? bubble.c
字號:
/* * Example: Bubble Sort (bubble.c): 68K 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 .bss. */ 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. */% mem address_p; /* Parameter passing method. */ move.w (address_p),d0 /* Get value to return reg. */ rol.w #8,d0 /* Swap two low bytes in return reg.*/}/* 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);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -