CS401 Assembly Language Programming Mid Term Solved Subjective Question Answers by Asad Naeem

               
                                                     
CS401 By Asad Naeem                                                                                                                         

Introduction:

Hi Everyone!✋

Here are CS401 Assembly Language Programming Mid Term Solved Subjective Question Answers for Sure 100% Success and Exam Preparation. All Questions are very important and repeated every time in exam.

All answers are according to CS401 Handout. Thus all students are request to prepare these Questions for better CGPA and solid Concepts.

If any student prepare these questions sensibly then he no need of any other material and to prepare whole handout.

Benefits of These Notes:

1.     Time Consuming:
Mostly students are jobs holder so these are very helpful for them. As I mentioned above all are very important so you can save your time by preparing these notes in a very short time, rather no need to prepare a complete Handout of Assembly Language Programming CS401.

2.    All are Past Exams Questions:

     Sometime students confuse about syllabus and pattern about exams questions, so these are very helpful to known about type of questions you will face in exams.

3.     Most Repeated:
All are from Past Exams and most repeated. Sometime examiner change 1 or 2 words of question and its meaning remain the same. So prepare all by creating concepts.

4.     Completely Theoretical:
Most advantage is that all questions are Theoretical
and summary of complete handout. By preparing these notes you will be able to answer the any question you face in exam.

5.     To the point Answers:
All answers given are to the point and according to university and examiner necessities. There is no additional and irrelevant material.

Therefore Prepare them by creating your own concepts and write in your own words in exam. You will not forget these concepts in your future. Then you can taught to others obviously. 


                                                             

Lets Start!

CS401 (Assembly Language Programming) MID TERM QUESTION ANSWER BY CH. ASAD NAEEM BC170200260 Asadnaeem280@gmail.com

Q 1: Affected flag of AND operation?

Affected Flag of AND are: CF (carry flag), OF (Over Flow Flag), PF (Parity Flag), SF (Sign Flag), ZF (zero flag) and AC (Auxiliary Carry).

Q 2: Relation between RET and CALL is dependent or independent.

Technically they are independent in their operation but both the instructions are commonly used as a pair. RET works irrespective of the CALL and the CALL irrespective of the RET.

Q 3: What is the difference between LES (Load Extra Segment) and LDS (Load Data Segment) instruction? Or why we need the general register in LES and LED instruction?

There are two special instructions that load a segment register and a general purpose register. These instructions have two factors, one is the general purpose register to be loaded and the other is the memory location from which to load these registers.

Q 4: Write down the procedure to clear the selective bit.

The source operand is loaded with a mask containing at positions which keep their old value and zero. The effect of applying this operation on the destination with mask in the source is to clear the desired bits. That process is named as masking.

Q 5: Why REP prefix is generally not used with LODS instruction?            

LODS is used in a loop and not with the REP prefix then the value formerly overloaded in the register is overwritten, if the instruction is repeated and only the last value of the block remains in the register.

Q 6: What is difference between REPE (repeat while equal) and REPNE (repeat while not equal)?

REPE or REPZ repeat the next string instruction while the zero flag is set and REPNE or REPNZ repeat the next instruction while the zero flag is not set.

Q 7: Describe PUSH and POP with the help of an example.

The operations of placing items on the stack and removing them are called push and pop. Memory is like a shelf as zero at the top and the maximum at the bottom. If a decrementing stack begin at shelf five, the 1st item is located in shelf 5; the next entry is located in shelf 4, same as the next will in shelf 3 and so on.

Q 8: Explain all characteristics of SCAS (scan string) instruction.

SCAS (Scan String) is used to compare the source byte or word in register AL or AX with the destination string element ES: DI and updates the flags. SCAS (Scan String) is frequently used to place equality or in-equality in a string. SCAS (Scan String) is dissimilar from the other instructions. It’s like a CMP instruction.

Q 9: Describe Local Variable?

Local variables are created by stack. Global variables take permanent space but they not. Local variables formed when the subroutine is called and wasted later. Therefore the space used by them can be use again for the local variables of another subroutine. Local variables only have meaning inside the subroutine and no meaning outside it. The most suitable place to store these variables is the stack.

Q 10: Explain divide overflow error.

If a large number is divided by a very small number it is possible that the percentage is larger than the space. In this case a stop is automatically generated and the program is usually terminated as a result. That is termed as divided overflow error.

Q 11: For what purpose "INT4" is reserved.

For Arithmetic Overflow INT4 is reserved, change of sign bit.                                           

Q 12: Double working of Exchange instruction with help of an example.

XCHG (Exchanges) instructions exchange the contents of the destination (first) and source (second) operands. Two general-purpose registers are called the operands.

Q 13: Two form of String Moves Instruction?

MOVS has the two forms MOVSB and MOVSW.

Q 14: How value of IP (Instruction Pointer) Register is saved & updated when call Instruction executed.

When Call instruction is executed the stack pointer (SP) is decremented by 2 and value of IP is pushed on stack.

Q 15: How many parameters a subroutine can receive through stack.

There are 7 parameters a subroutine can receive.

Q 16: How the string instruction is used in the block of memory?

STOS (store string) transfers a byte or word from register AL or AX to the string element addressed by ES: DI and updates DI to point to the next location. STOS is often used to clear a block of memory or fill it with a constant.

