Wednesday, December 8, 2010

Embeded System II - Assembly Language

 An assembly language is a low-level programming language for computers, microprocessors, micro controllers, and other integrated circuits. It implements a symbolic representation of the binary machine codes and other constants needed to program a given CPU architecture. This representation is usually defined by the hardware manufacturer, and is based on mnemonics that symbolize processing steps (instructions), processor registers, memory locations, and other language features. An assembly language is thus specific to a certain physical (or virtual) computer architecture. This is in contrast to most high-level programming languages, which, ideally, are portable.

A utility program called an assembler is used to translate assembly language statements into the target computer's machine code. The assembler performs a more or less isomorphic translation (a one-to-one mapping) from mnemonic statements into machine instructions and data. This is in contrast with high-level languages, in which a single statement generally results in many machine instructions.

title   Hello World Program                             (hello.asm)
; This program displays "Hello, World!"

dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main  proc
      mov    ax,@data
      mov    ds,ax

      mov    ah,9
      mov    dx,offset hello_message
      int    21h

      mov    ax,4C00h
      int    21h
main  endp
end   main
 
 Assembly Language Tutorial #1 Introduction 
 

Historical perspective

Assembly languages were first developed in the 1950s, when they were referred to as second generation programming languages. For example, SOAP (Symbolic Optimal Assembly Program) was a 1957 assembly language for the IBM 650 computer. Assembly languages eliminated much of the error-prone and time-consuming first-generation programming needed with the earliest computers, freeing programmers from tedium such as remembering numeric codes and calculating addresses. They were once widely used for all sorts of programming. However, by the 1980s (1990s on microcomputers), their use had largely been supplanted by high-level languages[citation needed], in the search for improved programming productivity. Today, although assembly language is almost always handled and generated by compilers, it is still used for direct hardware manipulation, access to specialized processor instructions, or to address critical performance issues. Typical uses are device drivers, low-level embedded systems, and real-time systems.

Historically, a large number of programs have been written entirely in assembly language. Operating systems were almost exclusively written in assembly language until the widespread acceptance of C in the 1970s and early 1980s. Many commercial applications were written in assembly language as well, including a large amount of the IBM mainframe software written by large corporations. COBOL and FORTRAN eventually displaced much of this work, although a number of large organizations retained assembly-language application infrastructures well into the 90s.

Most early microcomputers relied on hand-coded assembly language, including most operating systems and large applications. This was because these systems had severe resource constraints, imposed idiosyncratic memory and display architectures, and provided limited, buggy system services. Perhaps more important was the lack of first-class high-level language compilers suitable for microcomputer use. A psychological factor may have also played a role: the first generation of microcomputer programmers retained a hobbyist, "wires and pliers" attitude.

In a more commercial context, the biggest reasons for using assembly language were minimal bloat (size), minimal overhead, greater speed, and reliability.

Typical examples of large assembly language programs from this time are IBM PC DOS operating systems and early applications such as the spreadsheet program Lotus 1-2-3, and almost all popular games for the Atari 800 family of home computers. Even into the 1990s, most console video games were written in assembly, including most games for the Mega Drive/Genesis and the Super Nintendo Entertainment System[citation needed]. According to some industry insiders, the assembly language was the best computer language to use to get the best performance out of the Sega Saturn, a console that was notoriously challenging to develop and program games for .The popular arcade game NBA Jam (1993) is another example. On the Commodore 64, Amiga, Atari ST, as well as ZX Spectrum home computers, assembler has long been the primary development language. This was in large part because BASIC dialects on these systems offered insufficient execution speed, as well as insufficient facilities to take full advantage of the available hardware on these systems. Some systems, most notably Amiga, even have IDEs with highly advanced debugging and macro facilities, such as the freeware ASM-One assembler, comparable to that of Microsoft Visual Studio facilities (ASM-One predates Microsoft Visual Studio).

