Thursday, 22 June 2017

Network Security Parameters

The security of the network can be gauged by considering the following parameters;

1. Authentication:

It is the verification that the communication parties are the ones that are claimed.

2. Access Control:
Access control includes the access provision to only intended parties to access the data or resources.

3. Integrity:
It includes the assurance that the data which was sent by the actual sender is received without any modification by any third party. In other words, the data is received by the receiver as it was originally sent by the sender.

4. Confidentiality:
It includes the assurance that the secrecy of the data is preserved. The data is not disclosed to the un-authorized users.

5. Non-repudiation:
Protection against the denial of the communication by any one of the parties.


Sunday, 5 March 2017

Before We Get Started

What is Cryptology?
Cryptology is a study of techniques consisting of the techniques required for ensuring the authenticity and confidentiality of the information.
Cryptology has two main branches;
- Cryptography
                         Which literally means hidden writing. It's the study of the design of such techniques.
- Cryptanalysis
                         Which deals with the analysis of these techniques, to recover the information, which is authentic.


What is Network Security?
Network security is making use of cryptographic algorithms in network protocols and network applications in an order to ensure their security.


What is Computer Security?
Computer security is the security of computers against hackers and malicious software/viruses.


The OSI Security Architecture
The OSI(Open Systems Interconnection) security architecture provides a systematic framework for defining security attacks, mechanisms and services.


Security Attacks
Attacks to breach or threaten the security are known as security attacks.
There are two types of security attacks;
1. Active Attacks
     These attacks include modifying the information without authorization.
2. Passive Attacks
     These attacks include unauthorized monitoring of the information.


Security Mechanism
Any mechanism that is designed to detect, prevent, or recover from security attack. Example: authentication protocols, encryption algorithms, etc.


Security services
Security services include data confidentiality, access control, authentication, non-repudiation, data integrity, and availability.

Friday, 6 January 2017

Relations and Functions

1. Relation

Let A and B be two sets. A binary relation from A into B is any subset of the Cartesian product A x B.
Example: 
Let's assume that a person owns three shirts and two pairs of trousers.
So, let A = {yellow shirt, green shirt, red shirt} and
           B = {blue trouser, black trouser}
Then A x B = {(yellow shirt, blue trouser), (green shirt, blue trouser), (red shirt, blue trouser), (yellow shirt, black trouser), (green shirt, black trouser), (red shirt, black trouser)}

  • Relation on a Set
A relation from a set A into itself is called a relation on A.


  • Properties of Relations
Let's assume that R is a relation on set A; in other words, R ⊆ A x A. Let's write a R b to denote (a,b)∈ R.

1. Reflexive

R is reflexive if for every a ∈ A, aRb.

2. Symmetric

R is symmetric if for every a and b in A, if aRb, then bRa.

3. Transitive

R is transitive if for every a, b and c in A, if aRb and bRc, then aRc.

4. Equivalence

R is equivalence relation on A if R is reflexive, symmetric and transitive.


2. Function

A function, denoted by f, from a set A to a set B is a relation from A to B that satisfies;
- for each element a in A, there is an element b in B such that <a,b> is in a relation, and
- if <a,b> and <a,c> are in the relation, then b=c.

The set A in the above definition is called the domain of the function and B is its co-domain.

Thursday, 29 December 2016

SET

Before we get into the details of Theory of Computations. The set is an essential topic which is required to be reviewed. So, let's have a quick review of this topic.

What is a Set?


- Set is a group of elements, having a common characteristic or property.
- Example: A = {1,2,3,4,5}
- Another way to specify a set is to give the properties that characterize elements of the sets.
- Example: A = {x | x is a positive integer less than or equal to 5}


Set Terminology


1. Belongs To (∈)

- x ∈ A means that x is an element of A.
- Using this notation we can specify the set {0,1,2,3,4} call it Z by writing
                   Z = {x | x ∈ N | x <= 5}
   Where N = set of natural numbers.