Q 17: How many block processing instructions in 8088, just name the number of processing instructions?

8088 contain only 5 block processing instructions. These 5 block instructions are STOS (store string), LODS (load string), CMPS (compare string), SCAS (scan string), and MOVS (move string) respectively.

Q 18: What are the instruction use by assembly language for permanent diversion and temporarily diversion?

The instructions for permanent diversion in 8088 are the jump instructions, while the instruction for temporary diversion is the CALL instruction.

Q 19: How much string instructions are in assembly language? Write down all instructions.

STOS – Clearing the Screen

LODS – String Printing

SCAS -String Length

LES (Load Extra Segment) and LDS (Load Data Segment)                                             

MOVS -Screen Scrolling

CMPS – String Comparison

Q 20: Describe the purpose of these string instructions? (1) STOS (2) CMPS

1: STOS:-

STOS transfers a byte or word from register AL or AX to the string element addressed by ES: DI and updates DI to point to the next location. STOS is often used to clear a block of memory or fill it with a constant.

2: CMPS:-

CMPS withdraws the source location DS: SI from the destination location ES: DI. Source and Destination are not changed. SI (Source Index) and DI (Destination Index) are updated accordingly. CMPS compares 2 blocks of memory for equality or inequality. It withdraws byte by byte or word by word.

Q 21: What is the syntax of PUSH instruction?

Push ax

Q 22: For what purpose DS and ES registers are generally used in the context of video memory.

To access the video memory both DS and ES are used. However usually we have DS for accessing our data, and load ES with the part of video memory.

Q 23: At what time the instruction “push ax” is performed in decrementing stack and how the value of SP will change.

The instruction “push ax” is executed in decrementing stack, Then SP is decremented by 2 and IP is pushed on the stack.

Q 24: What colors are repeated by 0th, 1st and 2nd bits (from least significant side) in Attribute Byte:

Blue, green, Red

Q 25: How SCAS instructions can be used to detect Null at the end of a string?

We use SCASB with REPNE and a zero in AL to find a zero byte in the string. We can load maximum 64K bytes In CX but actual strings will be much smaller. If SCAS and CMPS stopped due to equality or inequality then the index register have previously incremented. Hence when SCAS will stop DI thatwould be pointing the null character.

Q 26: From where does the contents of SL and DS registers are loaded as a result of execution of the instruction” LDS SI [BP +4]”?

“Lds si, [bp+4]” will load SI from BP+4 and DS from BP+6.

Q 27: How a 16-bit MUL operation is different from 32-bit MUL operation?

If the operands were 16bit the answer would be in 32bit and if the operands were 32bit the answer would be 64bit. For declaration of 16 bit we use “dw” and for 32-bit we use “dd”.

Q 28: Describe the working of the CALL instruction with the reference of Stack.

During the CALL operation, the current value of the IP (instruction pointer) is automatically saved on the stack, and the destination of CALL is loaded in the IP (instruction pointer). Therefore Execution begin again from the destination of CALL.

Q 29: Explain the function of rotate right (ROR) instruction.

In the rotate right operation every bit moves one position to the right and the bit dropped from the right is inserted at the left.

Q 30: Write all steps of algorithm for printing number 352.                                   

The steps of our algorithm are below.

• Divide figure or number by base (10 in case of decimal).

• The remainder is its right most digits.

• Transform the digit into ASCII representation (Add 0x30 to the remainder in case of decimal).

• Save this digit on stack.

• If the proportion is non-zero then repeat the whole process to get the next digit, otherwise stop.

• Pop digits one by one and print on screen left to right.


Q 31: What are the results after performing the instruction?

1. and ax, bx

2. or ax, bx

3. XOR ax, bx

Given that ax = 00110011 and bx = 00010001

1. 0x0011

2. 0x0033

3. 0x0022

Q 32: Explain the complete operation of Interrupt when it is generated.

The result of an INT instruction is named as Interrupt (software interrupt) or it is created by an external hardware which passes the interrupt number by a different instrument. After completion of current executing instruction, the existing value of FLAGS pushed into the stack, then the existing code section is strapped, then the offset of the next instruction is strapped. After this it automatically clears the trap flag and the interrupt flag prohibit further interrupts until the current routine finishes.

Q 33: Which instruction is used to determine zero bits in string?

REPE or REPZ repeat the next string instruction as zero flag is set and REPNE or REPNZ repeat the next instruction as zero flag is not set.

Q 34: Explain the use of TEST instruction.

For bit testing, test instruction is used. BX holds the mask and in every next iteration shifts to left, as our concerned bit is now the next bit.

Q 35: Describe MOVS and CMPS instructions?

1. MOVS

MOVS handovers a byte or word from the source location DS: SI to the destination ES: DI and informs SI and DI to point to the next sites. For moving a block of memory MOVS is used.

2. CMPS

CMPS withdraws the source location DS: SI from the destination location ES: DI. Source and Destination are not changed. SI and DI are updated consequently. CMPS compares 2 blocks of memory for equality or inequality of the block. It withdraws byte by byte or word by word.

Q 36: Define short jump?

If the offset is stored in a single byte as in 75F2 with the opcode 75 and operand F2, the jump is called a short jump. For example Unconditional jumps can be short, near, and far.

