Attention: Dear visitors If you find any answer or something wrong on allvirtuals.blogspot.com plz feel free to contact me ali.hse123@gmail.com or leave comments

Saturday, 19 November 2011

CS403 Assignment No. 02 fall 2011


Objective
To understand the Basics of Drawing ERD

Instructions:
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit if:

The assignment is submitted after due date.
  1. The submitted assignment does not open or file is corrupt.
  2. The assignment is copied (from other student or copy from handouts).
  3. The assignment is in the format other than MS Word (doc).
  4. Student ID is not mentioned in the assignment File or name of file is other than student ID.
Draw an ER Diagram of “Inventory Management System” on the basis of information given below. Follow the given “Rules” to draw Cardinalities and Relationships between Entities.

 * ERD must be drawn by using MS-Word. No other submitted format is acceptable.

Entities and Attributes:

Customer:
-          C-ID (Key)
-          C-Name
-          C-Address
-          C-Phone#

Order:
-          Order-ID (Key)
-          O-Description

Invoice:
-          Inv-ID (Key)
-          Inv-Description
-          Total-Amount

Product:
-          P-ID (Key)
-          P-Name
-          P-Price

Category:
-          Cat-ID (Key)
-          Cat-Description

Vendor:
-          V-ID (Key)
-          V-Name
-          V-Address

Store:
-          S-ID (Key)
-          S-Location
-          S-Phone#

Hall:
-          H-ID (Key)

Rules:
Customer can place many Orders at a time. He also may not place any Order
ü      There is always one Invoice for each Order.
ü      One Order can have one or many Products. And one Product can be ordered many times or may not be ordered at all.
ü      A Vendor provides many products and it is also possible that organization order single product from multiple vendors.
ü      One Category can have many products, but must have at least one product. And one product must belongs to a single category.
ü      A Store has Products of many Categories. And Products of one Category is always placed in one Store.
ü      One store has multiple halls and one hall belongs to single store.

Solution:  CS403 Assignment No. 02 fall 2011

By HSE with No comments

Subjective Question for CS401




Q#21 Mark 2
What are the instructions used by assembly language for permanent and temporary diversions.

Q#22 Mark 2
Which instruction is used to determine zero bit in string.

Q#23 Mark 3
Explain the use of TEST instruction.
The test instruction is used for bit testing. BX holds the mask and in every next iteration it is shifting left, as our concerned bit is now the next bit.

Q#24 Mark 3
Explain LES and LDS

The string instructions need source and destination in the form of a segment offset pair. LES and LDS load a segment register and a general purpose register from two consecutive memory locations. LES loads ES while LDS loads DS. Both instructions has two parameters, one is the general purpose register to be loaded and the other is the memory location from which to load these registers. The major application of these instructions is when a subroutine receives a segment offset pair as an argument and the pair is to be loaded in a segment and an offset register.

Q#25 Mark 5
Describe local variables.
Another important role of the stack is in the creation of local variables that are only needed while the subroutine is in execution and not afterwards. They should not take permanent space like global variables. Local variables should be created when the subroutine is called and discarded afterwards. So that the spaced used by them can be reused for the local variables of another subroutine. They only have meaning inside the subroutine and no meaning outside it.
The most convenient place to store these variables is the stack. We need some special manipulation of the stack for this task. We need to produce a gap in the stack for our variables. This is explained with the help of the swapflag in the bubble sort example.
The swapflag we have declared as a word occupying space permanently is only needed by the bubble sort subroutine and should be a local variable. Actually the variable was introduced with the intent of making it a local variable at this time. The stack pointer will be decremented by an extra two bytes thereby producing a gap in which a word can reside. This gap will be used for our temporary, local, or automatic variable; however we name it. We can decrement it as much as we want producing the desired space, however
the decrement must be by an even number, as the unit of stack operation is a word. In our case we needed just one word. Also the most convenient position for this gap is immediately after saving the value of SP in BP. So that the same base pointer can be used to access the local variables as well; this time using negative offsets. The standard way to start a subroutine which needs to access parameters and has local variables is as under.
push bp
mov bp, sp
sub sp, 2
 The gap could have been created with a dummy push, but the subtraction makes it clear that the value pushed is not important and the gap will be used for our local variable. Also gap of any size can be created in a single instruction with subtraction. The parameters can still be accessed at bp+4 and bp+6 and the swapflag can be accessed at bp-2. The subtraction in SP was after taking the snapshot; therefore BP is above the parameters but below the local variables. The parameters are therefore accessed using
