130 lines
2.0 KiB
C
130 lines
2.0 KiB
C
|
|
#include "stdint.h"
|
|
#include "head.h"
|
|
|
|
|
|
|
|
// 无符号大小比较
|
|
void test1(uint32_t a,uint32_t b){
|
|
if(a>b){
|
|
my_printf("%u>%u\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%u<%u\n",a,b);
|
|
}else{
|
|
my_printf("%u==%u\n",a,b);
|
|
}
|
|
}
|
|
|
|
|
|
// 有符号大小比较
|
|
void test2(int32_t a,int32_t b){
|
|
if(a>b){
|
|
my_printf("%d>%d\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%d<%d\n",a,b);
|
|
}else{
|
|
my_printf("%d==%d\n",a,b);
|
|
}
|
|
}
|
|
|
|
// uint16_t 大小比较
|
|
void test3(uint16_t a,uint16_t b){
|
|
if(a>b){
|
|
my_printf("%u>%u\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%u<%u\n",a,b);
|
|
}else{
|
|
my_printf("%u==%u\n",a,b);
|
|
}
|
|
}
|
|
|
|
void test4(int16_t a,int16_t b){
|
|
if(a>b){
|
|
my_printf("%d>%d\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%d<%d\n",a,b);
|
|
}else{
|
|
my_printf("%d==%d\n",a,b);
|
|
}
|
|
}
|
|
|
|
|
|
// uint8_t 大小比较
|
|
void test5(uint8_t a,uint8_t b){
|
|
if(a>b){
|
|
my_printf("%u>%u\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%u<%u\n",a,b);
|
|
}else{
|
|
my_printf("%u==%u\n",a,b);
|
|
}
|
|
}
|
|
|
|
void test6(int8_t a,int8_t b){
|
|
if(a>b){
|
|
my_printf("%d>%d\n",a,b);
|
|
}else if(a<b){
|
|
my_printf("%d<%d\n",a,b);
|
|
}else{
|
|
my_printf("%d==%d\n",a,b);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void test7(uint32_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void test8(int32_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void test9(uint16_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void test10(int16_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void test11(uint8_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void test12(int8_t a,int b){
|
|
my_printf("shift right %08x, %08x\n",a,a>>b);
|
|
}
|
|
|
|
void cpu_test() {
|
|
|
|
my_printf("test 32 bit\n");
|
|
test1(1,2);
|
|
test1(1,-2);
|
|
test2(1,2);
|
|
test2(1,-2);
|
|
|
|
my_printf("test 16 bit\n");
|
|
test3(1,2);
|
|
test3(1,-2);
|
|
test4(1,2);
|
|
test4(1,-2);
|
|
|
|
my_printf("test 8 bit\n");
|
|
test5(1,2);
|
|
test5(1,-2);
|
|
test6(1,2);
|
|
test6(1,-2);
|
|
|
|
my_printf("shift test\n");
|
|
test7(0x80000000,7);
|
|
test8(0x80000000,7);
|
|
test9(0x8000,7);
|
|
test10(0x8000,7);
|
|
test11(0x80,7);
|
|
test12(0x80,7);
|
|
|
|
}
|
|
|
|
|