Q 37: Every character is displayed on the screen in the form of a word. What individually byte of this word represents?

The second byte in the word chosen for one screen location holds the center and background colors for the character. Therefore the couple of the ASCII code in one byte and the attribute in the second byte creates the word that links to one location on the screen. The lower address contains the code however the higher one holds the attribute.

Q 38: IF DF=0 what its represent and IF DF=1 what its represent?             

It represent that the current operation has to be done from bottom to top of the block (D=0) or from top to bottom of the block (D=1).

Q 39: Explain how extended shifting is performed?

Using our basic shifting and rotation instructions we can effectively shift a 32bit number in memory word by word. We cannot shift the whole number at once as our architecture is limited to word operations. We use just two instructions and we name it extended shifting.

num1: dd 40000

          Shl word [num1], 1

          Rcl word [num1+2], 1

The multiplicand is shifted left as a 32bit number using extended shifting operation.

Q 40: Explain MUL instruction in both cases (i) if the source operand is byte (ii) if the source operand is a word?

MUL (multiply) performs an unsigned multiplication of the source operand and the accumulator. If the source operand is a byte, then it is multiplied by register AL and the double-length result is returned in AH (A High Byte) and AL (A Low Byte). If the source operand is a word, then it is multiplied by register AX, and the double-length result is returned in registers DX and AX.

Q 41: Why is it necessary to provide the segment and offset address in case of FAR jump?

Far jump must be used a two byte segment and a two byte offset are given to it because It loads CS with the segment part and IP with the offset part.

Q 42: What’s your understanding about Incrementing and Decrementing Stack?

A decrementing stack moves from higher addresses to lower addresses as elements are added in it while an incrementing stack moves from lower addresses to higher addresses as elements are added.

Q 43: What is the Difference between CALL and RET?

The CALL instruction allows temporary change and then reusability of code. Therefore RET takes no arguments and transfers control back to the instruction.

Q 44: Tell the Formula to scroll up the screen:

Rep movsw                                         scroll up                                                 

Scrollup: push bp

Mov bp, sp

Push ax

Push cx

Push si

Push di

Push es

Push ds

Mov ax, 80              ; load chars per row in ax

Mul byte [bp+4]      ; calculate source position

Mov si, ax                ; load source position in si

Push si                     ; save position for later use

Shl si, 1                    ; convert to byte offset

Mov cx, 2000           ; number of screen locations

Sub cx, ax                ; count words to move

Mov ax, 0xb800

Mov es, ax               ; point es to video base

Mov ds, ax               ; point ds to video base

Xor di, di                 ; point di to top left column

Cld                          ; set auto increment mode

Rep movsw             ; scroll up

Mov ax, 0x0720     ; space in normal attribute

Pop cx                    ; count of positions to clear

Rep stosw              ; clear the scrolled space

Pop ds

Pop es

Pop di

Pop si

Pop cx

Pop ax

Pop bp

Ret 2

 Q 45: Write a subroutine to calculate the string length?                                   

Subroutine to calculate the length of a string

; Takes the segment and offset of a string as parameters

Strlen: push bp

Mov bp, sp

Push es

Push cx

Push di

Les di, [bp+4]             ; point es: di to string

Mov cx, 0xffff            ; load maximum number in cx

Xor al, al                     ; load a zero in al

Repne scasb                ; find zero in the string

Mov ax, 0xffff            ; load maximum number in ax

Sub ax, cx                  ; find change in cx

Dec ax                        ; exclude null from length

Pop di

Pop cx

Pop es

Pop bp

Ret 4

Q 46: What is difference between SHR (Shift Logical Right) and SAR (Shift Arithmetic Right) instructions?

SHR (shift logical right operation) inserts a zero from the left and transfers every bit one position to the right and copies the rightmost bit in the carry flag.

The operation of SAR (shift arithmetic right) is to move every bit one place to the right with a copy of the most important bit. 

Q 47: For what purpose "INT 1" is reserved?

INT 1, Trap, Single step Interrupt

This interrupt is used in debugging with the trap flag. 8088 was the 1st processor that has this capability to support debugging.

Q 48: Define implied operand?

Implied operand means, it is continuously in a particular register say the accumulator, and it need not be mentioned in the instruction.

Q 49: Explain the process of ADC (add with carry)?

The ADC instruction is specially placed for extending the capability of ADD. Any size of number can be added using an appropriate arrangement of ADD and ADC. Entirely basic building blocks are providing for the assembly language programmer and the programmer can extend its capabilities as much as needed by using these fine instructions in suitable groupings. Further clarifying the operation of ADC, consider an instruction “ADC AX, BX.”

Q 50: Describe mismatch? Define with one example.

If we compose our code in bytes but we state in word then there will be a logical error in the code and it is called size mismatch error.

; A program add 3 numbers via byte variables

[Org 0x0100]

Mov al, [num1]; load first number in al

Mov bl, [num1+1]; load second number in bl

Add al, bl; gather sum in al

Mov bl, [num1+2]; load third number in bl

Add al, bl; gather sum in al

Mov [num1+3], al; store sum at num1+3

Mov ax, 0x4c00; terminate program

Int 0x21

num1: DW 5, 10, 15, 0

 

CS401

Q 51: Compose a subroutine to clear screen.                                                      