The Assembler for the VIC-20 was written by Don French and published by French Silk. At 1639 bytes in length, its author believes it is the smallest symbolic assembler ever written. The assembler supported the usual symbolic addressing and the definition of character strings or hex strings. It also allowed address expressions which could be combined with addition, subtraction, multiplication, division, logical AND, logical OR, and exponentiation operators.

List of Interrupts

13           INT 00 through INT 10/BE
14           INT 10/BF through INT 15/0F
15           INT 15/10 through INT 15/E7
16           INT 15/E8 through INT 1A/B0
17           INT 1A/B1 through INT 1F
18           INT 20 through INT 21/43
19           INT 21/44 through INT 21/5E
20           INT 21/5F through INT 21/E2
21           INT 21/E3 through INT 21/F1
22           INT 21/F2 through INT 25
23           INT 26 through INT 2F/15
24           NT 2F/16 through INT 2F/79
25           INT 2F/7A through INT 2F/D9
26           INT 2F/DA through INT 50
27           INT 51 through INT 61
28           INT 62 through INT 6A
29           INT 6B through INT 91
30           INT 92 through INT FF

Example Assembly Code: Hello Word
title   Hello World Program                             (hello.asm)
; This program displays "Hello, World!"

dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main  proc
      mov    ax,@data
      mov    ds,ax
     mov    ah,9
      mov    dx,offset hello_message
      int    21h
      mov    ax,4C00h
      int    21h
     main  endp
     end   main
 

   
   
   
   
   
   
   
   
  

Example Assembly Code: A complete program to display the letter ‘a‘on the screen

; prog1.asm: displays the character ‘a’ on the screen
; Author: Joe Carthy
; Date: March 1994
.model small
.stack 100h
.code
start:
mov dl, ‘a’ ; store ascii code of ‘a’ in dl
mov ah, 2h ; ms-dos character output function
int 21h ; displays character in dl register
mov ax, 4c00h ; return to ms-dos
int 21h
end start
 
 
 

Sunday, October 17, 2010

Embedded System - PIC: Instruction Set


PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1640[1] originally developed by General Instrument's Microelectronics Division. The name PIC initially referred to "Programmable Interface Controller".  A PIC's instructions vary from about 35 instructions for the low-end PICs to over 80 instructions for the high-end PICs. The instruction set includes instructions to perform a variety of operations on registers directly, the accumulator and a literal constant or the accumulator and a register, as well as for conditional execution, and program branching. Some operations, such as bit setting and testing, can be performed on any numbered register, but bi-operand arithmetic operations always involve W (the accumulator) ; writing the result back to either W or the other operand register. To load a constant, it is necessary to load it into W before it can be moved into another register. On the older cores, all register moves needed to pass through W, but this changed on the "high end" cores.

All instruction take one cycle unless conditional test is true or PC is changed as a result og an instruction.

Tutorial:
http://www.pictutorials.com/INCFSZ-DECFSZ.htm
http://www.pictutorials.com/INCFSZ-DECFSZ.htm 






Embedded System - Hardware


Hardware is a general term for the physical artifact of technology. In embedded devices, all the electronics hardware resides on a board, also referred to as a printed circuit board(PCB). PCB often made of thin sheets of fiberglass. The major hardware components of the most board are Central processing unit(CPU) the master processor, memory where the system's software is stored, input devices input slave processors, output devices output slave processors and Bus interconnection the other components to another and provide pathway. Example of embedded system hardware is this ADIDAS shoe it is embedded with microprocessor that calculates the pressure between the runner's foot and the ground. Modern hardware stores typically sell equipment such as keys, locks, hinges, latches, corners, handles, wire, chains, plumbing supplies, tools, utensils, cutlery and machine parts, especially when they are made of metal.
Random-access memory (RAM) is a form of computer data storage. Today, it takes the form of integrated circuits that allow stored data to be accessed in any order ."Random" refers to the idea that any piece of data can be returned in a constant time, regardless of its physical location and whether or not it is related to the previous piece of data.

