程序意义,它是如何工作的 [英] PROGRAM MEANING, how it works

查看:92
本文介绍了程序意义,它是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// Switch and key functions program

#include "system.h"
#include <stdio.h>
#include "altera_avalon_pio_regs.h"
#include "sys/alt_stdio.h"
#include <unistd.h>

unsigned int toBCD(unsigned n)

{
	unsigned rval,i,d;
	rval=0;
	i=0;

	while(n!=0)
	{
		d=n%10;
		d=d << (4*i);
		rval|=d;
		i++;
		n/=10;

	}
	return rval;
	}

int main()
{
 unsigned switches,keys;
 printf("Hello from Nios II!\n");


    while(1){

	   switches= IORD_ALTERA_AVALON_PIO_DATA(SWITCH_BASE);
	   keys=IORD_ALTERA_AVALON_PIO_DATA(KEY_BASE);

	   IOWR(SEG7_BASE,0,switches);
	   IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,switches);
	   IOWR_ALTERA_AVALON_PIO_DATA(LEDG_BASE,(~keys)&0xf);
    }

	   return 0;


}

推荐答案

你有什么想法一行一行地解释代码是?

每一行都需要一段解释!例如:

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();



创建一个名为next的新变量,它可以包含一个整数值。从先前声明的Random实例r,调用Next方法获取一个新的随机数,并将其分配给next变量。



可以你想象我们需要多长时间才能解释一个像你的例子一样的非常短的代码片段,一行一行?



不会发生这种情况。如果您有特定问题,请询问有关它的问题。但首先考虑一下 - 您是否希望坐下45分钟并无理由地输入逐行描述?


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?


它看起来像是为Alterra FPGA编写的C代码。一般来说,针对FPGA编写C是一个坏主意,所以在回答这是如何工作的?我会说非常无效。

否则它只是一个无限循环,执行由C Preprcessor宏确定的预定义代码

It looks like C code written for an Alterra FPGA. In general writing C against an FPGA is a bad idea so in answer to how does this work? I would say very ineffeciently.
Otherwise it''s simply an endless loop that performs some predefined code determined by the C Preprcessor macros
<br />
IOWR<br />
IORD_ALTERA_AVALON_PIO_DATA<br />
IOWR_ALTERA_AVALON_PIO_DATA<br />



你还没有提供了定义。我想这些输入输出是读和写,但我不能说。


for which you have not provided the definitions. I guess these do Input Output Read and Write but how I cannot say.


这篇关于程序意义,它是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