; Clear screen using string instructions

[Org 0x0100]

Jmp start

; Subroutine to clear the screen

Clrscr: push es

Push ax

Push cx

Push di

Mov ax, 0xb800

Mov es, ax              ; point es to video base

Xor di, di                ; point di to top left column

Mov ax, 0x0720     ; space char contain normal attribute

Mov cx, 2000          ; number of screen locations

Cld                           ; auto increment style

Rep stosw                 ; clear the whole screen

Pop di

Pop cx

Pop ax

Pop es

Ret

Start: call clrscr        ; call clrscr subroutine

Mov ax, 0x4c00       ; terminate program

Int 0x21

Q 52: Replace the following invalid instruction with the single valid instruction

 (1) Mov IP (2) Mov IP, L5

Mov IP

RET:-The instruction Ret will pop the IP address.

Mov IP, L5                                                                                                             

CALL:-The instruction Ret will pop the IP address.

Q 53: Describe the selective bit testing and operation that can be used with selective bit testing?

AND Operation can be used to check whether particular bits of a number are set or not. We change our multiplication algorithm by using selective bit testing instead of checking bits one by one. An AND Operation can be used with selective bit testing.

Q 54: What happen behind the screen when a character displayed on the monitor screen?             Or how the data is displayed on monitor screen?

When we press a specific number like ‘A’. It’s shifted from the keyboard to the computer. Our program read that number as the character ‘A’. When the same method repeated, the Video Graphics Adapter (VGA) in our computer shows the shape of character.

ASCII code of corresponding character placed at a cell in the VGA memory will cause the matching ASCII shape to be displayed on the corresponding screen location.

When 0x40 is sent to the VGA card then it will turn into pixels ‘on’ and ‘off’ in such a way that a graphic representation of ‘A’ performs on the screen.

Q 55: What does “41” represent in the instruction “mov word [es: 0], ox0741”?

The 41 is the lower byte is the ASCII code that display on top left in white color on black screen. And display A.

Q 56: Briefly define the term”de facto standard” by giving an example?

The lengthy ASCII code is just a de facto industry standard but it is not defined by an organization like the standard ASCII. ASCII has become the most common de facto standard and is used for Internet and global communication as well. For example Microsoft Word DOC, AutoCAD,  IBM Personal Computer (PC) etc.

Q 57: Why do we need special instructions like LES (loads extra segment register) and LDS (loads data segment register)?

LES (loads extra segment register) loads ES while LDS (loads data segment register) loads DS. These instructions have 2 parameters, 1 is the general purpose register to be loaded, and the other is the memory location from where to load these registers. The major application of these instructions is when a subroutine receives a segment offset pair as an argument and loaded in a segment.

Q 58: Describe the working of the RET with the reference of Stack.

RET (Return) transfers control back from a procedure to the instruction. RET pops the word at the top of the stack. The word at the top of stack is popped into the CS register,

Q 59: What is stack “n” defined with example?

Stack is a data structure that behaves like a LIFO manner. It contains many elements and there is only one way for in and out of the container. When an element is inserted it place on top of all other elements and when an element is removed then the top element is removed first. For example,

Consider a test tube and put some balls in it. The second ball will come above the first and the third will come above the second. When a ball is taken out only the one at the top will be removed. The operation of placing an element on top of the stack is called pushing the element and the operation of removing an element from the top of the stack is called popping the element.

Q 60: Define address bus?

The group of bits that the processor uses to inform the memory about which element read or write is known as the address bus. Another important bus called the data bus is used to move the data from the memory to processor. The address bus is unidirectional and address continuously journeys from processor to memory.

Data moves from both, processor to memory and memory to processor, so the data bus is bidirectional.

Q 61: Explain the working of shift logical left SHL?

The shift logical left operation is the exact opposite of shift logical right. In this operation the zero bits inserted from the right and every bit moves one position to its left with the most significant bit dropping into the carry flag.

Shift arithmetic left is just another name for shift logical left.

Q 62: Write any two control instructions.

The instruction pointer and instructions run are two control instructions. These are instructions that control the program execution.

Q 63: RET instruction take how many arguments?                                             

No arguments are taken by RET and also it transfers control back to the instruction.

Q 64: Write down the names of four segment registers?

CS code Segment

DS data Segment

ES Extra Segment

SS Stack Segment

Q 65: What is direct addressing"?

Direct addressing: A fixed offset is given in brackets and the memory is accessed to that offset.

Q 66: What is conditional jump"?

Conditional jump is the chief instruction, because it gives the processor decision making capability.

Q 67: Data clear algorithm in assembly language code?

; clear the screen

[Org 0x0100]

Mov ax, 0xb800; load video base in ax

Mov es, ax; point es to video base

Mov di, 0; shift di to top left column

Nextchar: mov word [es: di], 0x0720; clear next character on the screen

Add di, 2; shift to next screen position

Cmp di, 4000; has the whole screen cleared

Jne nextchar; if no clear next position

Mov ax, 0x4c00; terminate program

Int 0x21

Q 68: What is ‘Multiplication’ in assembly language?

MUL (multiply) performs an unsigned multiplication of the source operand and the accumulator. If the source operand is a ‘byte’, at that point it is multiplied by register AL and the double length result is returned in AH and AL. In that case if the source operand is a ‘word’, then it is multiplied by register AX, and the double length result is returned in registers DX and AX.