2. Subset

- Let A and B be two sets. Then A is a subset of B if every element of A is an element of B.
- It is represented by A⊆ B.
- If A is a subset of B and B is a subset of A, then A = B. Also if a is a subset of B but is not equal to B then it is represented as A⊂ B.


3. Universal Set

- The set U of all the elements we might ever consider in the discourse is called the universal set.


4. Complement

- Let A be a set, then the complement of A is the set consisting of all elements of the universal set that are not in A.
                 A' = {x | x∈ U \land \!\, x ∉ A}
- It is denoted by A'.
- Example:
               If U is a set of natural numbers and A = {1,2,3}, then
                 A' = {x | x∈ U \land \!\, x > 3}


Set Operations


Different operations can be performed on sets;


1. Union:

- If A and B are two sets, then the union of A and B is the set that contains all the elements that are in A and B including the ones in both A and B.
- Union is denoted by A∪B.
- Example:
   If A = {1,2} and B = {3, 4, 5} then A∪B = {1, 2, 3, 4, 5}.


2. Difference

- If A and B are two sets, then the difference of A from B is the set that contains all the elements that are in A but not in B.
- The difference is denoted by A-B.
- Example:
  If A= {1, 2, 3} and B = {3, 4, 5} then A-B = {1,2} also B-A = {4,5}.
- It can be seen that A-B ≠ B-A.


3. Intersection

- If A and B are two sets, then the intersection of A and B is the set that contains all the elements that are in both A and B.
- The intersection is denoted by A∩B.
- Example:
  If A= {1, 2, 3} and B = {3, 4, 5} then A∩B = {3}.


Disjoint Sets


- A and B sets are said to be disjoint if they contain no common element, i.e. A∩B = ∅, where ∅ is an empty set.
- Example:
  Let A= {1, 2, 3} and B = {4,5,6,7} then A and B are disjoint sets as  A∩B = ∅.


Some Standard Identities of Sets


Let A, B, C represent arbitrary sets and ∅ be the empty set and U be the Universal set, then


1. Commutative Laws:

- A∪B = B∪A
- A∩B = B∩A


2. Associative Laws:

- A∪(B∪C) = (A∪B)∪C
- A∩(B∩C) = (A∩B)∩C


3. Distributive Laws:

- A∩(B∪C) = (A∩B)∪(A∩C)
- A∪(B∩C) = (A∪B)∩(A∪C)


4. Idempotent Laws:

- A∪A = A
- A∩A = A


5. Absorption Laws:

- A∪(A∩B) = A
- A∩(A∪B) =  A

6. De Morgan Laws:

- (A∪B)' = A' ∩ B'
- (A ∩ B)' = A' U B'


7. Laws involving Complements:

