World's most popular travel blog for travel bloggers.

Pointers in C language is a variable that stores/points the address of another variable. A Pointer in C is used to allocate memory dynamically i.e. at run time. The pointer variable might be belonging to any of the data type such as int, float, char, double, short etc.

Adder


An adder is a kind of calculator that is used to add two binary numbers. When I say, calculator, I don’t mean one with buttons, this one is a circuit that can be integrated with many other circuits for a wide range of applications. There are two kinds of adders;

Half adder


Full adder


Half Adder

With the help of half adder, we can design circuits that are capable of performing simple addition with the help of logic gates.

Let us first take a look at the addition of single bits.

0+0 = 0

0+1 = 1

1+0 = 1

1+1 = 10

These are the least possible single-bit combinations. But the result for 1+1 is 10. Though this problem can be solved with the help of an EXOR Gate, if you do care about the output, the sum result must be re-written as a 2-bit output.

Thus the above equations can be written as

0+0 = 00

0+1 = 01

1+0 = 01

1+1 = 10

Here the output ‘1’of ‘10’ becomes the carry-out. The result is shown in a truth-table below. ‘SUM’ is the normal output and ‘CARRY’ is the carry-out.

INPUTS                 OUTPUTS

A             B             SUM      CARRY

0              0              0              0

0              1              1              0

1              0              1              0

1              1              0              1

From the equation, it is clear that this 1-bit adder can be easily implemented with the help of EXOR Gate for the output ‘SUM’ and an AND Gate for the carry. Take a look at the implementation below.

Half Adder Circuit


For complex addition, there may be cases when you have to add two 8-bit bytes together. This can be done only with the help of full-adder logic.

Full Adder

This type of adder is a little more difficult to implement than a half-adder. The main difference between a half-adder and a full-adder is that the full-adder has three inputs and two outputs. The first two inputs are A and B and the third input is an input carry designated as CIN. When a full adder logic is designed we will be able to string eight of them together to create a byte-wide adder and cascade the carry bit from one adder to the next.

The output carry is designated as COUT and the normal output is designated as S. Take a look at the truth-table.

INPUTS                 OUTPUTS

A             B             CIN         COUT    S

0              0              0              0              0

0              0              1              0              1

0              1              0              0              1

0              1              1              1              0

1              0              0              0              1

1              0              1              1              0

1              1              0              1              0

1              1              1              1              1

From the above truth-table, the full adder logic can be implemented. We can see that the output S is an EXOR between the input A and the half-adder SUM output with B and CIN inputs. We must also note that the COUT will only be true if any of the two inputs out of the three are HIGH.

Thus, we can implement a full adder circuit with the help of two half adder circuits. The first will half adder will be used to add A and B to produce a partial Sum. The second half adder logic can be used to add CIN to the Sum produced by the first half adder to get the final S output. If any of the half adder logic produces a carry, there will be an output carry. Thus, COUT will be an OR function of the half-adder Carry outputs. Take a look at the implementation of the full adder circuit shown below.

Full Adder Circuit


Though the implementation of larger logic diagrams is possible with the above full adder logic a simpler symbol is mostly used to represent the operation. Given below is a simpler schematic representation of a one-bit full adder.

Single-bit Full Adder


With this type of symbol, we can add two bits together taking a carry from the next lower order of magnitude, and sending a carry to the next higher order of magnitude. In a computer, for a multi-bit operation, each bit must be represented by a full adder and must be added simultaneously. Thus, to add two 8-bit numbers, you will need 8 full adders which can be formed by cascading two of the 4-bit blocks. The addition of two 4-bit numbers is shown below.

Multi-Bit Addition using Full Adder


Parity bits are used as a form of error checking during the transmission of information. When old modem is transmitted data over a network or communications device, the data was encoded into a series of ones and zeros called bits (modern modems send information in packets and check for errors in different ways, so a parity bit is unnecessary). A single bit can describe only two possible states, 0 (off) or 1 (on). Several bits are thus needed to describe a letter or number. A total of seven bits are used to describe the set of ASCII characters, which include the letters and numbers that compose this document.


The letter "A", for example, has ASCII code 65, which in binary is 1000001. Note that each binary digit corresponds to a power of two, and 65, which is two to the sixth power plus two to the zeroth power, has ones in only the sixth and zeroth columns of its binary representation. The letter C, with code value 67, has the binary sequence 1000011.


Because noise or electrical interference may sometimes interfere with the transmission of data, it is useful to have some way to easily detect errors in information as it is exchanged. One way to do this is to add an eighth bit to characters that are transmitted, called a parity bit. The parity bit is chosen such that all correctly transmitted characters will have either an even or odd number of ones. Thus, if a zero were placed at the start of the code for the letter A, producing 01000001, a one would be placed before the code for C, producing 11000011.


The prefixes shown here produce binary codes with an even number of ones (and zeros), and the added bit is thus called an even parity bit. The leading ones and zeros could also be chosen to always produce odd numbers of ones and zeros, and this scheme is called odd parity. Familiar settings in communications programs are E7, which uses one even parity bit and seven data bits, and N8, which indicates no parity bit and the use of all eight bits for transmitting data.


Use of the wrong parity setting in a communications program may produce screens full of garbage characters. If this happens, check to see what parity settings the computer to which you are connecting expects. If you do not have this information, try connecting with a different parity setting and see if this produces legible text.


