74LS181 ALU真值表如下:
代码实现:
/*
计算机组成原理数据生成器
使用与第一次实验
实现了74LS181的逻辑结构
如果发现那个有问题请自行修改
*/
#include
#include
#include
void experimentOne()
{
int dr1,dr2;
printf("Please input DR1(Hex) and DR2(Hex)(0x00~0xff):");
scanf("%x %x",&dr1,&dr2);
printf("DR1=%x,DR2=%x\n",dr1,dr2);
//dr1=0x35,dr2=0x48;
//dr1=0xc1,dr2=0x43;
#define A dr1
#define B dr2
printf("lin\t s3\t s2\t s1\t s0\t CN=1\t CN=0\t M=1\t\n");
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",1,0,0,0,0, (A)&0xff, (A+1)&0xff, (~A)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",2,0,0,0,1, (A|B&0xff), ((A|B)+1)&0xff,((~(A|B))&0xff)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",3,0,0,1,0, (A|((~B)&0xff))&0xff,((A|((~B)&0xff))+1)&0xff,(((~A)&0xff)&B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",4,0,0,1,1, (0-1)&0xff,(0-1+1)&0xff,0&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",5,0,1,0,0, ((A+(A&(~B&0xff))))&0xff,((A+(A&((~B)&0xff)))+1)&0xff,(~(A&B))&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",6,0,1,0,1,((A|B)+(A&~B))&0xff,((A|B)+(A&~B)+1)&0xff,(~B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",7,0,1,1,0,(A-B-1)&0xff,(A-B)&0xff,(A^B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",8,0,1,1,1,((A&(~B))-1)&0xff,(A&~B)&0xff,(A&~B)&0xff);
//
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",9,1,0,0,0,(A+(A&B))&0xff,(A+(A&B)+1)&0xff,(~A|B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",10,1,0,0,1,(A+B)&0xff,(A+B+1)&0xff,~(A^B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",11,1,0,1,0,((A|(~B))+(A&B))&0xff,((A|(~B))+(A&B)+1)&0xff,B&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",12,1,0,1,1,((A&B)-1)&0xff,A&B&0xff,A&B&0xff);
//
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",13,1,1,0,0,(A+A)&0xff,(A+A+1)&0xff,0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",14,1,1,0,1,((A|B)+A)&0xff,((A|B)+A+1)&0xff,(A|~B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n",15,1,1,1,0,((A|(~B))+A)&0xff,((A|(~B))+A+1)&0xff,(A+B)&0xff);
printf("%d\t %d\t %d\t %d\t %d\t %-2x\t %-2x\t %-2x\t\n\n",16,1,1,1,1,(A-1)&0xff,A&0xff,A&0xff);
system("pause");
}
int main()
{
while(true)experimentOne();
return 0;
}