positive offsets from BP and the local variables are accessed using negative offsets.

By HSE with No comments

CS401 Subjective Questions


Q#: 28    ( Marks: 2 )
 Write instructions to do the following. Copy contents of memory location with offset 0025 in the current data segment into AX.

Ans:

Mov ax , [0025]

mov[0fff], ax

mov  ax , [0010]
   mov [002f] , ax

   
Q#: 29    ( Marks: 2 )

 Write types of Devices?

Ans:
There are two types devices used  in pc.
  1. Input devices(keyboard, mouse,)
  2. Output devices.(monitor, printer)


   
Q#: 30    ( Marks: 2 )

What dose descriptor 1st 16 bit tell?

Ans:
Each segment is describe by the descriptor like
  1. base,
  2. limit,
  3. and attributes,
it  basically define the actual base address.


   
Q#: 31    ( Marks: 3 )

List down any three common video services for INT 10 used in text mode.

Ans:
INT 10 - VIDEO - SET TEXT-MODE CURSOR SHAPE
AH = 01h
CH = cursor start and options
CL = bottom scan line containing cursor (bits 0-4)

Q#: 32    ( Marks: 3 )

How to create or Truncate File using INT 21 Service?

Ans:


INT 21 - TRUNCATE FILE
AH = 3Ch
CX = file attributes
DS:DX -> cs401 filename
Return: 
CF = error flag
AX = file handle or error code

   
Q#: 33    ( Marks: 3 )

How many Types of granularity also name them?
Ans:
There are three types of granuality :
  1. Data Granularity
  2. Business Value Granularity
  3. Functionality Granularity 
   
Q#: 34    ( Marks: 5 )

How to read disk sector into memory using INT 13 service?


Ans:
INT 13 - DISK - READ SECTOR(S) INTO MEMORY :
AH = 02h
AL = number of sectors to read (must be nonzero)
CH = low eight bits of cylinder number
CL =                sector number 1-63 (bits 0-5)
                          high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer


Return: 
CF = error flag
AH = error code
AL = number of sectors transferred
   
Q#: 35    ( Marks: 5 )

The program given below is written in assembly language. Write a program in C to call this assembly routine.
[section .text]
global        swap
swap:        mov  ecx,[esp+4]      ; copy parameter p1 to ecx
                  mov  edx,[esp+8]      ; copy parameter p2 to edx
                  mov  eax,[ecx]           ; copy *p1 into eax
                  xchg eax,[edx]           ; exchange eax with *p2
                  mov  [ecx],eax           ; copy eax into *p1
                  ret                               ; return from this function


Ans:
The above code will assemble in c through this command. Other aurwise error will occur.
Nasm-f win32 swap .asm

This command will generate swap.obj file.
The code for given program will be as follow.

#include <stdio.h>
Void swap(int* pl, int* p2);
Int main()
{
      Int a=10,
      Int b= 20;
Print f (“a=%d b=%d\n” , a ,b);

Swap (&a ,&b);

Print f (“a=%d b=%d\n” , a ,b);

System ( “pause”);


Return 0;


}



   
Q#: 36    ( Marks: 5 )

Write the code of “break point interrupt routine”.


