Thursday, 30 September 2010

Compiler Optimizations

The task of every compiler is to translate high-level language source code to machine code that will run on target processor. This may be achieved through assembly language file or by linking object files, the ultimate goal of every compiler is to generate code for the target processor. In principle this is a simple task. Every high level statement can be translated in a series of target instructions. However, without some optimizations this code would be very inefficient. Unoptimized code still works, but it is slower and the files are bigger.


The nature of high-level statements is to operate with variables. Loading and storing of variables can happen in any order. But transfers from and to memory are slower comparing to transfers between registers. And if some value is stored to memory location and immediately after it is needed again in a different calculation, then it doesn't make sense to load it again since it was already present in some register. With proper register loading we can save a lot of redundant loads and stores. There are many optimization algorithms to make the code as efficient as possible. In fact, the compiler optimization is a science. There are many books written on this subject.

Most optimization algorithms are based on control and data flow analysis. There are many optimization approaches: to reduce jumps, to remove dead, redundant or common code, to remove redundant loads and stores, to use registers efficiently, to replace slow instructions with faster ones, to replace specific arithmetic calculations with short instructions, etc. Each optimization is based on some code or data properties. Some of the common optimizations include: constant folding, integer arithmetic optimizations, dead code elimination, branch elimination, code-block reordering, loop-invariant code motion, loop inversion, induction variable elimination, Instruction selection, instruction combining, register allocation, common sub-expression elimination, peephole optimizations, etc.

The basic rule of every optimization is that the original functionality of the program should not be changed. All optimization algorithms are based on the assumption that the program under analysis is the only one who changes memory locations. In reality interrupts or hardware ports can break this rule. Therefore proper actions must be taken to prevent optimizations on memory locations which might be modified outside the code we are trying to optimize. An additional programming technique that complicates optimizations is using pointers. But with proper analysis it is possible to apply safe optimizations on most parts of the code.

You can optimize the code for speed or for code size. In each case the program runs faster or occupies less memory. The later is extremely important in embedded programming where the memory of microcontrollers is limited. Compiler optimizations are an important part of every compiler. Unoptimized code is a waste of memory and time on any target system.

A practical example of  compiler optimizations in action is the Pascal compiler for 8051 microcontrollers which uses Turbo Pascal syntax and generates optimized code. If you are interested in practical compiler construction you can examine the Turbo Pascal internals. This is Turbo Pascal compiler written in Turbo Pascal which can be used as an excellent book on compiler design.

Monday, 20 September 2010

Home Web Hosting - Access Your Home Server From the Internet

If you are a webmaster developing or maintaining websites then you probably have a home web server for development or testing purposes. An old computer can easily be transformed into a Linux server. If you install also Apache, MySQL and PHP applications you will be able to host websites at your home. Of course, this is not the same hosting as offered by commercial providers, it is only a place where you can install, develop and test web applications. With some additional settings you can access your home computers from any place that has internet access. This is very convenient for getting files you forgot at home.

Assuming that you already have a local area network (LAN) including the router, which is a bridge between your computers and the internet, you need no additional equipment. In order to enable web access from the internet, you have to configure your router to forward outside web requests to the your server. The default port for web is 80, but you can choose any other port number to increase security.


The first prerequisite for remote access is a domain. This is the name of your home server on the internet. There are many services that offer free domains and free updating of IP addresses. This is especially important if you don't have a static IP address. Most internet providers dynamically assign IP addresses which change once a day or with every connection. Since knowing your external IP address is crucial to access your computers from the internet, you need a way to update the domain DNS records.

Many routers support popular dynamic DNS services like DynDns. If your router has no such function you can still install simple software utility on your computer which will update address every time it will be changed. You should create an account, select preferred domain name and choose your name which you will use as a sub-domain. This account data you should enter into the router settings or external software for IP address update.

Now you have access to your router. Each time you will enter your name followed by the chosen domain, you will reach you router. If you have enabled access to its user interface from the external port, you will be able to configure it as you do it from your home computer. To reach your server you need to configure port redirection. If you would like to use the standard port 80 for web access, then simply create a rule to forward external (public) port 80 to the local port 80 at IP address of your web server. This is everything that is needed to access your web server from anywhere.

