Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / preserves_regs.c.in
blob73e9004f66312c927fd6f61ec84ba5d2af502600
1 /* __preserves_regs test
2 type: unsigned char, unsigned int, unsigned long
3 */
5 #include <testfwk.h>
7 #if defined(__SDCC_z80) || defined(__SDCC_z80n) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined(__SDCC_ez80_z80)
8 void write_bc(void) __preserves_regs(a, d, e, h, l, iyl, iyh) __naked
10 __asm
11 ld bc, #0
12 ret
13 __endasm;
16 void write_de(void) __preserves_regs(a, b, c, h, l, iyl, iyh) __naked
18 __asm
19 ld de, #0
20 ret
21 __endasm;
24 void write_hl(void) __preserves_regs(a, b, c, d, e, iyl, iyh) __naked
26 __asm
27 ld hl, #0
28 ret
29 __endasm;
32 {type} add_bc({type} a, {type} b)
34 {type} r = a + b;
36 write_de();
37 write_hl();
39 return(r);
42 {type} add_de({type} a, {type} b)
44 {type} r = a + b;
46 write_bc();
47 write_hl();
49 return(r);
53 {type} add_hl({type} a, {type} b)
55 {type} r = a + b;
57 write_bc();
58 write_de();
60 return(r);
64 {type} add_iy({type} a, {type} b)
66 {type} r = a + b;
68 write_bc();
69 write_de();
70 write_hl();
72 return(r);
74 #endif
76 void testRegs(void)
78 #if defined(__SDCC_z80) || defined(__SDCC_z80n) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined(__SDCC_ez80_z80)
79 ASSERT(add_bc(0x55, 0xaa) == ({type})(0x55 + 0xaa));
80 ASSERT(add_de(0x55, 0xaa) == ({type})(0x55 + 0xaa));
81 ASSERT(add_hl(0x55, 0xaa) == ({type})(0x55 + 0xaa));
82 ASSERT(add_iy(0x55, 0xaa) == ({type})(0x55 + 0xaa));
83 #endif