- (A')' = A
- A ∩ A' = ∅
- A ∪ A' = U


8. Laws involving empty set:

- A ∪ ∅ = Λ
- A ∩ ∅ = ∅


9. Laws involving Universal set:

- A ∪ U = U
- A ∩ U = A

Tuesday, 27 December 2016

Smallest of two 8-bit numbers

Here is an example of Assembly Language code for 8086. This example illustrates how the smallest of two 8-bit number using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 09H                       // this instruction will move                                                                                                the operand 09H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              CMP  AL, BL                                             // this instruction will compare the
                                                                              content of the Register B with the
                                                                              content of the accumulator, by the
                                                                              means of subtraction.
              JC NEXT                                            // this instruction will cause a jump
                                                                                to the next label if a carry is
                                                                                generated.
              MOV [2035H], BL                               // if carry is not generated the result
                                                                               from Register B would be moved
                                                                               to the memory location 2035H.
 NEXT: MOV [2035H], AL                               // if carry is generated the result
                                                                               from accumulator would be moved
                                                                               to the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program




NOTE:
While actually implementing this code the keyword next should be replaced with the address of the instruction.

Largest of two 8-bit numbers

Here is an example of Assembly Language code for 8086. This example illustrates how the largest of two 8-bit number using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 09H                       // this instruction will move                                                                                                the operand 09H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              CMP  AL, BL                                             // this instruction will compare the
                                                                              content of the Register B with the
                                                                              content of the accumulator, by the
                                                                              means of subtraction.
              JNC NEXT                                            // this instruction will cause a jump
                                                                                to the next label if no carry is
                                                                                generated.
              MOV [2035H], BL                               // if carry is generated the result from
                                                                               Register B would be moved to the
                                                                               memory location 2035H.
 NEXT: MOV [2035H], AL                               // if carry is not generated the result
                                                                               from accumulator would be moved
                                                                               to the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program




NOTE:
While actually implementing this code the keyword next should be replaced with the address of the instruction.

1's Complement

Here is an example of Assembly Language code for 8086. This example illustrates how the 1's complement of an 8-bit number using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 07H                       // this instruction will move                                                                                                the operand 07H to the accumulator.
              NOT  AL                                             // this instruction will flip the
                                                                              content of the accumulator by
                                                                              finding 1's complement of its single
                                                                               operand.
              MOV [2035H], AL                               // the result would be moved to
                                                                                the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program

2's Complement

Here is an example of Assembly Language code for 8086. This example illustrates how the 2's complement of an 8-bit number using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 07H                       // this instruction will move                                                                                                the operand 07H to the accumulator.
              NEG  AL                                             // this instruction will negate the
                                                                              content of the accumulator by
                                                                              finding 2's complement of its single
                                                                               operand.
              MOV [2035H], AL                               // the result would be moved to
                                                                                the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program
          

Subtraction of two 8-bit numbers

Here is an example of Assembly Language code for 8085. This example illustrates how the subtraction of two 8 bit numbers using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 09H                       // this instruction will move                                                                                                the operand 09H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              SUB  AL, BL                                             // this instruction will subtract the
                                                                              content of the Register B from the
                                                                              content of the accumulator.
              MOV [2035H], AL                               // the result would be moved to
                                                                                the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program
          

Addition of two 16-bit numbers with carry

Here is an example of Assembly Language code for 8086. This example illustrates how the addition of two 16 bit numbers using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 99H                             // this instruction will move
                                                                              the operand 99H to the accumulator.
              MOV BL, 90H                                    // this instruction will move
                                                                              the operand 90H to the Register B.
              ADC  AL, BL                                             // this instruction will add the
                                                                              content of the Register B with the
                                                                              content of the accumulator, the result
                                                                               would be stored in AL and the carry
                                                                                bit would be stored in AH.
              MOV [2035H], AL                               // the result would be moved to
                                                                                the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program
          

Monday, 26 December 2016

Multiplication of two 8-bit numbers

Here is an example of Assembly Language code for 8086. This example illustrates how the multiplication of two 8 bit numbers using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 02H                             // this instruction will move
                                                                              the operand 02H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              MUL  BL                                             // this instruction will multiply the
                                                                              content of the Register B with the
                                                                              content of the accumulator.
              INT  21H                                             // call the interrupt handler 0x21
                                                                              which is the DOS Function dispatcher.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program


Addition of two 8-bit numbers (Direct Addressing Mode)

Here is an example of Assembly Language code for 8085. This example illustrates how the addition of two 8 bit numbers using Direct Addressing Mode is done.

This can be done in two ways:

Way 1:

DATA  SEGMENT                                             // start of the logical data segment
          SUM  DB  ?                                              // this instruction directs the
                                                                             assembler to reserve one
                                                                             memory location and leave
                                                                             it uninitialized it for the                                                                                                             variable named SUM.
DATA  ENDS                                                     // end of the logical data segment


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE, DS:DATA            // this instruction will inform
                                                                              the assembler that CS and                                                                                                             DS will be assumed names
                                                                              for the code and data logical
                                                                              segments respectively.
START: MOV  AX, [5000H]                              // this instruction will move
                                                                              the operand from the memory
                                                                              location 5000H to the accumulator.
              MOV  BX, [5001H]                              // this instruction will move
                                                                              the operand from the memory
                                                                              location 5001H to the Register B.
              ADD  AX, BX                                      // this instruction will add both
                                                                             numbers and will move the
                                                                             result to the accumulator
              MOV [1504H], AX                              // this instruction will move
                                                                              the result from the accumulator
                                                                              to the memory location 1504H.
              HLT                                                       // Halt
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program


Way 2:

CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                              the assembler the assumed name of CS.              START: MOV  AL, 05H                                   // this instruction will move
                                                                              the operand 05H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              ADD AL, BL                                      // this instruction will add both
                                                                             numbers and will move the
                                                                             result to the accumulator
              MOV [2000H], AL                              // this instruction will move
                                                                              the result from the accumulator
                                                                              to the memory location 2000H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program

Sunday, 25 December 2016

The 8086 String Instruction

1. MOVS:

- MOVS instruction is used for moving a string of ASCII characters from one place in the memory to the another place.

2. MOVSB:

- MOVSB instruction will perform all the actions in repeat unit loop.
- The MOVSB instruction will copy a byte from the location pointed to by the Direct Index Register.
- It will then automatically increment SI to point to the next source location.
- If you add a special prefix called the repeat prefix in front of the MOVSB instruction, the MOVSB instruction will be repeated and CX decremented until CX is counted down to zero.
- The source index register, SI must contain the offset of the start of the source string and the start of the destination location.
- Also, the number of string elements to be moved must be loaded into the CX register.
- If the direction flag is cleared with CLD instruction, then the pointers in SI and DI will automatically be incremented after each string operation. If the direction flag is set with an STD instruction, then the pointers in SI and DI will be automatically decremented after each string operation.
- It is necessary to initialize the extra segment register, for string instructions an offset in DI is added to the segment base represented by the number in the extra segment register to produce a physical address.
- If DS and ES are initialized with the same value then SI and DI will point to locations in the same segment.

3. MOVSW:

- The MOVSB instruction can be used to move a string of words depending on the state of the direction flag, SI and DI will automatically be incremented or decremented by 2 after each word move.

4. MOVSB: 

- A single MOVSB  instruction can cause the 8086 to move up to 65,536 bytes from one location in memory to another.

'$':

- A '$' is used to symbolically represent the current value of the location at any point.
- This trick with the $ sign allows you to load the number of string elements in CX symbolically, rather than having to manually count the number. This trick has the further advantage that if the password is changed and the program reassembled, the instruction that loads CX with the string length will automatically use the new value.

Jumps, Flags and Conditional Jumps


1. Flags

- Flags indicate whether some condition is present or not.


2. Jump

- Jump instructions are used to tell the computer the address to fetch its next instruction from.
- There are two types of jump instructions:
                      a. Conditional Jump Instruction
                      b. Unconditional Jump Instruction


a. Conditional Jump Instruction

- Conditional jump evaluates the state of specified flag to determine whether to fetch its next instruction from the jump destination location or to fetch its next instruction from the next sequential memory location.

Fig. 1. Flow chart showing the working of conditional jump

b. Unconditional Jump Instruction

- When the 8086 executes a jump(JMP) instruction, it loads a new number into the instruction pointer register and in some cases, it also loads a new number into the code segment register.

- If the jump destination is in the same code segment, the 8086 only has to change the contents of the instruction pointer. This type if a jump is referred to as a near or intrasegment jump.

-  If the jump destination is in the different code segment, the 8086 has to change the contents of the instruction pointer and the code segment to make the jump. This type of jump is referred to as far jump or intersegment jump.

- Near and far jumps are further described as either
   i) Direct
      - If the destination address for the jump is specified directly as a part of the instruction, then the jump is described as direct. It is further classified as direct near jump and direct far jump.
  ii) Indirect
      - If the destination address for the jump is contained in a register or memory location, the jump is referred to as an indirect jump.

