note_13

 

#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

#include<string.h>

//***作业讲解

//(3,4)逗号表达式

int main()

{

int arr[] = {1,2,(3,4),5};

printf("%d", sizeof(arr));//16

return 0;

}

//***数组操作

void init(int arr[], int sz)

{

int i = 0;

for (i = 0; i < sz; i++)

{

arr[i] = 0;

}

}

void print(int arr[], int sz)

{

int i = 0;

for (i = 0; i < sz; i++)

{

printf("%d ", arr[i]);

}

printf("\n");

}

void reverse(int arr[], int sz)

{

int left = 0;

int right = sz - 1;

int tmp = 0;

while (left < right)

{

tmp = arr[left];

arr[left] = arr[right];

arr[right] = tmp;

left++;

right--;

}

}

int main()

{

int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };

int sz = sizeof(arr) / sizeof(arr[0]);

//init(arr, sz);

print(arr, sz);

reverse(arr, sz);

return 0;

}

//***数组交换

int mian()

{

int arr1[] = { 1,3,4,7,9 };

int arr2[] = { 2,4,6,8,10 };

int sz = sizeof(arr1) / sizeof(arr1[0]);

int tmp = 0;

int i = 0;

for (i = 0; i < sz; i++)

{

tmp = arr1[i];

arr1[i] = arr2[i];

arr2[i] = tmp;

}

return 0;

}

***操作符详解

(板书)

int main()

{

***算数操作符

10.0 % 3错误必须整数

//int ret = 10 % 3;//取模(取余)

//int ret1 = 10 / 3;//商

//double ret2 = 10 / 3.0;

//printf("%d\n", ret);//1

//printf("%d\n", ret1);//3

//printf("%lf\n", ret2);//3.333333

***移位操作符

//int a = 5;

//int a1 = -5;

//int b = a << 2;//a的二进制位移动两位

//int b1 = a1 << 2;//补码移动两位

//printf("%d\n", b);//20

//printf("%d\n", b1);//-20

return 0;

}

//右移

//算术右移(左边补原来的符号位)or逻辑右移(左边补0)

int main()

{

int a = 5;

int a1 = -5;

int b = a >> 1;

int b1= a1 >> 1;

printf("%d\n", b);//2

printf("%d\n", b1);//-3(算术右移)

return 0;

}

//***位操作符

//&按位与

//|按位或

//^按位异或

int main()

{

int a = 3;//0011

int b = -5;//1...1011

int c = a & b;//补码计算

printf("%d\n", c);//3

return 0;

}

int main()

{

int a = 3;//0011

int b = -5;//1...1011

int c = a | b;//补码计算

printf("%d\n", c);//1...1011, -5

return 0;

}

int main()

{

int a = 3;//0011

int b = -5;//1...1011

int c = a ^ b;//补码计算

printf("%d\n", c);//1...1000->1...0111->1000...1000,-8

return 0;

}

***交换变量

方法一

int main()

{

int a = 3;

int b = 5;

int c = 0;//临时变量

printf("%d %d\n", a, b);

c = a;

a = b;

b = c;

printf("%d %d\n", a, b);

return 0;

}

方法二

int main()

{

int a = 3;

int b = 5;

printf("%d %d\n", a, b);

a = a + b;

b = a - b;

a = a - b;

printf("%d %d\n", a, b);

return 0;

}

方法三

异或

int main()

{

int a = 3;

int b = 5;

printf("%d %d\n", a, b);

a = a ^ b;

b = a ^ b; //a^b^b

a = a ^ b;//a^a^b

printf("%d %d\n", a, b);

return 0;

}

***左值,是可以放在等号左边的,一般是一块空间

右值,是可以放在等号右边的,一般是一个值,或一个空间的内容

//*** ~ 对一个二进制数按位取反

int main()

{

int a = 0;

printf("%d\n", ~a);

return 0;

}

int main()

{

int a = 10;

a |= (1 << 2);

printf("%d\n", a);

//1010

//或0100

//得1110

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是形成音符并发声模块的 test 代码示例: ```verilog module test_note_formation; // Inputs reg clk0; reg clr; reg [13:0] note_music; reg [13:0] div; // Outputs wire clk_out; // Instantiate the Unit Under Test (UUT) note_formation uut ( .note_music(note_music), .div(div), .clk0(clk0), .clr(clr), .clk_out(clk_out) ); initial begin // Initialize inputs clr = 1; clk0 = 0; note_music = 14'b0; div = 14'b10000000000000; // Wait 10 ns for global reset to finish #10; // Test case 1 - 初始状态下,输出为低电平 if (clk_out !== 1'b0) $error("Test case 1 failed"); // Test case 2 - 当输入的音符为 0 时,输出应该一直为低电平 note_music = 14'b0; div = 14'b10000000000000; #10; if (clk_out !== 1'b0) $error("Test case 2 failed"); // Test case 3 - 当输入的音符不为 0 时,输出应该形成特定频率的方波 note_music = 14'b11000000000000; div = 14'b10000000000000; #10000; // 等待一段时间,观察输出波形 // TODO: 检查输出波形是否符合预期 $display("All test cases passed"); $finish; end endmodule ``` 在这个 test 代码示例中,我们首先实例化了形成音符并发声模块,并将其连接到测试的输入输出端口上。然后,我们定义了多个测试用例并在 initial 块中执行它们。每个测试用例都包含了对输入信号的不同组合,并检查模块输出的 clk_out 是否与预期值相等。如果不相等,则会输出错误信息。最后,我们通过 $display 输出所有测试用例都通过的信息,并通过 $finish 结束仿真。注意,在测试用例 3 中,我们使用了 #10000 来等待一段时间,以便观察输出波形是否符合预期。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值