For hosting of real websites especially if they are commercial in nature you need a reliable hosting like Hostgator. Simply because the website needs to be available 24 hours a day and downtime in the case of hardware failure should be as short as possible. Commercial hosting companies usually provide professional service for few dollars per month. This includes unlimited number of domains, unlimited disk space and many other goodies.


Having a possibility to access home computers from any location is very useful when you need some files or data from home. Even if you have a dynamic IP address you can access your development websites and show them to your friends or clients.

Saturday, 18 September 2010

What to Look For in a LCD Computer Monitor?

In general, it is difficult to say which computer component is most important. Probably there is no such component. Every part is needed to perform some task otherwise we wouldn't need it. But there is one difference. With some computer components we have direct contact. One of such components is monitor. Computer monitor communicates with us in a very special way. It displays all the information about the status of the computer as well as windows of currently active applications. Therefore, it is essential that this computer component is carefully selected and that it displays stable and clear picture.

Currently LCD is the predominant technology for computer monitors. There is no big difference between computer LCD monitors and LCD TV sets. The only major difference is the additional interface electronics that makes a LCD TV set look like a television and LCD monitor to look as computer monitor.


Usually, when buying computers we look at the price tag. This is normal since price ranges can vary significantly. But the price should not be the only parameter upon which we will make a decision. When buying computer monitors we should consider the following:

Main Purpose of Our Computer
We can use the computer as office tool, gaming machine, designer's drawing board, or a combination of listed and also other purposes. Each purpose needs emphasis on a different parameter. For example, designers working in desktop publishing need large desktops and realistic color reproductions, games need monitors with fast response, etc. The first step in choosing monitor is to define the main purpose of the computer.

Size
The bigger the better. This simple rule is valid for all computer purposes. With larger working area you will easily work with many applications at the same time. Application windows will not be squeezed to small cluttered rectangles, the taskbar will look as a nice informative bar and not like a bar with many small buttons, on the desktop you will be able to put more icons for frequently used programs, etc. Because all LCD monitors are flat there will be no problem with the space on the table. So the only disadvantage with large monitors is maybe higher price.

Resolution
Again, the bigger the better. The display resolution tells us how many pixels or points the monitor can display. More pixels means larger monitor or smaller image dots. A typical resolution for multipurpose computer is 1920x1200 pixels. It allows comfortable work with office programs, web browsing and also good experience with CAD programs.

Interfaces
Almost all computer LCD monitors have DVI input. This is standard for computer graphics cards. If we intend to connect multimedia devices we also need a HDMI input. Many monitors have also integrated USB hubs. This is very handy to connect keyboard, mouse and external disks. Some computer monitors have also a TV tuner which converts them into a real TV set.


Choosing computer monitor is not an easy task even if you know what to look for. For more tips and hints you can visit the http://computerlcdmonitors.org/ website which provides few basic facts about computer LCD monitors.

Perhaps the most important fact you should remember is that you will be staring for hours into this flat panel. Make sure it will look pretty.

Thursday, 16 September 2010

Universal JTAG Cable

Every electronic device around has some microcontroller or other programmable device in it. Even kitchen appliances or toy has some kind of electronics which controls important functions. In some cases this electronic device has predefined functionality which can not be changed. But in most cases this electronics contains a processor that uses flash memory to store code. And if a device is programmable then you can change the program it runs at any time.


Of course, in many cases this programming is not needed since the electronics performs what is supposed to. But in some cases it makes sense to allow end users to update the device with the latest firmware. Therefore, it makes sense to have a universal interface that can be used in factory and at home to program electronic devices with simple additional hardware. This universal interface is JTAG. This is a standard that defines a serial interface to transfer data between a device and computer (or between devices). The JTAG interface needs only four basic signals. This makes it easy to use PC parallel port as JTAG interface. While this works many modern JTAG programmers use USB port to connect to the PC.