The direct near and Short type jump instructions

- A near-type jump instruction can cause the next instruction to be fetched from anywhere in the current code segment.

- A 16 bit signed displacement means that the jump can be to a location anywhere from +32,767 to -32,768 bytes from the current instruction pointer location.

- A positive displacement is an ahead jump. and a negative displacement is a backward jump.

- A special case of the direct near type jump instruction is the direct short type jump.

- If the destination for the jump is within a displacement range of +127 to -127 bytes from the current instruction pointer location, the destination can be reached with just an 8-bit displacement.

Saturday, 24 December 2016

Assembly Language Program Development Tools


1. Editor

- An editor is a program which allows you to create a file containing the assembly language statements for your program.
Example: PC-Write, Wordstar.

- As you type in your program, the editor stores the ASCII codes for the letters and numbers in successive RAM locations.

- When you have typed in all your program, you then save the file on the hard disk. This file is called source file and the extension is .asm.


2. Assembler

- An assembler program is used to translate the assembly language mnemonics for instructions to corresponding binary codes. When you run the assembler, it reads the source file of your program from the disk where you have saved it after editing.

- On the first pass through the source program, the assembler determines the displacement of named data items, the offset of labels, etc. and puts this information in a symbol table.

- On the second pass through the source program, the assembler produces the binary code for each instruction and inserts the offsets, etc. that it calculated during the first pass.