Opcode is an instruction that tells processor what to do with the variable or data written besides it.

Oprand is a variable that stores data(and data can be a memory address or any data that we want to process).

e.g. MVI A,B

here instruction MVI is an opcode. A & B are oprands.

Same for other instructions.

An algorithm is a finite set of steps defining the solution of a particular problem. An algorithm is expressed in pseudo code – something resembling C language or Pascal, but with some statements in English rather than within the programming language
  1. A sequential solution of any program that written in human language, called algorithm.
  2. Algorithm is first step of the solution process, after the analysis of problem, programmers write the algorithm of that problem.
Pseudo code 
  • Input Num
  • Initialize Len to zero and Y to Num
  • While Y is not zero
  •                Save Remainder by Y Mod 16 in array HEXD at index Len
  •                Initialize Y to Y divided 16
  •                Increment Len
  • for(Initialize I to Len-1 ; Condition I Greater than  -1 ;  Decrement I )
  •                If HEXD[I] Less than 10
  •                           HEXC[I]=HEXD[I]+48
  •                Else
  •                           HEXC[I]=HEXD[I]+55
  • Initialize HEXC[I] to NULL
  • Print HEXC
Detailed Algorithm:
Step 1:  Input NUM
Step 2:  LEN = 0 & Y=NUM
Step 3:  While (Y > 0)
                       HEXD[LEN]=Y%16
                       Y=Y/16
                       LEN++
Step 4: for(I=LEN-1;I>-1;I–)
                       IF(HEXD[I]<10)
                                HEXC[I]=HEXD[I]+48;
                       ELSE
                                HEXC[I]=HEXD[I]+55;
Step 5:  HEXC[I]=NULL
Step 5:  Print HEXC

Flowchart:-



Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Examples of objects range from human beings (described by name, address, and so forth) to buildings and floors (whose properties can be described and managed) down to the little widgets on a computer desktop (such as buttons and scroll bars).
The first step in OOP is to identify all the objects the programmer wants to manipulate and how they relate to each other, an exercise often known as data modeling. Once an object has been identified,  it is generalized as a class of objects (think of Plato's concept of the "ideal" chair that stands for all chairs) which defines the kind of data it contains and any logic sequences that can manipulate it.
Object-Oriented Programming has the following advantages over conventional approaches:
  • OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
  • OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
  • OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.


SYS_EXIT  equ 1
SYS_READ  equ 3
SYS_WRITE equ 4
STDIN     equ 0
STDOUT    equ 1

segment .data

   msg1 db "Enter a digit ", 0xA,0xD
   len1 equ $- msg1

   msg2 db "Please enter a second digit", 0xA,0xD
   len2 equ $- msg2

   msg3 db "The sum is: "
   len3 equ $- msg3

segment .bss

   num1 resb 2
   num2 resb 2
   res resb 1   

section  .text
   global _start    ;must be declared for using gcc
        
_start:             ;tell linker entry point
   mov eax, SYS_WRITE        
   mov ebx, STDOUT        
   mov ecx, msg1        
   mov edx, len1
   int 0x80               

   mov eax, SYS_READ
   mov ebx, STDIN 
   mov ecx, num1
   mov edx, 2
   int 0x80           

   mov eax, SYS_WRITE       
   mov ebx, STDOUT        
   mov ecx, msg2         
   mov edx, len2        
   int 0x80

   mov eax, SYS_READ 
   mov ebx, STDIN 
   mov ecx, num2
   mov edx, 2
   int 0x80       

   mov eax, SYS_WRITE        
   mov ebx, STDOUT        
   mov ecx, msg3         
   mov edx, len3        
   int 0x80

   ; moving the first number to eax register and second number to ebx
   ; and subtracting ascii '0' to convert it into a decimal number
        
   mov eax, [num1]
   sub eax, '0'
        
   mov ebx, [num2]
   sub ebx, '0'

   ; add eax and ebx
   add eax, ebx
   ; add '0' to to convert the sum from decimal to ASCII
   add eax, '0'

   ; storing the sum in memory location res
   mov [res], eax

   ; print the sum
   mov eax, SYS_WRITE       
   mov ebx, STDOUT
   mov ecx, res        
   mov edx, 1       
   int 0x80

exit:   
  
   mov eax, SYS_EXIT  
   xor ebx, ebx
   int 0x80
When the above code is compiled and executed, it produces the following result −
Enter a digit:
3
Please enter a second digit:
4
The sum is:
7
The program with hardcoded variables −
section  .text
   global _start    ;must be declared for using gcc
        
_start:             ;tell linker entry point
   mov   eax,'3'
   sub     eax, '0'
        
   mov   ebx, '4'
   sub     ebx, '0'
   add   eax, ebx
   add   eax, '0'
        
   mov   [sum], eax
   mov   ecx,msg 
   mov   edx, len
   mov   ebx,1    ;file descriptor (stdout)
   mov   eax,4    ;system call number (sys_write)
   int   0x80     ;call kernel
        
   mov   ecx,sum
   mov   edx, 1
   mov   ebx,1    ;file descriptor (stdout)
   mov   eax,4    ;system call number (sys_write)
   int   0x80     ;call kernel
        
   mov   eax,1    ;system call number (sys_exit)
   int   0x80     ;call kernel
        
section .data
   msg db "The sum is:", 0xA,0xD
   len equ $ - msg  
   segment .bss
   sum resb 1