Q 69: Fill in the Blanks of Given Questions.                                                       

1. Stack is a _ data structure _____

2. Standard ASCII has 128 characters

3. Which bit is referring to the red component of foreground color? (2bit)

    Which bit is referring to the red component of background color? (6bit)

4. When a 32 bit number is divided by a 16 bit number, the quotient is of (16 bit)

5. There are just 5 block processing instructions in 8088.

6. after the execution of instruction “RET 2” increment or decrement.

Q 70: Write down the purpose of “define byte”?

To state a part of our program as ‘holding data’ as an alternative of instructions then we need a pair of elementary but special assembler directives. The first directive is “define byte” written as “db.”


Q 71: Write down the purpose of FAR Jump?

Sometimes we may need to go from one code segment to another, and near and short jumps not available. Far jump must be used for that purpose and a 2 byte segment and a 2 byte offset are given to it.

Q 72: How the value of stack pointer (sp) changes after every PUSH or POP instruction?

PUSH decrements SP (the stack pointer) by two and then transfers a word from the source operand to the top of stack. POP increments SP (the stack pointer) by two and then transfers a word from destination operand to the current top of stack.

Q 73: Explain AND, OR and XOR operations with truth tables.                      

“AND” operation

AND performs the logical bitwise and of the two operands (byte or word) and returns the result to the destination operand.

“OR” operation

OR operation executes the logical bitwise “inclusive or” of the 2 operands (byte or word) and returns the result to the destination operand.

“XOR” operation

XOR (Exclusive or) performs the logical bitwise “exclusive or” of the two operands and returns the result to the destination operand.

Q 74: Why we need to clear the stack?

“Clear the stack” is performed when there are many calls to a subroutine then it repeated many times.

Q 75: Which two registers are changed during CALL statement execution?

1. IP only

2. IP and SP only

3. SP only

4. BP and IP only

Answer: IP and SP only.

Q 76: Which instruction is used to determine the zero byte in string?

SCASB used with REPNE and a zero in AL to find a 0 byte in the string.

Q 77: The second byte in the word designated for one screen location holds the foreground and background colors for the character. Which colors are represented by 0th, 1st and 2nd bits (from least significant side)?

7 – Blinking of focus character

6 – Red section of background color

5 – Green section of background color

4 – Blue section of background color                                                                           

3 – Intensity section of focus color

2 – Red section of focus color

1 – Green section of focus color

0 – Blue section of focus color 

Q 78: One character store in one word in memory what is store in its upper byte and lower byte.

Upper byte (attributes) Lower byte (character code) 

Q 79: In which situation branching technique used in INTEL architecture, which instruction used to deliver temporary diversion and how?

The instruction for provisional change is the CALL instruction. The CALL instruction allows provisional change and therefore reusability of code. Now we can put the code for bubble sort at one place and reuse it again and again. That was not possible with permanent diversion.

Q 80: In the program HELLO WORLD desired location, what functionality is achieved from the given code lines?

Mov al, [SI]

Mov [ES: DI], ax

Add DI, 2

Add SI, 1

Answer:

Mov al, [SI]                                    ; load next character of string

Mov [ES: DI], ax                            ; display this character on the screen

Add DI, 2                                        ; transfer to next screen place

Add SI, 1                                        ; transfer to next character in string

Q 81: Which 2 instructions are used to checked that specific bits are set or not? How these 2 instructions are vary from each other?

“AND instruction” can be used to checked whether specific bits of a number are set or not.

 “Shifting and JC” used to checked bits one by one. The “AND operation” abolishes the destination mask.

Q 82: Briefly explain how string instruction work on data?

String instructions work on a block of data that has a start and an end. The instructions can work from the start to the end and then from the end towards the start. In fact they can work in both directions; only string instructions allow moving data from memory to memory.

Q 83: Which instructions are used to call a subroutine?

Both CALL and RET instructions are used to call a subroutine.

Q 84: How 16-bit DIV operation different from 32-bit Div operation?

DIV instruction presented in the 8088 processor and there are two forms of the DIV instruction. The 1st form divides a 32bit number in DX: AX by its 16bit operand and stores the 16bit proportion in AX and the 16bit remainder in DX.

The 2nd form divides a 16bit number in AX by its 8bit operand and stores the 8bit proportion in AL and the 8bit remainder in AH.

Q 85: What is a REP prefix? Write example.

A distinct prefix repeats the instruction in hardware that is called the REP prefix. REP repeats the string instruction CX times.

Q 86: Write any two logical bitwise operators.

“AND” operation:

AND operation does the logical bitwise “and” of the 2 operands.

“OR” operation:

OR operation executes the logical bitwise “inclusive or” of the 2 operands.

Q 87: What this instruction means? Mov [es: di], dx

Mov [es: di], dx                              ; print char on screen                                             

Q 88: Which logical operations are used to see 0 and 1 bit?

AND Operation is used to see o and 1 bit.

Q 89: How push instruction work in an assembly language program?

The PUSH instruction increases the stack pointer and stores the value of the specified byte operand inside the RAM address. By this instruction flags are not affected.

Q 91: What is the distinctive feature RET n?