Another beauty of the JTAG interface is the possibility to connect many devices in chain. This way you can program all the JTAG enables devices on the board with only one interface. In any case you need a JTAG cable to connect to the device. Each device may have own JTAG pinout but this is not a problem since JTAG cables can be made (almost) universal--at least for few device types. Unfortunately, JTAG cable is not enough. You need also a suitable software that will program the target device.


JTAG is not used only for commercial electronics. It is also a standard interface for all embedded systems including FPGAs, microcontrolelrs and various memories. Each manufacturer has some kind of JTAG cable to program their devices. Unfortunately, these cables use dedicated software and can not be used for other purposes.

One of the very popular uses of the JTAG interface in consumer electronics is to reprogram some router models with new firmware. There are many cheap JTAG cables that can be used to bring a new life for an old router. Changing original firmware is very popular not just for routers but also for other highly popular electronic devices. The Xbox is such example where a simple JTAG hack can change some built-in functions.


There are many JTAG cable supplies around. Before you decide for specific cable you need to check the JTAG pinout and software support. Usually, cheap cables are made only for specific devices and use the parallel port signals to program the device. More advanced JTAG cables use USB interface or at least a buffer to boost signals from parallel port.

Tuesday, 14 September 2010

Digital Television and Computers - Watch TV on Your Computer Monitor

Digital television broadcasting uses satellite and terrestrial platforms to deliver content to the viewers. Digital television is available also via cable and IPTV networks. Most people use TV sets to watch their favorite channels, but there is an alternative way of watching television. If you have a computer you can receive and decode all available channels including premium services if you have a suitable subscription card.

There are at least two methods to upgrade your computer for television reception. You can either use an internal radio/TV card or a small USB stick. Both hardware solutions work well and are not expensive. USB stick is more suitable for use with laptops but you can also use it with a desktop computer as a permanent solution. There are many different models that support different technologies. For terrestrial broadcasting in Europe and many other countries your device should support DVB-T. DVB-S in needed for satellite television and DVB-C for cable reception. Many cards and sticks also support analog FM radio and analog TV. Before you purchase such card or stick you should check which standards are used in your country.

Many internal cards have on-board audio/video decoding support. This hardware decoder does the work which is otherwise very time consuming and processor intensive. USB sticks have no hardware decoder, there is only a demodulator that supplies the DVB transport stream. While the main computer processor will have to decode the sound and picture, this is also an advantage. It is much easier and cheaper to update decoding software than to replace decoding hardware.

Most TV cards and sticks are provided with a remote control. It is very similar to the real TV remote control and enables you to turn your computer monitor into an advanced TV set. Every television decoding software allows you to display the TV picture over entire screen so you can enjoy as in front of standard TV set. The only disadvantage of this way of watching TV is that while you watch full-screen TV you can not use the computer for other work.


Receiving television channels with computer has also one big advantage. You can easily record any channel. You can also record one channel and watch a different one. This is all possible because the software is able to decode many different services simultaneously. Of course, this also depends on the speed of your processor, but in general recording of particular channel or entire stream is not a problem.

Digital television is much closer to computers than it was in the old analog days. Digital broadcasting uses codecs which have roots in computers. Watching television on the computer is nothing new. In fact, digital broadcasting is only a network of many dedicated computers and peripheral devices.

Sunday, 12 September 2010

Computer Forensics - How Volatile Data is Analyzed

Computer forensics plays an important role in fighting terrorism and criminal activity. The fact is that bad guys use computers, internet and other modern communication tools to communicate and to store their plans. We would be naive if we would think that they can barely open Word or Excel. They are aware of all the risks and they protect themselves with modern encryption algorithms and general protective measures. Fighting criminal activities is very different from discovering occasional violations on company computers.


Many traces can be hidden if the software used for criminal activity or otherwise unwanted is not present on the computer disk and runs in the memory of the computer. It is very easy to start some process and then successfully cover all traces that were left behind. In such case analyzing disk data makes no sense because nothing suspicious could be discovered. The only solution to this problem are tools that can protect volatile data like live memory.