Ans:
[org 0x0100]
jmp start
flag: db 0 ; ………………flag whether a key pressed
oldisr: dd 0 ; ……………..space for saving old ISR
names: db 'FL =CS =IP =BP =AX =BX =CX =DX =SI =DI =DS =ES ='
Breakpoint interrupts service routine :
debugISR:       push bp
              mov  bp, sp             ; …………….to read cs, ip and flags
              push ax
              push bx
              push cx
              push dx
              push si
              push di
              push ds
              push es

              sti                     ;…………………….. waiting for keyboard interrupt
              push cs
              pop  ds                 ;…………………… initialize ds to data segment

              mov  ax, [bp+4]         
              mov  es, ax             ; ………………….load interrupted segment in es
              dec  word [bp+2]        ; ……………….decrement the return address
              mov  di, [bp+2]         ;………………… read the return address in di
              mov  word [opcodepos], di ;…………. remember the return position
              mov  al, [opcode]       ; …………..load the original opcode
              mov  [es:di], al        ;………….. restore original opcode there

              mov  byte [flag], 0     ; …………set flag to wait for key
              call clrscr             ;……………. clear the screen

              mov  si, 6              ; …………..first register is at bp+6
              mov  cx, 12             ;………… total 12 registers to print
              mov  ax, 0              ; …………..start from row 0
              mov  bx, 5              ; ………….print at column 5

          push ax                 ; ………………..row number
              push bx                 ;………………. column number 
              mov  dx, [bp+si]
              push dx                 ;………………. number to be printed
              call printnum           ;…………….. print the number
              sub  si, 2              ; ……………….point to next register 
              inc  ax                 ; ………………..next row number 
              loop l3                 ; ……………….repeat for the 12 registers

              mov  ax, 0              ; ………………..start from row 0
              mov  bx, 0              ; ………………..start from column 0
              mov  cx, 12             ; …………………..total 12 register names
              mov  si, 4              ;……………………. each name length is 4 chars
              mov  dx, names          ; …………………..offset of first name in dx

              push ax                 ;………………………. row number 
              push bx                 ; ………………………column number 
              push dx                 ; ……………………….offset of string
              push si                 ; ………………………….length of string
              call printstr           ; ………………………….print the string
              add  dx, 4              ;………………………….. point to start of next string 
              inc  ax                 ; ……………………………new row number
              loop l1                 ;…………………………….. repeat for 12 register names

              or word [bp+6], 0x0100  ; ……………………set TF in flags image on stack

keywait:      cmp  byte [flag], 0     ;……………………. has a key been pressed
              je   keywait            ;            ………………….. no, check again

              pop es

              pop ds
              pop di
              pop si
              pop dx
              pop cx
              pop bx
              pop ax
              pop bp
              iret

start:        xor  ax, ax
              mov  es, ax             ;            ……………………point es to IVT base
              mov  word [es:1*4], trapisr ;…………………. store offset at n*4
              mov  [es:1*4+2], cs     ;      …………………...store segment at n*4+2
              mov  word [es:3*4],            …………………..debugisr ; store offset at n*4
              mov  [es:3*4+2], cs     ;      …………………..store segment at n*4+2
              cli                     ;                  ………………….disable interrupts
              mov  word [es:9*4], kbisr ; ………………….store offset at n*4
              mov  [es:9*4+2], cs     ; ……………………...store segment at n*4+2
              sti                     ;             ………………………enable interrupts



Q#: 1    ( Marks: 1 )    :-

SP is associated with…………. By default
       ► SS
       ► DS
       ► CS
       ► ES
   
Q#: 2    ( Marks: 1 )    :-

Which bit of the attributes byte represents the red component of foreground color
       ► 5
       ► 4
       ► 3
       ► 2
   
Q#: 3    ( Marks: 1 )    :-

 An 8 x 16 font is stored in ______________ bytes.
       ► 2
       ► 4
       ► 8
       ► 16
   
Q#: 4    ( Marks: 1 )    :-

In DOS input buffer, the number of characters actually read on return is stored in ___________ byte.
       ► third
       ► fourth  
       ► first 
       ► second      
   
Q#: 5    ( Marks: 1 )    :-

Which of the following gives the more logical view of the storage medium
       ► BIOS
       ► DOS
       ► Both
       ► None
   
Q#: 6    ( Marks: 1 )    :-

In STOSW instruction, when DF is clear, SI is

       ► Incremented by 1

       ► Incremented by 2

       ► Decremented by 1

       ► Decremented by 2

   
Q#: 7    ( Marks: 1 )    :-

Which of the following interrupts is Non maskable  interrupt

       ► INT 2
       ► INT 3
       ► INT 0
       ► INT 1
   
Q#: 8    ( Marks: 1 )    :-

Which of the following IRQs is connected to serial port COM 2?

       ► IRQ 0
       ► IRQ 1
       ► IRQ 2
       ► IRQ 3
   
Q#: 9    ( Marks: 1 )    :-

The time interval between two timer ticks is ?

       ► 40ms
       ► 45ms
       ► 50ms
       ► 55ms

By HSE with No comments

CS401 Mid Term Material