RET n discarded the arguments rather than popping them.

Q 92: What is divide overflow error, mov ax, bl, DIV bl......?                                

Overflow error

If a large number is divided by a very small number it is possible that the percentage is larger than the space. In this case a stop is automatically generated and the program is usually terminated as a result a divide overflow error occur.

Mov ax

These instructions are used to move data from one place to another. These places can be registers, memory, or even inside secondary devices.

BL:

The BL and BLX instructions copy the address of the next instruction into LR.

DIV bl:

“DIV BL” has 8bit operand, therefore the indirect dividend is 16bit that would store in the AX register.

“DIV BX” takes 16bit operand therefore the indirect dividend would 32bit.

Q 93: When Z flag is set?

If the last mathematical or logical instruction has produced a 0 in its destination then the Z flag (Zero flag) is set.

Q 94: What is difference between JNA and JBE?

JNA  à    Jump if not above             ZF = 1            

JBE  Ã    Jump if below or equal     CF = 1

This jump is taken after a CMP, if the unspecified destination is smaller than or equal to the unidentified source. 

Q 95: Define Multiplication of 1101, 0101 with complete steps.

                 1101 = 13

                 0101 = 5

                 -----

                 1101

               0000x

             1101xx                                                                                                 

           0000xxx

          ------------

          1000001 = 65

Q 96: What will happen if we do not clear the stack after subroutine call?

If the stack is not cleared or is partially cleared the stack will finally become full, SP will reach 0, and thereafter coil will produce unexpected results that’s known as SO (stack overflow). Thus clearance of everything that is placed on the stack is very important.

Q 97: What is the purpose of JAE? Explain with example.

Answer:

  Instruction                          Jump Condition                                             Test

     JAE                                          Jump if Above or Equal                                       CF=0

Q 98: Write 2 other standers for computer other then ASCII.

Gray Codes, EBCDIC

Q 99: Assume that there are 4 parameters in a stack write a single instruction to clear the stack?

1: CALLAR 2: CALLEE 3: REMOVE 4: RET

Q 100: Write a code to left shift 32 bit of number in a memory label num1?

Shl bl, 1                ; shift multiplicand left

Q 101: How can we convert a two dimensional video memory into one dimensional?

For two dimensional coordinate system of the screen to the one dimensional memory, we need to multiply the row number by 80 since there are 80 columns per row and add the column number to it and again multiply by two since there are 2 bytes for each character.

Q 102: How local variables are created in the stack?

PUSH and POP instructions are used to create local variables.

Q 103: Briefly explain the working of following registers AX, BX, IP, CS. 

AX Register:

To return a value from a subroutine is to use the AX register. That is why AX is not saved and restored in the subroutine.

IP (Instruction Pointer) Register:

This is the special register containing the address of the next instruction to be executed. No mathematics or memory access can be done through this register. It is out of our direct control and is automatically used. It is dangerous and required special care.

CS Register:

The code segment register is the special registers related to the Intel segmented memory model.

1 window that is pointy to the CS register holds the currently performing code. So CS holds the zero or the base of code.

BX Register.

BX registers points to our data and we can add them using the instruction “mov ax, [bx]” without fixing the address of our data in the instructions.                                                                                                                  

Q 103: Why we use callee not caller explain.

If RET n is not accessible, stack clearing through callee is a difficult procedure. It will save the return address in a register, then eliminate the parameters, and then place back the return address.

Q 104: What are intra segment call and inter segment call?

Near calls are called intra segment calls, while far calls are called inter-segment calls. 

Q 105: Illustrate the reason of introducing string instruction in 8088?

String instructions are complex instruction that perform a number of tasks against one instruction. DI and SI are used to access memory. SI and DI are called source index and destination index because of string instructions. If DF (Direction Flag) is cleared, this is called the auto increment mode of string instruction, and if DF (Direction Flag) is set, this is called the auto decrement mode.

Q 106: Identify only two prefix which are meaningful with CMPS instruction. Justify the answer.

REPE and REPNE are two prefix that are meaningful with CMPS instruction. CMPS used with a REPE or a REPNE prefix as the blocks are same or because they are different and use zero flag. 

Q 107: Describe working of "NOT “operation?

NOT invert the bits (forms the one’s complement) of the byte or word operand known as single operand instruction not a logical operation.

“Not ax” and “not byte [mem]” are examples.

Q 108: What reasoning the default segment association of BP with SS?

The stack segment has a very critical and fine use and there is a reason default segment association of BP with SS. DS (Default segment) link with the BP register is the SS (stack segment). The reason is to preview inside the stack using the BP register and read the parameters without removing them and without touching the stack pointer.

Q 109: Show the process of applying selective bit inversion on the lower nibble of following bits 10011011?

XOR would use as a masking operation to invert selective bits. The operand should be applied with a mask of 0F in the source to invert the lower nibble 10011011. The upper nibble will hold its value and the lower nibble will be set as a result.

Q 110: Write the code to print 'B' on the screen with black back ground and white foreground?

Mov word [es: 1], 0x0742                                                                                     

Q 111: Describe the two forms of DIV instruction?

DIV instruction presented in the 8088 processor and there are two forms of the DIV instruction. The 1st form divides a 32bit number in DX: AX by its 16bit operand and stores the 16bit proportion in AX and the 16bit remainder in DX.

