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.