Search This Blog

Tuesday, June 12, 2012

Program to determine whether the number is a bit wise palindrone or not

MY_DATA SEGMENT
    X DW MY_NUMBER
    MSG1 DB 'NUMBER IS A PALINDRONE'
    MSG2 DB 'NUMBER IS NOT A PALINDRONE'
MY_DATA ENDS
CODE SEGMENT

    ASSUME CS:CODE, DS:MY_DATA

    START:
    MOV AX, MY_DATA
    MOV DS, AX
    ; THE AOVE 2 STTEMNETS INITILISE THE DATA SEGMENT

    MOV CL, 10H ; AS DOUBLE WORD IS 16 BITS
   
    UP:
    ROR AX, 1
    ; ROTATE RIGHT ONE TIME
    RCL DX, 1
    ; ROTATE LEFT WITH CARRY ONE TIME
   
    LOOP UP
    ; TILL COUNTER GOES TO 0
   
    CMP AX, DX
    JNZ NOPALIN
    ; NO ZERO MEANS NOT A PALINDRONE SO DECLARE THAT
   
    LEA DX, MSG1
    ; DECLARE AS PALINDRONE IF ZERO
   
    ; IF USING TASM WRITE THESE TWO LINES
    MOV AH, 09H
    INT 21H
   
    JMP EXIT
   
    NOPALIN:
    LEA DX, MSG2
    ; DECLARE NOT A PALINDRONE
    ; IF USING TASM WRITE BELOW TWO LINES
    MOV AH, 09H
    INT 21H

    EXIT:
    ; IF USING TASM WRITE THESE TWO LINES TO END
    MOV AH, 4CH
    INT 21H

CODE ENDS
END

Program to find GCD of two numbers


MY_DATA SEGMENT
                NUM1 DW 000AH
                NUM2 DW 0004H
                GCD DW ?
MY_DATA ENDS

CODE SEGMENT
                ASSUME CS:CODE, DS:DATA
                START:
                MOV AX, DATA
                MOV DS, AX
                ; INITIALISATION OF DATA SEGMENT
               
                MOV AX, NUM1
                ; MOVE FIRST NUMBER TO AX
                MOV BX, NUM2
                ; MOVE SECOND NUMBER TO BX
               
                UP:
                CMP AX, BX
                JE EXIT
                ; IF EQUAL THEN NO POINT IN FINDING GCD
                JB EXCG
                ; IF FIRST NUMBER IS SMALLER PUT IT BX
                ; MEANING SMALL NUMBER MUST STAY IN BX
               
                UP1:
                MOV DX, 0000H
                ; INITIALISE DX
                DIV BX
                ; DIVIDE (BIGGER NUMBER)/(SMALLER NUMBER)
                CMP DX, 0
                ; SEE IF REMAINDER IS ZERO OR NOT
                JE EXIT
                ; IF ZERO VOILA YOU HAVE FOUND THE GCD IN THE SMALLER NUMBER
                MOV AX, DX
                ; IF NON ZERO MOVE REMAINDER TO AX
                JMP UP

                EXCG:
                XCHG AX, BX
                ; EXCHANGE CONTENTS OF AX AND BX
                JMP UP1
               
                EXIT:
                MOV GCD, BX
                ; STORE RESULT IN GCD
               
                ; WRITE THESE TWO LINES IF YOU ARE TESTING IN TASM
                MOV AH, 4CH
                INT 21H
                ; THE ABOVE TWO LINES ARE OBVIOUSLY THE EXIT INTERRUPT
                ; USED IN TASM

CODE ENDS
END START
Understanding the program
What I did was basically divide the larger number with the smaller number.
If we get remainder 0 then the smaller number is our GCD for the two given number.
If we don’t get a zero remainder we transfer the remainder to AX and then again repeat the process till we get that zero remainder. In short I perform the same procedure we use mathematically to find the Greatest Common Denominator.

Friday, June 8, 2012

Non Volatile and Data Memories

The ATmega16 is equipped with three main memory sections: flash electrically erasable programmable read-only memory (EEPROM), static random access memory (SRAM), and byteaddressable EEPROM for data storage.

InSystem Programmable Flash EEPROM
Bulk programmable flash EEPROM’s used to store programs. It can be erased and programmed as a single unit. Also, should a program require a large table of constants, it may be included as a global variable within a program and programmed into flash EEPROM with the rest of the program. Flash EEPROM is nonvolatile, meaning memory contents are retained when microcontroller power is lost. The
ATmega16 is equipped with 16K bytes of onboard reprogrammable flash memory. This memory component is organized into 8K locations, with 16 bits at each location. The flash EEPROM is in-system programmable. In-system programmability means the microcontroller can be programmed while resident within a circuit. It does not have to be removed from the circuit for programming. Instead, a host personal computer (PC) connected via a cable to a microcontroller downloads the program to the microcontroller.

Byte Addressable EEPROM
Byte-addressable memory is used to permanently store and recall variables during program execution. It too is nonvolatile. It is especially useful for logging system malfunctions and fault data during program execution. It is also useful for storing data that must be retained during a power failure but might need to be changed periodically. Examples where this type of memory is used are found in applications to store system parameters, electronic lock combinations, and automatic garage door electronic unlock sequences. The ATmega16 is equipped with 512 bytes of EEPROM.

Static Random Access Memory
SRAM is volatile. That is, if the microcontroller loses power, the contents of SRAM memory are lost. It can be written to and read from during program execution. The ATmega16 is equipped with 1000 bytes (actually 1120) of SRAM. A small portion (96 locations) of the SRAM is set aside for the general-purpose registers used by the CPU and also for the I/O and peripheral subsystems aboard the microcontroller.

Programmable Lock Bits
To provide for memory security from tampering, the ATmega16 is equipped with six memory lock bits. These lock bits are programmed using the Atmel STK500 programming board. The lock bits may be configured for the following options:
• No memory lock features enabled.
• No further programming of memory is allowed using parallel or serial programming techniques.
• No further programming or verification of memory is allowed using parallel or serial programming techniques.

Why use ATmega??

Well students mostly use either a ATmega8, ATmega16/32 cause they are very very cheap. Their development board can be home processed/fabricated very easily. As can be seen from the figure, the ATmega16 has external connections for power supplies (VCC, GND, AVCC, and AREF), an external time base (XTAL1 and XTAL2) input pins to drive its clocks, processor reset (active low RESET), and four 8-bit ports (PA0-PA7, PC0-PC7, PB0-PB7, and PD0-PD7), which are used to interact with the external world. As we shall soon see, these ports may be used as general purpose digital input/output (I/O) ports or they may be used for the alternate functions. The ports are interconnected with the ATmega16’s CPU and internal subsystems via an internal bus.The ATmega16 also contains a timer subsystem, an analog-to-digital converter (ADC), an interrupt subsystem, memory components, and a communication subsystem.