- The assembler generates 2 files on the floppy disk or hard disk. The first file is called object file (.obj).

- The second file generated by assembler is called the assembler list file and is given extension (.lst).


3. Linker

- A linker is a program used to join several object files into one large object file.

- The linker produces a link file which contains the binary codes for all the combined modules. The linker also produces a link map file which contains the address information about the linked files (.exe).


4. Locator 

- A locator is a program used to assign the specific address of where the segments of object code are to be loaded into memory.

- A locator program called EXE2BIN comes with the IBM PC Disk Operating System (DOS). EXE2BIN converts a .exe file to a .bin file which has physical addresses.


5. Debugger

- A debugger is a program which allows you to load your object code program into system memory, execute the program and troubleshoot or debug it.

- The debugger allows you to look at the contents of registers and memory locations after your program runs.

- It allows you to change the contents of registers and memory locations and re-run the program.

- Some debuggers allow you to stop execution after each instruction so that you can check or alter after each register contents.

- A debugger also allows you to set a breakpoint at any point in your program. If you insert a breakpoint at any point in your program, the debugger will run the program up to the instruction where you put the breakpoint and then stop the execution.


6. Emulator

- An emulator is a mixture of hardware and software.

- It is used to test and debug the hardware and software of an external system, such as the prototype of a microprocessor based instrument. Part of the hardware of an emulator is a multiwire cable which connects the host system to the system being developed.

Friday, 18 November 2016

Addition of two 8 bit numbers (Immediate Addressing Mode)

Here is an example of Assembly Language code for 8085. This example illustrates how addition of two 8 bit numbers using Immediate Addressing Mode is done.

DATA SEGMENT                                             // start of the logical segment
          FI_NO  DB  05H                                     // this instruction directs the
                                                                              assembler to reserve one
                                                                              memory location and initialize
                                                                              it with the value of 05 in
                                                                              hexadecimal for the variable
                                                                              named FI_NO.
          SE_NO  DB 03H
          AV_SUM  DB  ?                                     // this instruction directs the
                                                                             assembler to reserve one
                                                                             memory location and leave
                                                                             it uninitialized it for the                                                                                                             variable named AV_SUM.
DATA ENDS                                                     // end of the logical segment

CODE SEGMENT                                            // start of the logical segment
         ASSUME  CS:CODE  DS:DATA            // this instruction will inform
                                                                              the assembler that CS and                                                                                                             DS will be assumed names
                                                                              for the code and data logical
                                                                              segments respectively.
