الجمعة، 16 مايو 2014

merge_sort


#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void sort(int left, int right);
void merge(int left, int mid, int right);
int a[9] = { 75, 40, 10, 90, 50, 95, 55, 15, 65};
int tmp[9];
void sort(int left, int right)
{

if (left < right)
{
int mid = (left + right) / 2;
sort(left, mid);
sort(mid + 1, right);
merge(left, mid, right);
}
}

void merge(int left, int mid, int right)
{
int i = left;
int j = left;
int k = mid + 1;
while (j <= mid&&k <= right)
{
if (a[j] < a[k])
tmp[i++] = a[j++];
else
tmp[i++] = a[k++];
}
while (j <= mid)
tmp[i++] = a[j++];
for (i = left; i < k; i++)
a[i] = tmp[i];
}
void main()
{
sort(0, 8);
cout << "sort array:"<<"\n";
for (int i = 0; i < 9; i++)
cout << a[i] << " ";
_getch();

}
الاثنين، 5 مايو 2014

Q8: find even number from 1000 to 2000


org 100h

.data
dt1 dw 500 dup(0)

.code 

 mov ax,@data
 mov ds,ax

 mov si, offset dt1

 mov bx,1000
 mov cx,500
 label:
 mov [si],bx
 add bx,0002
 inc si
 inc si
 loop label

hlt

note: see in memory in two byte CE and 06 equal 1998 , so it down 1996 see cc,07


another way for find even number from 1000 to 1500:

org 100h

.data
dt1 db 250 dup(0)
.code
mov ax,@data
mov ds,ax
mov si,offset dt1
mov cx,1000
mov bx,02

new:
    mov [si],cx
    add cx,bx
    add si,bx
    cmp cx,1500
    jle new

ret
الأحد، 27 أبريل 2014

example (nand,or and xor) in vhdl

NAND:-
library IEEE;
use IEEE.std_logic_1164.all ;
entity NANDGATE is
 port (a : in std_logic;
b : in std_logic;
x : out std_logic ) ;
end entity NANDGATE ;
architecture RTL of NANDGATE is
begin
 x<=a nand b;
end architecture RTL ;

OR:-
library IEEE;
use IEEE.std_logic_1164.all;
entity or is
port ( a : in std_logic;
b: in std_logic;
z: out std_logic ) ;
end or ;
architecture dataflow of or is
begin
z<= a or b;
end dataflow;

XOR:-
library IEEE;
use IEEE.std_logic_1164.all;
entity xor is
 port( a: in std_logic;
b:in std_logic;
z:out std_logic );
architecture dataflow of xor is
beginz<= [a and (not b) or (not a) and b ] ;
end dataflow ;

تعريف VHDL

VHDL is a hardware description language . it describes the behavior of an electronic circuit or system , from which the physical circuit or system can then be attained (implemented) .

once the vhdl code has been written , it can be used either to implement  the circuit in a programmable device (from Altra,Xilinx ,Atmel , etc)  or can be submitted to foundry for fabrication of an ASIC chip . Currently , many complex commercial chips (microcontrollers , for example) are designed using such an approach .

Basic VHDL Code:-

library declarations is To declare a Library (that is to make visible to the design) two lines of code are needed , one containing the name of the library , and the other a use clause , as shown in the syntax below .
LIBRARY library_name ;USE library_name.package_name.package_parts;


ENTITYentity is a list with specifications of all input and output pins (ports)of the circuit . its syntax is show below.
ENTITY entity_name is port (port_name: signal_mode signal_type;port_name: signal_mode signal_type;...... ) ;end entity_name;

architecture the architecture is a description of how the circuit should behave (function) . its syntax is the following:
ARCHITECTURE architecture_name of entity_name is [declaration] BEGIN (Code)end architecture_name;



الخميس، 24 أبريل 2014

َQ6:datasheet to find y=x2-10+x in assembly

org 100h

.data
dt1 db 1,2,3,4,5,6,7,8,9,10
dt2 db 10 dup(0)
.code
mov ax,@data
mov ds,ax
mov si,offset dt1
mov di,offset dt2
mov cx,0ah
lable:
mov ax,[si] 
mov bx,2
mul bx
sub ax,10
add ax,[si]   
mov [di],ax
inc si
inc di
loop lable

ret

الأربعاء، 23 أبريل 2014

logical error

package logical.error;

public class LogicalError {

    public static void main(String[] args) {
String word="debugging";
String single_letter="";
    int letter_count=0;
    for(int i=0;i<word.length();i++)
    {
        single_letter=word.substring(1,1);    // errror
    if(single_letter.equals("g"))
    {
        letter_count++;
    }
    }
        System.out.println("g was fount = "+letter_count+"times");

        }
    
}



after correct:- 

package logical.error;

public class LogicalError {

    public static void main(String[] args) {
String word="debugging";
String single_letter="";
    int letter_count=0;
    for(int i=0;i<word.length();i++)
    {
        single_letter=word.substring(i,i+1);   // correct
    if(single_letter.equals("g"))
    {
        letter_count++;
    }
    }
        System.out.println("g was fount = "+letter_count+"times");

        }
    
}

stack in java

package stack;

public class Stack {


    public static void main(String[] args) {
System.out.println("stack");   
    m1();
            System.out.println("end");
    }
    static void m1()
    {
        System.out.println("function1");
        m2();
    }
    static void m2()
    {
        System.out.println("function2");
    }
}