The static analysis of computer data (i.e. the analysis of a hard disk removed from the computer) is usually not enough because many advanced techniques can be used to erase all traces from file systems and the only relevant data remains only in memory. Theoretically, it would be possible to freeze computer memory by liquid nitrogen and this would significantly increase chances to recover the data but this approach is not practical. Analysis of live volatile data in a computer is essential for any serious forensic analysis.


There are many open source and professional commercial forensic tools that can make a snapshot of crucial volatile data for later analysis. Such tools can discover open ports, virtual disk drives, VPN connections and other resources not visible to the normal user. In some cases also the whole disk drive or individual partition can be encrypted so it is important to make an image of it before the system is shut down. Once all the data is safely stored it can be analyzed regardless of the state of the computer.

A logical question would be, for example, what can be done to successful hide some processes running in the computer memory? Theoretically, it would be possible to eliminate traces from the memory when the process is not active or when it waits for some input. But even for such approaches there are some solutions. It is possible to create memory snapshots at periodic intervals and sooner or later the secret process will show itself.

For many computer users the most requested computer forensic service is recovering lost files. Check the http://digitaldatarecovery.org/ website for some practical tips on digital data recovery and practical advices to recover important files from broken hard disks or flash memories.


Computer forensics is becoming increasingly important part of the efforts to detect and prevent terrorist activities. But the game will never end. More advanced hiding techniques will lead to more advanced discovery techniques which will lead to even more advanced hiding techniques, etc.

Friday, 10 September 2010

Popular Microcontrollers

Embedded systems are not just complex projects in electronic laboratories--they are present in everyday devices. Every mobile device, electric toy or kitchen appliance has some electronic board which usually includes a programmable device--microcontroller. This is a special microprocessor with peripheral devices and I/O ports. Depending on the volume of the device the manufacturer can decide whether to develop an ASIC--a dedicated integrated circuit which performs all functions for this device or to make a standard board with discrete components. In both cases some microcontroller is used, either as a soft core in ASIC or a standard integrated circuit.

Popular microcontrollers are popular mainly because of availability of affordable development tools and low prices of devices. When hobby engineers start using one family they get used to it and it is very likely that they will use it later in a professional project. While PIC and AVR microcontrollers are heavily used in hobby projects, ARM has prevailed in the professional embedded world. However, 8051 microcontrollers are still used in many hobby and professional projects.

There is a plethora of choices from open-source projects to various IP cores with significant royalties for each device. Despite this choice there are few microcontroller families that are popular because of their flexibility, powerful development tools or because of historical reasons.

ARM


This is currently the hottest RISC core used in almost all mobile phones, portable devices and many other applications. It has powerful instruction set, low consumption, offers easy integration and there are many good development tools for easy development and debugging. The ARM core is also used in many popular microcontroller families from Atmel, Luminary Micro (now Texas Instruments), NXP and many other manufacturers. These microcontrollers are very popular among embedded engineers and are used in various applications from automotive industry to hobby projects.

AVR


This is one of the most popular microcontroller families from Atmel. It is also very popular among hobby engineers and it is used in many projects from simple LED controllers to complex communication devices. The RISC architecture offers fast execution and low power consumption. Development tools are available for free which is a great bonus for electronics enthusiasts. AVR is a direct competitor to Microchip's PIC. Some favor AVR, others like AVR. There is no clear winner. Both families work well. It is up to the developer/programmer what he like or prefers.

PIC


This is a leading microcontroller family from Microchip. PICs are available in very small packages with only few pins and also as powerful 32-bit microcontrollers with many peripheral modules and I/O pins. They are very popular among hobby engineers--in hobby projects you will find either AVR or PIC.

8051


This is a very old 8-bit microcontroller architecture that has managed to survive for more than 30 years. Many excellent compilers, a lot of code examples and simple development has contributed to the popularity of this family. This core is still used in many modern microcontrollers from Silabs, NXP, Atmel and many other microcontroller manufacturers. It is very likely that the 8051 is the most widely used core in embedded applications. Of course, many new designs will probably use ARM or some other advanced architecture, but because of popularity of the 8051 family in the past and availability of development tools (C, Assembler and Pascal),  it is still used in many applications.