START: MOV  AX  DATA                               // data segment is initiallised
              MOV DS  AX                                      
              MOV AL  FI_NO                               // this instruction will get the
                                                                             first number in accumulator
              MOV BL  SE_NO                              // this instruction will get the
                                                                             second number in B register.
              ADD AL  BL                                      // this instruction will add both
                                                                             numbers and will move the
                                                                             result to the accumulator
              MOV AV_SUM  AL                           // this instruction will move
                                                                              the result from the accumulator
                                                                              to the memory location which
                                                                              was left uninitialized with the
                                                                              variable named AV_SUM.
CODE ENDS                                                    // end of the logical segment
     END START                                                // end of the program

Tuesday, 11 October 2016

Constructing the Machine Codes for 8086 Instructions

- Since there are such a large number of possible codes for the 8086 instructions, it is impractical to list them all in a simple table.

- Instead, we use a template for each basic instruction type and fill in bits within this template to indicate the desired addressing mode, data type, etc.

- In other words we build up the instruction code on a bit by bit basis.


MOV instruction coding format

- At least 2 code bytes are required for the instruction.

- The upper 6 bits of the first byte are an opcode which indicates the general type of instruction.

- The 'W' bit in first word is used to indicate whether a byte of a word is being moved. If byte, make W=0 else if word make W=1.

- In this instruction one operand must always be a register, so 3 bits in the second byte are used to indicate which register is involved.

- The 'D' bit in the first byte of the instruction is used to indicate whether the data is being moved to the register identified in 'REG' field of the second byte or from that register.

- If the instruction is moving data to the register identified in the REG field, make D=1.

- If the instruction is moving data from that register, make D=0.

- The 2-bit field labelled 'MOD' and the 3-bit field labeled 'R/M' in the second byte of the instruction code are used to specify the desired addressing mode for the other operand.


Sunday, 18 September 2016

Assembler Directives

Assembler

- An assembler is a program used to convert an assembly language program into the equivalent machine code modules which may further be converted to executable codes.

- The assembler decides the address of each label and substitutes the values for each of the constants and variables,

- It then forms the machine code for the mnemonics and data in the assembly language program.

- While doing these things, the assembler may find out syntax errors.


Assembler Directives

- For completing all these tasks(mentioned above), an assembler needs some hints from the programmer, i.e. the required storage for a particular constant or variable, logical names of the segments, types of the different routines and modules, end of file, etc.

- These types of hints are given to the assembler using some predefined alphabetical strings called assembler directives.

_________________________________________________________________________________

Assembler Directives help the assembler to correctly understand the assembly language programs to prepare the codes.
_________________________________________________________________________________

Now, lets learn about some of these directives;

1. Define Byte (DB):
- The DB directive is used to reserve byte or bytes of memory locations in the available memory.
   Example:
                  LIST DB 01H, 02H, 03H, 04H
   This statement directs the assembler to reserve four memory locations for a list named LIST and          initialize them with the above specified values.

                  MESSAGE DB 'GOOD MORNING'
   This makes the assembler reserve the number of bytes of memory equal to the number of characters    in the string named MESSAGE and initialize those locations by the ASCII equivalent of these            characters.

                  VALUE DB 50H
   This statement directs the assembler to reserve 50H memory bytes and leave them uninitialised for      the variable named VALUE. 

2. Define Word (DW):
- Used to reserve the number of memory words (16-bit) in the available memory.
   Example:
                  WORDS DW 1234H, 4567H, 78ABH, 045CH
                   WDATA DW 5 DUP (6666H)
   Reserve five words i.e. 10 bytes of memory for a word label WDATA and initialise all the word          locations with 6666H.

3. Define Quad Word (DQ):
- This directive is used to direct the assembler to reserve four words (8 bytes) of memory for the            specified variable and may initialize it with the specified values.