The 2nd form divides a 16bit number in AX by its 8bit operand and stores the 8bit proportion in AL and the 8bit remainder in AH.

Q 112: which interrupts are generated as a result of (a) dividing a number by zero (b) if the trap flag is set
INT 0, Division by zero?

It’s Mean that the proportion did not fit in the DS (destination register)

INT 1, Trap, Single step Interrupt:

This interrupt is used in debugging with the trap flag. Whenever trap flag would set, the Single Step Interrupt would generated after every instruction.

Q 113: Define legal and illegal instructions? Give reason why these are illegal instructions such as mov ax, bx “mov [num1], [num2]” mov bx, [num1].

Answer:

The assembler only keeps writing illegal instructions which the processor cannot execute that is also the difference between a syntax error and a logic error.

“mov [num1], 5” is legal instruction but the processor can’t recognize the data movement scope in this process. The variable num1 can be cured as a byte or word and also 5 can be treated as a byte or word.

Mov ax, bx these instructions are used to move data from one place to another.

“mov [num1], [num2]”  This instruction is illegal because memory to memory data movement is not acceptable.

Mov [num1+6], [num1]; ILLEGAL

However this form is illegal and not allowed on the Intel architecture.

Q 114: How Assembly language strings declare in ASCII code.

Add dl, 0x30                           ; convert digit into ASCII value
converting a digit into its ASCII representation by adding 0x30 and subtracting 0x20 from it.

Q 115: why address bus is a unidirectional bus also mention the flow of address bus.

The address bus is unidirectional and address continuously travels from processor to memory.

Because memory is a dumb device and cannot expect which element the processor need at a particular time.

Q 116: Define RET n?

There is a form of the RET instruction called “RET n” where n is a numeric argument. After performing the operation of RET, it further increments the stack pointer by this number.

Q 117: Explain the correlation between interrupt numbers and interrupt handler?

The correlation process from the interrupt number to the interrupt handler uses a table called interrupt vector table. Its location is fixed to physical memory address. Each entry of the table is four bytes.

Q 118: How video devices are viewed by processor?

The video device is seen by the processor because a memory area is containing the ASCII codes that are currently displayed on the screen and a set of I/O ports controlling things like the resolution, the cursor height, and the cursor position.

Q 119: Why interrupts are considered to be asynchronous and unpredictable?

Unpredictable means the time in which interrupt cannot be predicted, while asynchronous means that the interrupt has nothing to do with the currently executing instruction and the current state of the processor.

Q 120: Describe ASCII stander code and extended ASCII code?

ASCII stands for American Standard Code for Information Interchange. The name shows that this is a code that allows the interchange of information; All ASCII based computers use the same code.

The extended ASCII number is just a de facto industry standard but then it is not defined by an organization like the standard ASCII.

Q 121: What is the Function of ISR interrupts service routine?

The routine that performs in reaction of an INT instruction is called the interrupt service routine (ISR) or the interrupt handler.

Q 122: How many operands in ADC?                                                                 

ADC has three operands.

Q 123: Which instruction is most use in screen rolling function and how screen rolling works.

The instruction MOVS is used for Screen Scrolling. Scrolling is the process when all the lines on the screen move one or more lines towards the top and towards the bottom. REP with MOVS will operate the full processor power to organize the scrolling in less period. 

Q 124: What 32 bit word is defined?

32 bit word defines the double.

Q 125: What will be the result if 2 16bit operands multiplied?

The outcome will be 32bit.

Q 126: What we write for software int?

For software int we write INT.

Q 127: which instruction and its limitation is used to swap the values?

A new instruction XCHG has been introduced. The instruction swaps source and destination operands. It has reduced the code size by one instruction.

Q 128: Which instructions are used for insert and retrieve data from stack.

When CALL operation occur the current value of the instruction pointer is automatically saved on the stack, When the RET instruction is executed, it recovers the value of the instruction pointer from the stack.

Q 129: What does the following instruction do? Xor di, di                             

Xor di, di                 ; point di to top left column

Q 130: Explain the function of rotate left (ROL) instruction.

In the operation of (ROL) rotate left instruction, the most important bit is copied to the carry flag and is injected from the right, causing every bit move to the left position.


Q 131: What is the function of segment override prefix and what changes it brings to the opcode?

To dominate the relationship for one instruction of one of the registers BX, BP, SI or DI, we use the segment override prefix. Opcode has not altered.

Q 132: What are the different types of jumps available? Define position relative addressing.

Near Jump: We can jump anywhere within a segment by using a near jump.

Short Jump: This is the limitation of a byte in char representation. It used with segment.

Far Jump: Far capability makes intra segment control possible.

Q 133: What is purpose of DF direction flag? 

This flag tells that the current operation has to be done from bottom to top of the block (D=0) or from top to bottom of the block (D=1).

Q 134: Write instruction of following:
MOV AX 10
MOV AX 0X10 

Answer:

Mov ax, 10                        ; space used by one task

Mov ax, 0x10                    ; load all seg regs to 0x10

Q 135: Write the command to access the debugger and clarify individually portion of debugger.

The debugger displays the values of registers, flags, stack, our code and 1 or 2 areas of the system memory as data. Inside the debugger we can see that the registers before and after the CALL operation are precisely identical. The debugger provides a close vision of the processor.