storage devices such as magnetic discs and optical discs rely on the physical movement of the recording medium or a reading head. In these devices, the movement takes longer than data transfer, and the retrieval time varies based on the physical location of the next item.

Microprocessor incorporates most or all of the functions of a computer's central processing unit (CPU) on a single integrated circuit (IC, or microchip). Other embedded uses of 4-bit and 8-bit microprocessors, such as terminals, printers, various kinds of automation etc.
Embedded microprocessors are not exactly very popular, but that is how computers started out. These processors are basically soldered onto the motherboard, making it nearly impossible to switch processors. Socket-based microprocessors are the most popular since they are easy to interchange with one another. If you want to replace a Socket 775 microprocessor, you just have to buy another Socket 775 processor, and that's the end of the story.
Reduced instruction set computing is a CPU design strategy based on the insight that simplified (as opposed to complex) instructions can provide higher performance if this simplicity enables much faster execution of each instruction. A computer based on this strategy is a reduced instruction set computer (also RISC). PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1640[1] originally developed by General Instrument's Microelectronics Division. The name PIC initially referred to "Programmable Interface Controller". PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide availability, large user base, extensive collection of application notes, availability of low cost or free development tools, and serial programming (and re-programming with flash memory) capability. A complex instruction set computer (CISC) is a computer where single instructions can execute several low-level operations (such as a load from memory, an arithmetic operation, and a memory store) and/or are capable of multi-step operations or addressing modes within single instructions. The STATUS register is of most importance to programming the PIC, it contains the arithmetic status of the ALU (
Arithmetic Logic Unit), the RESET status and the bank select bit for data memory. As with any register, the STATUS register can be the destination for any instruction. If the STATUS register is the destination for an instruction that affects the Z, DC or C bits, then the write to these three bits is disabled. These bits are set or cleared according to device logic. Furthermore, the TO and PD bits are not writable. Therefore, the result of an instruction with the STATUS register as destination may be different than intended. For example, CLRF STATUS will clear the upper-three bits and set the Z bit. This leaves the STATUS register as 000u u1uu (where u = unchanged). A memory-mapped file is a segment of virtual memory which has been assigned a direct byte-for-byte correlation with some portion of a file or file-like resource. This resource is typically a file that is physically present on-disk, but can also be a device, shared memory object
, or other resource that the operating system can reference through a file descriptor. Once present, this correlation between the file and the memory space permits applications to treat the mapped portion as if it were primary memory. memory map is a structure of data (which usually resides in memory itself) that indicates how memory is laid out. Memory maps can have a different meaning in different parts of the operating system.

___________________________________________________________________
♣ Embedded systems are part of a bigger system.
♣ Embedded systems are small.
♣ Embedded systems programming is programming with resource
   constraints.

Thursday, October 14, 2010

Embedded System

Embedded System is a specialized computer system that embedded into an appliance with one or more micro-controller. A Micro-controller is a small computer on a single integrated circuit(IC) containing a processor core, memory and a programmable input/output peripherals. A memory in a form flash is also often included on chip, as well as a typically small amount of RAM. The micro-controllers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. Examples of embedded system devices are Personal digital assistant(PDA), Cellphones, Camera etc.Personal digital assistant(PDA) also known as Palmtop Computer is a mobile devices that function as a personal information manager. its embedded with 32-bits of microprocessor. Embedded system include both hardware and software to implement and it is expected to function without human intervention and to respond, monitors, controls external environment using sensors.

Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale. Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single micro controller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.

Typically, an embedded system is housed on a single microprocessor board with the programs stored in ROM. Virtually all appliances that have a digital interface -- watches, microwaves, VCRs, cars -- utilize embedded systems. Some embedded systems include an operating system, but many are so specialized that the entire logic can be implemented as a single program.

___________________________________________________________________

♣ In today's world, embedded systems are everywhere -- homes, offices, cars, factories, hospitals, plans and consumer electronics. Their huge numbers and new complexity call for a new design approach, one that emphasizes high-level tools and hardware/software tradeoffs, rather than low-level assembly-language programming and logic design.