4. Define Ten Bytes (DT)

5. Double Word (DD)

6. Assume logical segment name (ASSUME):
- Used to inform the assembler the names of the logical segments to be assumed for different                  segments used in the program.
   Example:
                  ASSUME DS:DATA

7. End of Program (END):
- Marks the end of assembly language program.
- When the assembler comes across this END directive, it ignores the source lines available later on.

8. End of Procedure (ENDP):
- To mark end of a particular procedure, the name of procedure may appear as a prefix with the              directive ENDP.
   Example: PROCEDURE STAR
                             .
                             .
                             .
                    STAR ENDP

9. End of Segment (ENDS):
- Marks end of a logical segment.
   Example: DATA SEGMENT
                          .
                          .
                          .
                    DATA ENDS

- The SEGMENT and ENDS directives are used to identify a group of data items or group of instructions that you want to be put together in a particular segment.

- A group of data statements or a group of instruction statements contained between SEGMENT and ENDS directives is called a LOGICAL SEGMENT.

- A logical is not usually given a physical starting address when it is declared. After the program is assembled and perhaps linked with other assembled program modules, it is then assigned the physical address where it will be loaded in memory to be run.

Saturday, 27 August 2016

Data Addressing Modes of 8086

     1. Immediate Addressing Mode
In this mode, 8 or 16 bit data(operand) can be specified as part of the instruction.
____________________________________
|      OP Code        |      Immediate Operand   |
|______________|_____________________|

Example: MOV CL, 03H
              = Moves the 8 bit data  03H into CL

                MOV DX, 0525H
              = Moves the 16 bit data 0525H into DX

A constant value such as "VALUE" can be defined by the assembler EQUATE directive such as
  
              VALUE EQU 35H
Example: MOV BH, VALUE
             = Used to load 35H into BH


     2. Register Addressing Mode
The operand to be accessed is specified as residing in an internal register of 8086.

Example: MOV DX, CX
             = Move 16 bit content of CX into DX

                MOV CL, DL
             = moves 8 bit content of DL into CL


     3. Direct Addressing Mode
The instruction Opcode is followed by an Effective Address(EA), this effective address is directly used as the 16 bit offset of the storage location of the operand from the location specified by the current value in the selected segment register.

The default segment is always DS.

PA= DS:EA
Segment override prefix (SOP)
PA =  _    _
          | CS | 
          | DS |      :         [ Direct Address ]
          |  SS |
          |  ES |
          --    -- 


     4. Register Indirect Addressing Mode
The EA is specified in either pointer(BX) register or an index (SI or DI) register. The 20 bit physical address is computed using DS and EA.

Example: MOV [DI], BX
             If [DS] = 5004, [DI]=0020, [BX]=2456, PA=[50060]
             The content of BX is moved to memory locations 50060H and 50061H.

               MOV AL, [START+BX]
              The 8 bit content of this memory location is moved to AL.
               The kind of addressing used in this particular example is known as Based Addressing Mode,                since BX pointer is used. 
               
               Indexed Addressing Mode: MOV BH, START [SI]
                                                         Here Physical Address(PA) will be [START]+[SI]+[DS]

               Based Indexed Addressing Mode: MOV ALPHA[SI][BX], CL
                                                         Here PA will be ALPHA+[SI]+[BX]+[DS]


     5. Input-Output Mode (Direct):
Here port number is an 8-bit immediate operand.

Example: OUT 05H, AL
                Outputs [AL] to 8-bit port 05H.

          Input-Output (Indirect):
The port number is taken from DX.

Example: IN AL, DX
              If [DX] = 5040,
              8 bit content by port 5040 is moved to AL.


     6. Relative Addressing Mode
Example: JNC START
             If CY=0, then PC is loaded with current PC contents plus 8 bt signed value of START,                        otherwise the next instruction is executed.


     7. Implied Addressing Mode
Instruction using this operating mode have no operands.

Example: CLC which clears the carry flag.