Showing posts with label C51 stuff. Show all posts
Showing posts with label C51 stuff. Show all posts

Harvard architecture vs von Neumann architecture

I was asked about the architecture difference between the Harward model and the von Neumann model during an interview. Shame! Shame! Shame! I only rememeber Harward was faster in certain mathematical calculation, such as Fourier transform.

Here is something I extracted from wikipedia.org.

Harward has the physically separated data and instruction storage and pathways, which means it has the capability to read instruction and read/write data at the same time. Obviously, this is not possible in the classical x86 architecure, since our data and instruction are all stored in the ram (from hardisk) and read/write through the shared data/address bus. One thing has to note: the cache. We are talking about the case of von Neumann model without cache here.

dirty tricks in 80C51

The following content is quoted from:
http://www.esacademy.com/automation/docs/c51primer/c15.htm#15

General Things to be Aware of

The ANSI standard says that the product of two 8 bit numbers is also an 8 bit number. This means that any unsigned chars which might have to be multiplied must actually be declared as unsigned int's if there is any possibility that they may produce even an intermediate result over 255.

However it is very wasteful to use integer quantities in an 8051 if a char can do the job! The solution is to temporarily convert (cast) a char to an int. Here the numerator potentially could be 16 bits but the result always 8 bits. The "(unsigned int)" casts ensure that a 16 bit multiply is used by C51.

{
unsigned char z ;
unsigned char x ;
unsigned char y ;
z = ((unsigned int) y * (unsigned int) x) >> 8 ;
}


Here the two eight bit numbers x and y are multiplied and then divided by 256. The intermediate 16 bit (unsigned int) result is permissible because y and x have been loaded by the multiplier library routine as int's.