Q 136: How most significant bit is affected when we execute shift logical right and shift arithmetic right instruction?

The shift logical right operation insets a 0 from the left and moves every bit one position to the right and copies the rightmost bit in the carry flag.

The operation of shift arithmetic right is to shift every bit one place to the right with a copy of the most important bit.

Q 137: How Stack data structure is helpful in assembly programming?

Stack data structure use PUSH and POP to store and recover data.

Sometimes we want to save the information existing in the registers. This information may be lost when program is run. So we save this information in Stack by using PUSH, at the end we can recover this information using POP.

Q 138: Which logical operation can be used to see whether a bit is 1 or 0?

We can use logical operation AND to see if bit is 1 or 0.

Q 139: Suppose AL contains 11001011b and CF= 1. Provide the original contents of AL after individually instructions executed. Assume the former early situations for individually part of this question.     

1.                  SHL AL,1

2.                  SHR AL,1

3.                  ROL AL,CL ;if CL comprises 2

4.                  SAR AL,CL ;if CL comprises 2

5.                  RCR AL,CL ;if CL comprises 3

Answer:

SHL AL, 1

1001011b1

SHR AL, 1

111001011

ROL AL, CL ; if CL contains 2

1001011b1

SAR AL, CL ; if CL contains 2

121001011b

RCR AL, CL ; if CL contains 3

311001011

Q 140: Following part of code belong to the program "scrolling up the screen". Write against each instruction what it does.

Mov ax, 80

Mul byte [bp+4]

Mov si, ax                                                                                                

Push si

Shl si, 1

Answer:

Mov ax, 80                       ; each line consists of 80 words, so we move to next line

Mul byte [bp+4]               ; we move 4 words in front

Mov si, ax                        ; contents of accumulator register ax are moved to source index SI

Push si                              ; a copy of contents of source index SI are moved to stack

Shl si, 1                            ; contents of source index are moved to left by 1 unit.

Q 141: Write down an assembly language program that displays zero (0) on the whole DOS screen.

.model small

.stack 100H

.data

.code

Call proc

Mov cx, 1

Mov dx, 0

L1:

Mov bx, 0

Add dx, bx

Loop L1

Endp

Q 142: Write an assembly program which shows two arrays using bubble sort method.

Mov ax, [ARR+si]

Mov dx, [ARR+di]

Start:

Mov ax, code

Mov ds, ax

Jmp start2

ARR:   dw 1,2,4,3,6,5,9

start2:

Mov ch, 0h

Q 143: Enlist the flag that will be affected by DIV instruction.                           

The CF, OF, SF, ZF, AF, and PF flags are undefined.

Q 144: Write a code for adding two 32 bit number using extends addition.

Mov edx, 0

Mov eax, 0FFFFFFFFh

Add eax, 0FFFFFFFFh

ADC edx, 0    ; EDX += CF, add "leftover" carry

Q 145: Write assembly code for sorting two arrays with bubble sort.

Mov ax, [ARR+si]

Mov dx, [ARR+di]

Start:

 Mov ax, code

 Mov ds, ax

 Jmp start2

ARR:   dw 1,2,4,3,6,5,9

start2:

 Mov ch, 0h

Q 146: Calculate the physical memory address generated by the followingsegment offset pairs.

1. 0000:6727

Physical Address = Segment x10 + Offset

Physical Address = 0000 x10 + 6727

Physical Address = 00000 + 6727

Physical Address = 6727h

2. FFFF: 4336

Physical Address = Segment x10 + Offset

Physical Address = FFFF x10 + 4336

Physical Address = FFFF0 + 4336

Physical Address = 104326h

To make 20bit physical address we have to drop the carry bit so

Physical Address = 04326h

3. AB01: FFFF

Physical Address = Segment x10 + Offset

Physical Address = AB01 x10 + FFFF

Physical Address = AB010 + FFFF

Physical Address = BB00Fh

Q 147: Replace the following invalid instructions with a single instructionthat has the same effect.

A. pop ip

Ret

B. mov ip, L5

Jmp L5

C. sub sp, 2

Mov [ss: sp], ax

Push ax

D. mov ax, [ss: sp]                                                                             

Add sp, 2

Pop ax

E. add sp, 6

Mov ip, [ss: sp-6]

Call

Q 148: Suppose we have AX = 0x123, write an assembly language instruction which clear the lowest nibble of the value placed in AX.

AND AX, 000Fh

This will clear all but the low-nibble of AX,

Q 149: Write a program which does extended multiplication between 32bit operands.

Mov eax, 12345h

Mov ebx, 1000h

Mul ebx; EDX: EAX = 0000000012345000h, CF=0

Q 150: How many BYTES will be move by each of the following block of codes? 

a) MOV cx, 384 REP movsb

b) MOV cx, 384 REP movsw

In block “A” move 384 bytes (B). In block B move 384 words (W)

Which amounts to 2 x 384 = 768 bytes

Q 151: What shifting operation we use for 16-bit multiplication by 2 and why?

See on Google or Handout.

ALSO READ: 

CS403 Subjective Solved Question Answers for Mid Term Exam




 


 

 

 

 

 


 




 

 




Post a Comment

0 Comments