CS401-Computer Architecture & Assembly Language
1.       The shift logical right operation inserts
2.      After the execution of “PUSH   AX” statement
3.      The extended ASCII has 256 characters
4.     The iAPX88 processor supports _____________modes of memory access.
5.      In STOS instruction, the implied source will always be in  AL or AX registers
6.     The maximum memory, IAPX88 can access is________.
7.      The registers IP, SP, BP, SI, DI, and BX all can contain a ________offset.
8.     In the “mov ax, 5”     5 is the __________ operand.
9.      In MUL instruction if the source operand is a word then it is multiplied by register
10.  The prevalent and standard format for representation of characters in computers is
11.   which bit sets the character "blinking" on the screen?
12. “mov byte [num1], 5” is _________ instruction.
13.  _____ can process blocks of data in one go.
14.  In string instructions, CX is always
15.   STOS transfers a byte or word from register AL or AX to the string element addressed by
16.  The execution of the instruction “mov word [ES : 0],  0x0741” will print character  “A” on screen, color of the character will be
17.   In  A4FB:4872  Segment:offset pair the physical address is (both segment and offset are in hexadecimal):  A9822
18.  Which of the following operations relating to PUSH is true?
19.  If the decimal number "35" is shifted by two bits to left, the new value will be _________
20. Which of the following flags will be affected by MOVSB?
21. Explain the fuction of rotate right (ROR) instruction
The rotate right (ROR) and rotate through carry right (RCR) instructions shift all the bits toward less significant bit positions, except for the least-significant bit, which is rotated to the most-significant bit location
22.                        Why REP prefix is generally not used with LODS instruction?
The lods instruction is unique among the string instructions. We will never use a repeat prefix with this instruction. Because it copies the byte or word pointed at by ds:si into the al, ax, or eax register, after which it increments or decrements the si register by one, two, or four. Repeating this instruction via the repeat prefix would serve no purpose whatsoever since the accumulator register will be overwritten each time the lods instruction repeats. At the end of the repeat operation, the accumulator will contain the last value read from memory.
23.                        Write all steps of  algorithm for printing number 352.

In this technique the first digit printed is the right most one
Divide the number by base (10 in case of decimal)..The remainder after
first division was 3, after second division was 5 and after the third division
was 2.
• The remainder is its right most digit
• Convert the digit to its ASCII representation
• Save this digit on stack
• If the quotient is non-zero repeat the whole process to get the next
digit, otherwise stop.

• Pop digits one by one and print on screen left to right. Stack is a Last In First Out structure so if 3, 5, and 2 are pushed on it, 2, 5, and 3 will come
out in this order.
24. What are the result after performing the instruction      (each carry 1 marks )
1.                            and ax,bx
2.                           or ax,bx
3.                           xor ax,bx

Given that ax = 00110011 and bx = 00010001
25. Describe Local Variables?
A local variable is valid within the statement block in which it is defined and within any nested statement blocks, unless you redefine the variable within the statement block.
Local variables should be created when the subroutine is called and discarded afterwards. So that the spaced used by them can be reused for the local variables of another subroutine. They only have meaning inside the subroutine and no meaning outside it.
It is important role of the stack to create local variables that are only needed while the subroutine is in execution and not afterwards. They should not take permanent space like global variables.

The most convenient place to store these variables is the stack. We need some special manipulation of the stack for this task. We need to produce a gap in the stack for our variables.
Are valid only for the duration of the SPL routine
Are reset to their initial values or to a value the user passes to the routine, each time the routine is executed
Cannot have default values
26.                        Explain the complete operation of Interrupt when it is generated.
Interrupt  is the result of an INT instruction (software interrupt) or it is generated by an external hardware which passes the interrupt number by a different mechanism. The currently executing instruction is completed, the current value of FLAGS is pushed on the stack, then the current code segment is pushed, then the offset of the next instruction is pushed. After this it automatically clears the trap flag and the interrupt flag to disallow further interrupts until the current routine finishes. After this it loads the word at nx4 in IP and the word at nx4+2 in CS if interrupt n was generated. As soon as these values are loaded in CS and IP execution goes to the start of the interrupt handler. When the handler finishes its work it uses the IRET instruction to return to the caller. IRET pops IP, then CS, and then FLAGS. The original value of IF and TF is restored which re-enables further interrupts

By HSE with No comments