/* * Testing inline assembler with HI-TECH C under CP/M * Version for PC CP/M emulator w/o OUT instructions */ #include void testNegation(); void digitalWrite(char dataPin, char state); void fnctpar(unsigned int); void regvar1(); void regvar2(); unsigned char portData; #ifndef false #define false 0 #endif #ifndef true #define true 1 #endif #ifndef LOW #define LOW 0 #endif #ifndef HIGH #define HIGH 1 #endif /* Entry point to program */ int main() { char c; printf("Hello world !\n"); printf("======================================\n"); printf("Getting function parameter to register\n"); fnctpar(170); printf("--------------------------------------\n"); printf("Press Enter to continue..."); scanf("%c", &c, 1); fnctpar(85); printf("--------------------------------------\n"); printf("Press Enter to continue..."); scanf("%c", &c, 1); fnctpar(3855); printf("--------------------------------------\n"); printf("Press Enter to continue..."); scanf("%c", &c, 1); printf("======================================\n"); /* This page says: www.vcfed.org/forum/archive/index.php/t-50530.html If there is a register variable (there is at most one) it's in register IY L.V.: Note this is NOT TRUE, variable declared as 'register' is accessible via IX-displacement as other local variables ! 'register' it is just a hint to the compiler. It is up to the latter to satisfy your desire or not. L.V.: Note 2 - register hint for pointer works, IY is used for it (max one). See regvar3() in HELLOEMU.AS */ printf("Getting register-variable to register pair - OPTIMALIZED\n"); regvar1(); printf("--------------------------------------\n"); printf("Getting register-variable to register pair - NOT OPTIMALIZED\n"); regvar2(); printf("--------------------------------------\n"); regvar3(); printf("======================================\n"); return 0; } /* Getting register-variable to register pair HL */ /* Expect, that compiler optimalized storing 'register unsigned int ri' to IY */ void regvar1() { register unsigned int ri = 3855; /* 0000111100001111 */ unsigned int iy_copy = 0; #asm PUSH AF PUSH HL PUSH IY POP HL ; HL <= IY /* Local variables can be accessed by IX-displacement */ /* Because we expect that 'ri' is in IY, iy_copy is at IX-1, IX-2 */ LD (IX-1), H ; Put the high-byte to local 'iy_copy' LD (IX-2), L ; Put the low-byte to local 'iy_copy' POP HL POP AF #endasm /* This comparsion fails */ printf("ri: %d, iy_copy: %d\n", ri, iy_copy); /* Assure that ri and iy_copy have the same value */ printf("ri: %4.4x, iy_copy: %4.4x\n", ri, iy_copy); /* Assure that ri and iy_copy have the same value */ } /* Getting register-variable to register pair HL */ /* Expect, that compiler DO-NOT optimalized storing 'register unsigned int ri' to IY */ void regvar2() { register unsigned int ri = 3855; /* 0000111100001111 */ unsigned int li = 0; #asm PUSH AF PUSH HL /* Local variables can be accessed by IX-displacement */ LD H, (IX-1) ; Pick up the high-byte of reg. local 'ri' LD L, (IX-2) ; Pick up the low-byte of reg. local 'ri' LD (IX-3), H ; Put the high-byte to local 'li' LD (IX-4), L ; Put the low-byte to local 'li' POP HL POP AF #endasm /* This comparsion success */ printf("ri: %d, li: %d\n", ri, li); /* Assure that ri and li have the same value */ printf("ri: %4.4x, li: %4.4x\n", ri, li); /* Assure that ri and li have the same value */ } regvar3() { char ch1; register char *p_ch1; char ch2; register char *p_ch2; ch1 = ' '; p_ch1 = &ch1; /* Store address of 'ch1' in pointer variable, register IY is used */ *p_ch1 = 'x'; /* LD (IY+0), 120 */ ch2 = ' '; p_ch2 = &ch2; /* Store address of 'ch2' in pointer variable, only one pointer may be optimalized by 'register' keyword so IY isn't used */ *p_ch2 = 'y'; /* LD (IY+0), 120 */ printf("ch1: %c, ch2: %c\n", ch1, ch2); } /* Getting function parameter to register */ void fnctpar(unsigned int fi) { unsigned int li = 0; #asm PUSH AF PUSH HL /* Function parameters can be accessed by IX+displacement */ /* The first argument is located at (IX+6) */ LD H, (IX+7) ; Pick up the high-byte of parameter 'fi' LD L, (IX+6) ; Pick up the low-byte of parameter 'fi' /* Local variables can be accessed by IX-displacement */ LD (IX-1), H ; Put the high-byte to local 'li' LD (IX-2), L ; Put the low-byte to local 'li' POP HL POP AF #endasm printf("fi: %d, li: %d\n", fi, li); /* Assure that fi and li have the same value */ printf("fi: %4.4x, li: %4.4x\n", fi, li); /* Assure that fi and li have the same value */ }