SARDAR MUDDASAR ALI KHAN

Size: px
Start display at page:

Download "SARDAR MUDDASAR ALI KHAN"

Transcription

1 CS401 Computer Architecture and Assembly Language Programming SARDAR MUDDASAR ALI KHAN

2 FILE VERSION UPDATE: Table of Content (DATED: 19-MAY-2011)... ERROR! BOOKMARK NOT DEFINED. TABLE OF CONTENT... 2 INTRODUCTION TO NASM AND AFD IMPORTANT REGISTER NAMES... 7 NOTES OF CS EXAMPLE PROGRAMS FROM HANDOUT ; A PROGRAM TO ADD THREE NUMBERS USING REGISTERS ; A PROGRAM TO ADD THREE NUMBERS USING MEMORY VARIABLES ; A PROGRAM TO ADD THREE NUMBERS ACCESSED USING A SINGLE LABEL ; A PROGRAM TO ADD THREE NUMBERS ACCESSED USING A SINGLE LABEL ; A PROGRAM TO ADD THREE NUMBERS DIRECTLY IN MEMORY ; A PROGRAM TO ADD THREE NUMBERS USING BYTE VARIABLES ; A PROGRAM TO ADD THREE NUMBERS USING INDIRECT ADDRESSING ; A PROGRAM TO ADD TEN NUMBERS ; A PROGRAM TO ADD TEN NUMBERS USING REGISTER + OFFSET ADDRESSING ; A PROGRAM TO ADD TEN NUMBERS WITHOUT A SEPARATE COUNTER ; A PROGRAM TO ADD TEN NUMBERS WITHOUT A SEPARATE COUNTER ; SORTING A LIST OF TEN NUMBERS USING BUBBLE SORT ; 4BIT MULTIPLICATION ALGORITHM ; 16BIT MULTIPLICATION ; 16BIT MULTIPLICATION USING TEST FOR BIT TESTING ; BUBBLE SORT ALGORITHM AS A SUBROUTINE ; BUBBLE SORT SUBROUTINE CALLED TWICE ; BUBBLE SORT SUBROUTINE USING SWAP SUBROUTINE ; BUBBLE SORT AND SWAP SUBROUTINES SAVING AND RESTORING REGISTERS ; BUBBLE SORT SUBROUTINE TAKING PARAMETERS FROM STACK ; BUBBLE SORT SUBROUTINE USING A LOCAL VARIABLE ; CLEAR THE SCREEN ; HELLO WORLD IN ASSEMBLY ; NUMBER PRINTING ALGORITHM ; HELLO WORLD AT DESIRED SCREEN LOCATION ; CLEAR SCREEN USING STRING INSTRUCTIONS ; HELLO WORLD PRINTING WITH A NULL TERMINATED STRING ; HELLO WORLD PRINTING WITH LENGTH CALCULATION SUBROUTINE ; SCROLL UP THE SCREEN ; SCROLL DOWN THE SCREEN ; COMPARING NULL TERMINATED STRINGS ; HOOKING DIVIDE BY ZERO INTERRUPT ; PRINT STRING USING BIOS SERVICE ; PRINT STRING AND KEYBOARD WAIT USING BIOS SERVICES FAQ OF CS401(LATEST UPDATED) QUESTION: WHAT IS COMPUTER ARCHITECTURE QUESTION: EXPLAIN SEGMENT OVERRIDE PREFIX QUESTION: WHAT IS OFFSET? QUESTION: WHAT IS SUBROUTINE? QUESTION: EXPLAIN SEGMENTED MEMORY MODEL QUESTION: WHAT IS ADDRESS WRAPAROUND? QUESTION: EXPLAIN LINEAR MEMORY MODEL

3 QUESTION: WHAT'S THE DIFFERENCE BETWEEN.COM AND.EXE FORMATS? QUESTION: IS MS-DOS DEAD? QUESTION: HOW CAN I READ A CHARACTER WITHOUT ECHOING IT TO THE SCREEN, AND WITHOUT WAITING FOR THE USER TO PRESS THE ENTER KEY? QUESTION: WHAT IS NASM? QUESTION: WHAT IS DIFFERENCE B/W ASSEMBLER AND DISASSEMBLER? QUESTION: WHAT ARE THE FUNCTIONS OF PARITY AND SIGN FLAG? QUESTION: WHAT IS MACHINE LANGUAGE? QUESTION: WHEN TO USE ASSEMBLY LANGUAGE QUESTION: WHAT ARE INTERRUPTS? QUESTION: WHAT ARE REGISTERS? QUESTION: WHAT IS CONTROL BUS AND WHAT FUNCTION IT PERFORMS? QUESTION: WHAT DO YOU MEAN BY PERIPHERL DEVICES? QUESTION: WHAT IS DIFFERENCE B/W PHYSICAL AND LOGICAL ADDRESS? QUESTION: WHAT IS DIFFERENCE BETWEEN DATA LABEL AND CODE LABEL? QUESTION: WHAT IS SEGMENT WRAP AROUND? QUESTION: WHAT IS BIOS AND HOW IT CAN BE UPDATED? QUESTION: WHAT BIOS DOES? QUESTION: WHAT IS INTERRUPT VECTOR TABLE? QUESTION: WHAT ARE THE TERMS ASCII CODE AND SCAN CODE? QUESTION: WHAT IS VIRTUAL MACHINE? QUESTION: WHAT ARE REGISTERS AND WHY THESE ARE NEEDED? QUESTION: WHAT IS BIG-ENDIAN AND LITTLE-ENDIAN? QUESTION: HOW WE CALCULATE PHYSICAL ADDRESS? QUESTION: WHAT IS A STACK? GLOSSARY UPDATED VERSION ABSOLUTE ADDRESS: PAST SOLVED ASSIGNMENTS QUESTIONS Q1) DIFFERENTIATE BETWEEN REGISTER AND MEMORY LOCATION (4) Q2) COMMANDS TO VIEW DATA IN MEMORY WINDOW 1 & 2: Q3) CODE TO SWAP TWO NUMBERS: Q4) EXPLAIN THE INSTRUCTIONS WITH EXAMPLE Q6) WHICH INSTRUCTIONS ARE LEGAL. IF ILLEGAL CORRECT THEM Q7) CALCULATING PHYSICAL ADDRESS HOW THESE INSTRUCTIONS ARE LEGAL OR ILLEGAL. IF ILLEGAL TELL THE REASON AND HOW WE CAN MAKE THIS LEGAL, CALCULATE THE EFFECTIVE ADDRESS AND THE PHYSICAL ADDRESS ACCESSED BY EACH OF THE FOLLOWING INSTRUCTIONS. ALSO GIVE THE VALUE OF THE DESIGNATED REGISTER IN EACH INSTRUCTION BY LOOKING UP THE DUMP OF A PORTION OF PHYSICAL MEMORY GIVEN BELOW ALL QUESTIONS ARE INDEPENDENT OF EACH OTHER. ASSUME THE REGISTERS ARE INITIALIZED AS QUESTION # 1. WHAT IS WRONG WITH FOLLOWING INSTRUCTIONS? QUESTION # 2 WHAT IS THE EFFECTIVE ADDRESS GENERATED BY THE FOLLOWING COMBINATIONS IF THEY ARE VALID. INITIALLY BX= 0X0200, SI= 0X0020, DI= 0X0002, BP= 0X400 AND SP= 0XFFFF? BX + BP IF AX=0X8000 AND BX=0X0001 AND CMP AX, BX IS EXECUTED, WHICH OF THE FOLLOWING JUMPS WILL BE TAKEN? EACH PART IS INDEPENDENT OF OTHERS. ALSO GIVE THE VALUE OF Z, S, AND C FLAGS WRITE A PROGRAM IN ASSEMBLY LANGUAGE TO FIND THE MAXIMUM NUMBER AND THE MINIMUM NUMBER FROM AN ARRAY OF TEN NUMBERS SUPPOSE AL CONTAINS B AND CF= 0. GIVE THE NEW CONTENTS OF AL AFTER EACH OF THE FOLLOWING INSTRUCTIONS IS EXECUTED. ASSUME THE PRECEDING INITIAL CONDITIONS FOR EACH PART OF THIS QUESTION Q#1 AX CONTAINS A NUMBER BETWEEN WRITE CODE TO COMPLEMENT THE CORRESPONDING BIT IN BX. FOR EXAMPLE IF AX CONTAINS 6; COMPLEMENT THE 6TH BIT OF BX. (NOTE: FIRST BIT IN BX IS AT 0TH POSITION AND LAST BIT IS AT 15TH POSITION) Q#2 SUPPOSE THAT AX=0X3412, BX=0X7856, CX= 0X1CAB, AND SP=0X100. GIVEN THE CONTENTS OF AX, BX, CX, AND SP AFTER EXECUTING THE FOLLOWING INSTRUCTIONS:... 47

4 IDENTIFY THE PROBLEMS IN THE FOLLOWING INSTRUCTIONS AND CORRECT THEM BY REPLACING THEM WITH ONE OR TWO INSTRUCTION HAVING THE SAME EFFECT WRITE A PROGRAM TO CALCULATE THE SQUARE OF 10 BY USING A LOOP THAT ADDS 10 TO THE ACCUMULATOR 10 TIMES IF AX=8FFF AND BX=0FFF AND CMP AX, BX IS EXECUTED, WHICH OF THE FOLLOWING JUMPS WILL BE TAKEN? EACH PART IS INDEPENDENT OF OTHERS. ALSO GIVE THE VALUE OF Z, S, AND C FLAGS WRITE A PROGRAM TO SWAP EVERY PAIR OF BITS IN THE AX REGISTER CALCULATE THE PHYSICAL MEMORY ADDRESS GENERATED BY THE FOLLOWING SEGMENT OFFSET PAIRS A. IDENTIFY THE PROBLEMS IN THE FOLLOWING INSTRUCTIONS AND CORRECT THEM BY REPLACING THEM WITH ONE OR TWO INSTRUCTION HAVING THE SAME EFFECT A. WRITE A PROGRAM IN ASSEMBLY LANGUAGE THAT CALCULATE THE FACTORIAL OF A NUMBER WHERE FACTORIAL IS DEFINED AS: B. IF AX=8FFF AND BX=0FFF AND CMP AX, BX IS EXECUTED, WHICH OF THE FOLLOWING JUMPS WILL BE TAKEN? EACH PART IS INDEPENDENT OF OTHERS. ALSO GIVE THE VALUE OF Z, S, AND C FLAGS WRITE A SEQUENCE OF INSTRUCTION TO DO EACH OF THE FOLLOWING: A. PUT THE SUM IN AX B. PUT THE SUM IN AX SPRING 2011 LATEST PAPERS (CURRENT) PAPER NO Which flag affected by often AND operator Explain divide overflow error for what purpose "INT4" is reserved Double working of Exchange instruction with help of an example What is the difference between LES and LDS intruction PAPER NO Two form of String Moves Instruction? Describe push & pop with help of example? Describe the working of the CALL instruction with the reference of Stack Describe the working of the RET with the reference of Stack Q3: what is stack n define with example? How value of IP Register is saved & updated when call. instruction executed AX = 0x3412, BX=0x7856, CX= 0x1CAB, Sp=0x How many parameter a subroutine can receive through stack PAPER NO MID-TERM PAST PAPERS (UPDATED VERSION) SHORT QUESTION PAPER (SET-1) Q What is difference between SHR and SAR instructions? The bit Shift Logical Right (SHR) Shift Arithmetic Right (SAR) Q Every charcther is displayed on the screen in the form of word. What each byte of this word represents? 2marks Q When the instruction push ax is excuted in decrement stack how the value of SP will change? Or Operation of PUSH..Marks Q Define address bus? 5 marks Q Explain the working of shift logical left SHL? 5 marks SHORT QUESTION PAPER (SET-2) Write any two control instructions RET instruction take how many arguments Explain the fuction of rotate right (ROR) instruction Write down the names of four segment registers? Given that [BX+0x0100] BX=0x SHORT QUESTION PAPER (SET-3) What are the instructions used by assembly language for permanent and temporary diversions Which instruction is used to determine zero bit in string Explain the use of TEST instruction

5 Describe local variables Describe MOVS and CMPS instructions SHORT QUESTION PAPER (SET-4) What is direct addressing"? What is conditional jump"? How are strings handled"? Differentiate between SHR, SAL, SAR" Write a calculator for adding strings" SHORT QUESTION PAPER (SET-5) Q:1 data clear algorithum in assmly language code? 5 MARKS Q4: multiplication in assmbley language 5 marks SHORT QUESTION PAPER (SET-6) For what purpose "INT 1" is reserved? Define implied operand? Tell the Formula to scroll up the screen Explain the process of ADC? SHORT QUESTION PAPER (SET-7) Explain the fuction of rotate right (ROR) instruction Why REP prefix is generally not used with LODS instruction? Write all steps of algorithm for printing number What are the result after performing the instruction (each carry 1 marks ) Explain the complete operation of Interrupt when it is generated SHORT QUESTION PAPER (SET-8) Why is it necessary to provide the segment and offset address in case of FAR jump? What s your understanding about Incrementing and Decrementing Stack? IF DF=0 what its represent and IF DF=1 what its represent? What is the Difference between CALL and RET Explain how extended shifting is performed Write a subroutine to calculate the string length.? SHORT QUESTION PAPER (SET-9) Define short jump SHORT QUESTION PAPER (SET-11) SHORT QUESTION PAPER (SET-15) How two dimensional coordinate system of the screen is converted into the one dimensional memory? Write down the purpose of FAR Jump How the value of stack pointer (sp) changes after every PUSH or POP instruction? SHORT QUESTION PAPER (SET-17) Explain AND, OR and XOR operations with truth tables. [ 5 marks ] Explain the complete operation of interrupt when it is generated. [ 5 marks ] Tell the formula to scroll up the screen. [ 3 marks ] Why we need to clear the stack? [ 3 marks ] SHORT QUESTION PAPER (SET-18) Which instruction is used to determine the zero byte in string? (2) 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) How the data is displayed on monitor screen? (5) Write an assembly language program that clear the screen using the string instruction? clear screen using string instructions SHORT QUESTION PAPER (SET-19) MCQZ LECTURE WISE SOLVED MCQZ MCQZ (SET-1) MCQZ (SET-2) MCQZ (SET-3) MCQZ (SET-4)

6 MCQZ (SET-5) MCQZ (SET-6) MCQZ (SET-7) MCQZ (SET-8) MCQZ (SET-9) MCQZ (SET-10) MCQZ (SET-11) MCQZ (SET-12) MCQZ (SET-13) MCQZ (SET-14) MCQZ (SET-14) MCQZ (SET-15) MCQZ (SET-16) MCQZ (SET-17) MCQZ (SET-18) MCQZ (SET-19) MCQZ (SET-20) MCQZ (SET-21) MCQZ (SET-22) MCQZ UNSOLVED (SET-15) Lecture Wise MCQs =========================================================>======= ====================================================================================== Introduction To NASM and AFD. Firstly Install the NASM, & AFD in hard Drive (Just Copy and Paste)Let us just say in D Drive. Open windows RUN box and Type cmd. Command Prompt will open. Open D: Drive and then go to NASM folder by typing CD NASM. CD=Change Directory Type Edit and Edit Menu of Command Prompt will appear. Write your Assembly Language Code. Press Alt to open File Menu. Select Save option and provide a suitable name to the file. And Finally save the file with the extension.asm (For assembly Language Files). Now we have to convert this.asm file into.com, and this will be performed by the nasm. For this operation, type this command. >nasm (input_file_name).asm o (output_name).com l (output_name).lst Remember () are for just reference.do not add them to the file name.if have file name ex01.asm then use (file_name)=ex01.asm do not type this (file_name)=(ex01).asm In case of successful conversion, no error message will appear. But if there is some error message, please recheck your code by typing this code in command prompt. Edit (input_file_name).asm (A Blue window will appear where you can examine your code) Now you have compilled your program,move to next step which we will launch the program in ADF (Advance Full Screen Debugger) where we will execute each statement of our code and will check different changing values of different registers, and Data values in data windows. A snapshot of the AFD is given Below.

7 Lest us discuss some important things (Terminology) for correct code writing. Try to remember this, Important Register Names OpCode =Operation Code Just this one number tells it that it has to add, where its operands are, and where to store the result. This number is called the opcode. The opcode BB is for moving a constant into the BX register, AX=Accumulator Register ( BX= Base Register ( CX= Counter Register (as there are certain instructions that work with an automatic count) DX = Destination Register SI= Source Index These are the index registers of the Intel architecture which hold address of data and used in memory access. DI= Destination Index These are the index registers of the Intel architecture which hold address of data and used in memory access. SP = Stack Pointer It is a memory pointer and is used indirectly by a set of instructions. BP = Base Pointer CS= Code Segment DS= Data Segment ES= Extra Segment SS=Stack Segment IP = Instruction Pointer This is the special register containing the address of the next instruction to be executed. HS= No Found FS= Not Found Flag Registers C Flag =Carry Flag P Flag = Parity Flag A Flag = Auxiliary Carry Z Flag = Zero Flag S Flag = Sign Flag T Flag = Trap Flag I Flag = Interrupt Flag D Flag = Direction Flag O Flag = Over Flow Flag Notes of CS401 Op-Code: An op-code (operation code) is the portion of a machine language instruction that specifies the operation to be performed. For every specific operation like add subtract or

8 multiplication there is an op-code which processor understands. Like add we have 152 and subtract 153. Program Counter/ Instruction Pointer: A Program is an ordered set of instructions. Instruction executes one after the other. Program Counter / Instruction Pointer ensure that instructions are working in order also Program counter/instruction Pointer holds the address of the next instruction to be executed. Control Bus: It s the part of computer Bus. CPU communicates with other devices within the computer through control bus. Through control bus CPU assign different jobs to other parts (registers, memory, input output) to perform some functionality on data. For Example Read data from memor Write data on memory Move data in register. Control Lines: As CPU have to perform more than one control operations so control bus consist of more than one lines called control lines. The number and type of lines in a control bus varies but there are basic lines common to all microprocessors, Read Write Offset A distance from a given paragraph boundary in memory. The offset usually is given as a number of bytes. Segment Registers: In certain processors memory is segmented (or divided).its actually not physically segmented rather logically to store code, data, stack etc in different portions of memory. So there should be some way to specify the starting address of each such segment. That s way registers are used called segment registers. There are four types of these registers CS: Code Segment DS: Data Segment SS: Stack Segment ES: Extra Segment CS contains the segment of the current instruction (IP is the offset). DS is the segment used by default for most data operations or most memory references come from data segment. SS contains the stack segment (SP is the offset). ES as name shows extra segment register. String instructions(movs,stos) also use this register. Logical Address and Physical Address: The segment, offset pair is called a logical address, while the 20bit address is a physical address which is the real thing. Logical addressing is a mechanism to access the physical memory. Offset: A distance from a given paragraph boundary in memory. The offset usually is given as a number of bytes

9 Word is unit of data, like (bit -1, nibble -4, byte-8, word-16, Dword-32, Qword-64) A word is of 2 bytes = 16bits Dword = 4 bytes Qword= 8 bytes Registers are like Scratch Pad Ram.What are the meaning of scratch pad ram. Scratchpad means a high-speed internal memory used for temporary storage of preliminary information. An 8-bit register, like AH, AL, BH, BL, can only store one data element at a time. And a 16- bit register can store multiple data element e.g. one in AH and other in AL. Segment memory model or segment register is all about how processor sees the different portion of the memory. Our Program is consisting of two parts, the code and the data, and actually there is a third part called the program stack as well, but higher level languages make this invisible to us. These three logical parts of a program should appear as three distinct units in memory, but making this division is not possible in the linear memory model. The segmented memory model does allow this distinction. We divide the memory into the functional parts or windows, one is for code and other is for data. Processor sees code form the code window and data from the data window. Now if process sees the code section it cant see the data section through the same window and vice versa. At a time four window exist one is CS( Code window ) hold the base point of the code 2nd is DS(Data window) hold the base point of the data 3rd is SS(Stack segment) holds the base point of the stack segment and last one is ES(Extra segment) its use only for data movement. Size of each window is 64K but it can move in any region in 1MB size. Segment memory model is all about how processor sees the different portion of the memory. I hope you can now understand the segmented memory model. This problem is discussed in P.14 of the handouts. Just read the handout with full concentration. Here the Segment and Offset address are given which are necessary to make physical address. Both offset and segment address are 16 bit to make 20 bit we use mechanism mention below. Now as Figure Show Segment register = 1DDD it is16 bit to make 20 bit we add 0 with the end of the segment register now it become = 1DDD0 And offset 0100 which is also 16 bit now we add 0 before the offset address to make 20 bit. Offset = 0100 after append 0 before it become 00100

10 Now add both 1DDD DED0 that is 20 bit physical address. I hope now you understand how to calculate physical address. Op-code The op-code or operation code is the binary pattern that represents an instruction. Segmentation: The segmented memory model allows multiple functional windows into the main memory, a code window, a data window etc. The processor sees code from the code window and data from the data window. The size of one window is restricted to 64K. However the maximum memory iapx88 can access is 1MB which can be accessed with 20 bits. Mnemonic A word, abbreviation, or acronym that replaces something too complex to remember or type easily. For example, ADC is the mnemonic for the 8086 s add-with-carry instruction. The assembler converts it into machine (binary) code, so it is not necessary to remember or calculate the binary form. Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4F52 would be stored as 4F52 in storage (if 4F is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524F (52 at address 1000, 4F at 1001). IBM's 370 computers, most RISC-based computers, and Motorola microprocessors use the big-endian approach.on the other hand, Intel processors (CPUs) and DEC Alphas and at least some programs that run on them are little-endian. Shift Operation:In this operation, the digits are moved, or shifted, to the left or right. Registers in a computer processor have a fixed number of available bits for storing data, so during shift some bits will be "shifted out" of the register at one end, while the same number of bits are "shifted in" from the other end.shifted out bits are either discarded or preserved in Flags. Rotation:Rotate instructions are similar to shift instructions, except that rotate instructions are circular, with the bits shifted out at one end returning(re-entring) on the other end. Rotates can be to the left or right. What is CALL and RET function? In every processor, instructions are available to divert temporarily and to divert permanently. The instructions for permanent diversion in 8088 are the jump instructions, while the instruction for temporary diversion is the CALL instruction. The word call must be familiar to the readers from subroutine call in higher level languages. The CALL instruction allows temporary diversion and therefore reusability of code. For example in the bubble sort code one place and reuse it again and again. This was not possible with permanent diversion. Actually the 8088 permanent diversion mechanism can be tricked to achieve temporary diversion. CALL takes a label as argument and execution starts from the label, until the RET instruction is encountered and it takes execution back to the instruction following the CALL. Both the instructions are mostly used as a pair. But

11 they are independent CALL can be use independent of the RET and RET can also be use independent of the CALL. RET give control back to the next instruction after the CALL. Here in this subject we have studied different "Intel processor architectures. From these one of earlier architecture is Intel 8080 and other is Intel 8085.These architectures use memory modeling scheme called linear memory model or flat memory model. So A flat memory model uses a linear (or sequential) addressing scheme, allowing direct addressing of all available memory locations. Now when a processor or DMA-enabled device needs to read or write to a memory location, it specifies that memory location on the address bus (the value to be read or written is sent on the data bus). The width of the address bus determines the amount of memory a system can address. As in Intel 8080 and 8086 processor internal registers are of 16 bits that s why the maximum linear address space was limited to 64 KB. When designing iapx88 the Intel designers wanted to remain compatible with 8080 and 8085 however 64K was too small to continue with, for their new processor. To get the best of both worlds they introduced the segmented memory model in There is also a logical argument in favor of a segmented memory model in addition to the issue of compatibility discussed above. We have two logical parts of our program, the code and the data and actually there is a third part called the program stack as well, but higher level languages make this invisible to us. These three logical parts of a program should appear as three distinct units in memory, but making this division is not possible in the linear memory model. The segmented memory model does allow this distinction. Intel AiAPX88 is also architecture of 16 bits processor but in order to access segmented memory it will generate the address of 20 bits as follows Address = 16*segment + offset And 20-bit external address bus gave an 1 MB (segmented) physical address space (2 20 = 1,048,576). The SCAS stand for Scan String. Basically it s a block processing instruction in Intel SCAS compares a source byte or word in register AL or AX with the destination string element addressed by ES:DI and updates the flags. DI is updated to point to the next location. SCAS is often used to locate equality or in-equality in a string through the use of an appropriate prefix. SCAS is a bit different from the other instructions. This is more like the CMP instruction in that it does subtraction of its operands. The prefixes REPE (repeat while equal) and REPNE (repeat while not equal) are used with this instruction. The instruction is used to locate a byte in AL in the block of memory. When the first equality or inequality is encountered; both have uses. For example this instruction can be used to search for a 0 in a null terminated string to calculate the length of the string. In this form REPNE will be used to repeat while the null is not there. LES and LDS Instructions

12 As Mention in the lecture that the string instructions need their source and destination in the form of a segment offset pair, there are two special instructions that load a segment register and a general purpose register from two consecutive memory locations. LES loads ES while LDS loads DS. These instructions have two parameters, one is the general purpose register to be loaded and the other is the memory location from which to load these registers. According to Intel rules of significance the word at higher address is loaded in the segment register while the word at lower address is loaded in the offset register. As parameters segment should be pushed first so that it ends up at a higher address and the offset should be pushed afterwards. When loading the lower address will be given. far jump is one that uses the full segment base: offset value as an absolute address. In far jump in addition to the simple jump operations, there are the call (call a subroutine) and ret (return from subroutine) instructions. Before transferring control to the subroutine, call pushes the segment offset address of the instruction following the call onto the stack; ret pops this value off the stack, and jumps to it, effectively returning the flow of control to that part of the program. In the case of a far call, the segment base is pushed following the offset; far ret pops the offset and then the segment base to return from that subroutine. So from above explanation you can understand that the example of far jump is calling a subroutine and then retuning from that. There are three types of unconditional jumps Short jumps Near jumps Far jumps Their range calculation is as follows The short jump is 2-byte instructions allow jumps or branches to memory locations with in +127 and -128 bytes from the address following the jump. This is the limitation of a byte in singed representation. Near jump is a 3-byte instructions allow a branch or jump within ±32K bytes (or anywhere in the current segment) from the instructions in the current code segment. Finally the 5-byte far jump allows a jump to any memory location within the real memory system The short and near jumps are often called intra segment jumps and far jumps are often called inter segment jumps Signed numbers are represented in form of 2's compliment in memory and registers and these are calculated as follows fisrt take 1's compliment of a number then add "1" in that complimented number and the result will show the number in 2's compliment or signed number. Example Programs From Handout Program No.01 Example 1.1 ; a program to add three numbers using registers [org 0x0100] mov ax, 5 ; load first number in ax mov bx, 10 ; load second number in bx add ax, bx ; accumulate sum in ax mov bx, 15 ; load third number in bx add ax, bx ; accumulate sum in ax mov ax, 0x4c00 ; terminate program int 0x21

13 001 To start a comment a semicolon is used and the assembler ignores everything else on the same line. Comments must be extensively used in assembly language programs to make them readable. 002 Leave the org directive for now as it will be discussed later. 003 The constant 5 is loaded in one register AX.004 The constant 10 is loaded in another register BX.005 Register BX is added to register AX and the result is stored in register AX. Register AX should contain 15 by now.006 The constant 15 is loaded in the register BX. 007 Register BX is again added to register AX now producing 15+15=30 in the AX register. So the program has computed = Vertical spacing must also be used extensively in assembly language programs to separate logical blocks of code The ending lines are related more to the operating system than to assembly language programming. It is a way to inform DOS that our program has terminated so it can display its command prompt again. The computer may reboot or behave improperly if thistermination is not present. ========================================================= Program No.02 Example 2.1 ; a program to add three numbers using memory variables [org 0x0100] mov ax, [num1] ; load first number in ax mov bx, [num2] ; load second number in bx add ax, bx ; accumulate sum in ax mov bx, [num3] ; load third number in bx add ax, bx ; accumulate sum in ax mov [num4], ax ; store sum in num4 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5 num2: dw 10 num3: dw 15 num4: dw Originate our program at The first executable instructions should be placed at this offset.003 The source operand is changed from constant 5 to [num1]. The bracket is signaling that the operand is placed in memory at address num1. The value 5 will be loaded in ax even though we did not specified it in our program code, rather the value will be picked from memory. The instruction should be read as read the contents of memory location num1 in the ax register. The label num1 is a symbol for us but an address for the processor while the conversion is done by the assembler. 013 The label num1 is defined as a word and the assembler is requested to place 5 in that memory location. The colon signals that num1 is a label and not an instruction. ================================================================ Program No.03 Example 2.2 ; a program to add three numbers accessed using a single label [org 0x0100] mov ax, [num1] ; load first number in ax mov bx, [num1+2] ; load second number in bx add ax, bx ; accumulate sum in ax mov bx, [num1+4] ; load third number in bx add ax, bx ; accumulate sum in ax mov [num1+6], ax ; store sum at num1+6 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5 dw 10 dw 15 dw The second number is read from num1+2. Similarly the third number is read from num1+4 and the result is accessed at num The labels num2, num3, and num4 are removed and the data there will be accessed with reference to num1. ================================================================== Program No.04 Example 2.3 ; a program to add three numbers accessed using a single label [org 0x0100] mov ax, [num1] ; load first number in ax mov bx, [num1+2] ; load second number in bx add ax, bx ; accumulate sum in ax mov bx, [num1+4] ; load third number in bx add ax, bx ; accumulate sum in ax mov [num1+6], ax ; store sum at num1+6 mov ax, 0x4c00 ; terminate program

14 int 0x21 num1: dw 5, 10, 15, As we do not need to place labels on individual variables we can save space and declare all data on a single line separated by commas.this declaration will declare four words in consecutive memory locations while the address of first one is num1. ================================================================= Program No.05 Example 2.4 ; a program to add three numbers directly in memory [org 0x0100] mov ax, [num1] ; load first number in ax mov [num1+6], ax ; store first number in result mov ax, [num1+2] ; load second number in ax add [num1+6], ax ; add second number to result mov ax, [num1+4] ; load third number in ax add [num1+6], ax ; add third number to result mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5, 10, 15, 0 ============================================================ Program No.06 Example 2.5 ; a program to add three numbers using byte variables [org 0x0100] mov al, [num1] ; load first number in al mov bl, [num1+1] ; load second number in bl add al, bl ; accumulate sum in al mov bl, [num1+2] ; load third number in bl add al, bl ; accumulate sum in al mov [num1+3], al ; store sum at num1+3 mov ax, 0x4c00 ; terminate program int 0x21 num1: db 5, 10, 15, The number is read in AL register which is a byte register since the memory location read is also of byte size.005 The second number is now placed at num1+1 instead of num1+2 because of byte offsets.013 To declare data db is used instead of dw so that each data declared occupies one byte only. =========================================================================== Program No.07 Example 2.6 ; a program to add three numbers using indirect addressing [org 0x100] mov bx, num1 ; point bx to first number mov ax, [bx] ; load first number in ax add bx, 2 ; advance bx to second number add ax, [bx] ; add second number to ax add bx, 2 ; advance bx to third number add ax, [bx] ; add third number to ax add bx, 2 ; advance bx to result mov [bx], ax ; store sum at num1+6 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5, 10, 15, Observe that no square brackets around num1 are used this time. The address is loaded in bx and not the contents. Value of num1 is 0005 and the address is So BX will now contain Brackets are now used around BX. In iapx88 architecture brackets can be used around BX, BP, SI, and DI only. In iapx386 more registers are allowed. The instruction will be read as move into ax the contents of the memory location whose address is in bx. Now since bx contains the address of num1 the contents of num1 are transferred to the ax register. Without square brackets the meaning of the instruction would have been totally different.005 This instruction is changing the address. Since we have words not bytes, we add two to bx so that it points to the next word in memory.bx now contains 0119 the address of the second word in memory.this was the mechanism to change addresses that we needed. =============================================================== Program No.08 Example 2.7 ; a program to add ten numbers [org 0x0100] mov bx, num1 ; point bx to first number mov cx, 10 ; load count of numbers in cx mov ax, 0 ; initialize sum to zero

15 l1: add ax, [bx] ; add number to ax add bx, 2 ; advance bx to next number sub cx, 1 ; numbers to be added reduced jnz l1 ; if numbers remain add next mov [total], ax ; write back sum in memory mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 total: dw Labels can be used on code as well. Just like data labels they remember the address at which they are used. The assembler does not differentiate between code labels and data labels. The programmer is responsible for using a data label as data and a code label as code. The label l1 in this case is the address of the following instruction. 009 SUB is the counterpart to ADD with the same rules as that of the ADD instruction. 010 JNZ stands for jump if not zero. NZ is the condition in this instruction. So the instruction is read as jump to the location l1 if the zero flag is not set. And revisiting the zero flag definition the zero flag is set if the last mathematical or logical operation has produced a zero in its destination. For example mov ax, 0 will not set the zero flag as it is not a mathematical or logical instruction. However subtraction and addition will set it. Also it is set even when the destination is not a register. Now consider the subtraction immediately preceding it. If the CX register becomes zero as a result of this subtraction the zero flag will be set and the jump will be taken. And jump to l1, the processor needs to be told each and everything and the destination is an important part of every jump. Just like when we as someone to go, we mention go to this market or that house. The processor is much more logical than us and needs the destination in every instruction that asks it to go somewhere. The processor will load l1 in the IP register and resume execution from there. The processor will blindly go to the label we mention even if it contains data and not code. The JNZ instruction is from the program control group and is a conditional jump, meaning that if the condition NZ is true (ZF=0) it will jump to the address mentioned and otherwise it will progress to the next instruction. It is a selection between two paths. If the condition is true go right and otherwisego left. ==================================================================== Program No.09 Example 2.8 ; a program to add ten numbers using register + offset addressing [org 0x0100] mov bx, 0 ; initialize array index to zero mov cx, 10 ; load count of numbers in cx mov ax, 0 ; initialize sum to zero l1: add ax, [num1+bx] ; add number to ax add bx, 2 ; advance bx to next index sub cx, 1 ; numbers to be added reduced jnz l1 ; if numbers remain add next mov [total], ax ; write back sum in memory mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 total: dw This time BX is initialized to zero instead of array base 007 The format of memory access has changed. The array base is added to BX containing array index at the time of memory access.008 As the array is of words, BX jumps in steps of two, i.e. 0, 2, 4. Higher level languages do appropriate incrementing themselves and we always use sequential array indexes. However in assembly language we always calculate in bytes and therefore we need to take care of the size of one array element which in this case is two. ================================================================== The operation of all jumps can be seen from the following table The CMP instruction sets the flags reflecting the relation of the destination to the source. ===================================================================== Program No.10 Example 3.1 ; a program to add ten numbers without a separate counter [org 0x0100] mov bx, 0 ; initialize array index to zero mov ax, 0 ; initialize sum to zero l1: add ax, [num1+bx] ; add number to ax add bx, 2 ; advance bx to next index cmp bx, 20 ; are we beyond the last index jne l1 ; if not add next number mov [total], ax ; write back sum in memory

16 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 total: dw The format of memory access is still base + offset.008 BX is used as the array index as well as the counter. The offset of 11th number will be 20, so as soon as BX becomes 20 just after the 10th number has been added, the addition is stopped.009 The jump is displayed as JNZ in the debugger even though we have written JNE in our example. This is because it is a renamed jump with the same opcode as JNZ and the debugger has no way of knowing the mnemonic that we used after looking just at the opcode. Also every code and data reference that we used till now is seen in the opcode as well. However for the jump instruction we see an operand of F2 in the opcode and not This will be discussed in detail with unconditional jumps. It is actually a short relative jump and the operand is stored in the form of positive or negative offset from this instruction. ================================================================= Program No.11 Example 3.2 ; a program to add ten numbers without a separate counter [org 0x0100] jmp start ; unconditionally jump over data num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 total: dw 0 start: mov bx, 0 ; initialize array index to zero mov ax, 0 ; initialize sum to zero l1: add ax, [num1+bx] ; add number to ax add bx, 2 ; advance bx to next index cmp bx, 20 ; are we beyond the last index jne l1 ; if not add next number mov [total], ax ; write back sum in memory mov ax, 0x4c00 ; terminate program int 0x JMP jumps over the data declarations to the start label and execution resumes from there. ================================================================= Program No.12 Example 3.3 ; sorting a list of ten numbers using bubble sort [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 swap: db 0 start: mov bx, 0 ; initialize array index to zero mov byte [swap], 0 ; rest swap flag to no swaps loop1: mov ax, [data+bx] ; load number in ax cmp ax, [data+bx+2] ; compare with next number jbe noswap ; no swap if already in order mov dx, [data+bx+2] ; load second element in dx mov [data+bx+2], ax ; store first number in second mov [data+bx], dx ; store second number in first mov byte [swap], 1 ; flag that a swap has been done noswap: add bx, 2 ; advance bx to next index cmp bx, 18 ; are we at last index jne loop1 ; if not compare next two cmp byte [swap], 1 ; check if a swap has been done je start ; if yes make another pass mov ax, 0x4c00 ; terminate program int 0x The jump instruction is placed to skip over data. 006 The swap flag can be stored in a register but as an example it is stored in memory and also to extend the concept at a later stage One element is read in AX and it is compared with the next element because memory to memory comparisons are not allowed. 013 If the JBE is changed to JB, not only the unnecessary swap on equal will be performed, there will be a major algorithmic flaw due to a logical error as in the case of equal elements the algorithm will never stop. JBE won t swap in the case of equal elements The swap is done using DX and AX registers in such a way that the values are crossed. The code uses the information that one of the elements is already in the AX register. 021 This time BX is compared with 18 instead of 20 even though the number of elements is same. This is because we pick an element and compare it with the next element. When we pick the 9th element we compare it with the next element and this is the last comparison, since if we pick the 10th element we will compare it with the 11 th element and there is no 11th element in our case If a swap is done we repeat the whole process for possible more swaps.

17 =============================================================== Program No.13 Example 4.1 ; 4bit multiplication algorithm [org 0x100] jmp start multiplicand: db 13 ; 4bit multiplicand (8bit space) multiplier: db 5 ; 4bit multiplier result: db 0 ; 8bit result start: mov cl, 4 ; initialize bit count to four mov bl, [multiplicand] ; load multiplicand in bl mov dl, [multiplier] ; load multiplier in dl checkbit: shr dl, 1 ; move right most bit in carry jnc skip ; skip addition if bit is zero add [result], bl ; accumulate result skip: shl bl, 1 ; shift multiplicand left dec cl ; decrement bit count jnz checkbit ; repeat if bits left mov ax, 0x4c00 ; terminate program int 0x21 The numbers to be multiplied are constants for now. The multiplication is four bit so the answer is stored in an 8bit register. If the operands were 8bit the answer would be 16bit and if the operands were 16bit the answer would be 32bit. Since eight bits can fit in a byte we have used 4bit multiplication as our first example. Since addition by zero means nothing we skip the addition step if the rightmost bit of the multiplier is zero. If the jump is not taken the shifted value of the multiplicand is added to the result.the multiplicand is left shifted in every iteration regardless of the multiplier bit.dec is a new instruction but its operation should be immediately understandable with the knowledge gained till now. It simply subtracts one from its single operand. The JNZ instruction causes the algorithm to repeat till any bits of the multiplier are left ================================================================= Program No.14 Example 4.2 ; 16bit multiplication [org 0x0100] jmp start multiplicand: dd 1300 ; 16bit multiplicand 32bit space multiplier: dw 500 ; 16bit multiplier result: dd 0 ; 32bit result start: mov cl, 16 ; initialize bit count to 16 mov dx, [multiplier] ; load multiplier in dx checkbit: shr dx, 1 ; move right most bit in carry jnc skip ; skip addition if bit is zero mov ax, [multiplicand] add [result], ax ; add less significant word mov ax, [multiplicand+2] adc [result+2], ax ; add more significant word skip: shl word [multiplicand], 1 rcl word [multiplicand+2], 1 ; shift multiplicand left dec cl ; decrement bit count jnz checkbit ; repeat if bits left mov ax, 0x4c00 ; terminate program int 0x The multiplicand and the multiplier are stored in 32bit space while the multiplier is stored as a word.the multiplier is loaded in DX where it will be shifted bit by bit. It can be directly shifted in memory as well.the multiplicand is added to the result using extended 32bit addition.the multiplicand is shifted left as a 32bit number using extended shifting operation. ================================================================ Program No.15 Example 4.3 ; 16bit multiplication using test for bit testing [org 0x0100] jmp start multiplicand: dd 1300 ; 16bit multiplicand 32bit space multiplier: dw 500 ; 16bit multiplier result: dd 0 ; 32bit result start: mov cl, 16 ; initialize bit count to 16

18 mov bx, 1 ; initialize bit mask checkbit: test bx, [multiplier] ; move right most bit in carry jz skip ; skip addition if bit is zero mov ax, [multiplicand] add [result], ax ; add less significant word mov ax, [multiplicand+2] adc [result+2], ax ; add more significant word skip: shl word [multiplicand], 1 rcl word [multiplicand+2], 1 ; shift multiplicand left shl bx, 1 ; shift mask towards next bit dec cl ; decrement bit count jnz checkbit ; repeat if bits left mov ax, 0x4c00 ; terminate program int 0x 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. We can do without counting in this example. We can stop as soon as our mask in BX becomes zero. These are the small tricks that assembly allows us to do and optimize our code as a result. ================================================================== Program No.16 Example 5.1 ; bubble sort algorithm as a subroutine [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 swap: db 0 bubblesort: dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero mov byte [swap], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order mov dx, [bx+si+2] ; load second element in dx mov [bx+si], dx ; store first number in second mov [bx+si+2], ax ; store second number in first mov byte [swap], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp byte [swap], 1 ; check if a swap has been done je mainloop ; if yes make another pass ret ; go back to where we came from start: mov bx, data ; send start of array in bx mov cx, 10 ; send count of elements in cx call bubblesort ; call our subroutine mov ax, 0x4c00 ; terminate program int 0x The routine has received the count of elements in CX. Since it makes one less comparison than the number of elements it decrements it. Then it multiplies it by two since this a word array and each element takes two bytes. Left shifting has been used to multiply by two. Base+index+offset addressing has been used. BX holds the start of array, SI the offset into it and an offset of 2 when the next element is to be read. BX can be directly changed but then a separate counter would be needed, as SI is directly compared with CX in our case. The code starting from the start label is our main program analogous to the main in the C language. BX and CX hold our parameters for the bubblesort subroutine and the CALL is made to invoke the subroutine. ============================================================== Program No.17 Example 5.2 ; bubble sort subroutine called twice [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98 dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5

19 swap: db 0 bubblesort: dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero mov byte [swap], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order mov dx, [bx+si+2] ; load second element in dx mov [bx+si], dx ; store first number in second mov [bx+si+2], ax ; store second number in first mov byte [swap], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp byte [swap], 1 ; check if a swap has been done je mainloop ; if yes make another pass ret ; go back to where we came from start: mov bx, data ; send start of array in bx mov cx, 10 ; send count of elements in cx call bubblesort ; call our subroutine mov bx, data2 ; send start of array in bx mov cx, 20 ; send count of elements in cx call bubblesort ; call our subroutine again mov ax, 0x4c00 ; terminate program int 0x There are two different data arrays declared. One of 10 elements and the other of 20 elements. The second array is declared on two lines,where the second line is continuation of the first. No additional label is needed since they are situated consecutively in memory. The other change is in the main where the bubblesort subroutine is called twice, once on the first array and once on the second. ======================================================================== Program No.18 Example 5.3 ; bubble sort subroutine using swap subroutine [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98 dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5 swapflag: db 0 swap: mov ax, [bx+si] ; load first number in ax xchg ax, [bx+si+2] ; exchange with second number mov [bx+si], ax ; store second number in first ret ; go back to where we came from bubblesort: dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero mov byte [swapflag], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order call swap ; swaps two elements mov byte [swapflag], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp byte [swapflag], 1 ; check if a swap has been done je mainloop ; if yes make another pass ret ; go back to where we came from start: mov bx, data ; send start of array in bx mov cx, 10 ; send count of elements in cx call bubblesort ; call our subroutine mov bx, data2 ; send start of array in bx mov cx, 20 ; send count of elements in cx call bubblesort ; call our subroutine again

20 mov ax, 0x4c00 ; terminate program int 0x21 A new instruction XCHG has been introduced. The instruction swaps its source and its destination operands however at most one of the operands could be in memory, so the other has to be loaded in a register. The instruction has reduced the code size by one instruction. The RET at the end of swap makes it a subroutine. ===============================================================, Program No.19 Example 5.4 ; bubble sort and swap subroutines saving and restoring registers [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98 dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5 swapflag: db 0 swap: push ax ; save old value of ax mov ax, [bx+si] ; load first number in ax xchg ax, [bx+si+2] ; exchange with second number mov [bx+si], ax ; store second number in first pop ax ; restore old value of ax ret ; go back to where we came from bubblesort: push ax ; save old value of ax push cx ; save old value of cx push si ; save old value of si dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero mov byte [swapflag], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order call swap ; swaps two elements mov byte [swapflag], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp byte [swapflag], 1 ; check if a swap has been done je mainloop ; if yes make another pass pop si ; restore old value of si pop cx ; restore old value of cx pop ax ; restore old value of ax ret ; go back to where we came from start: mov bx, data ; send start of array in bx mov cx, 10 ; send count of elements in cx call bubblesort ; call our subroutine mov bx, data2 ; send start of array in bx mov cx, 20 ; send count of elements in cx call bubblesort ; call our subroutine again mov ax, 0x4c00 ; terminate program int 0x When multiple registers are pushed, order is very important. If AX,CX, and SI are pushed in this order, they must be popped in the reverse order of SI, CX, and AX. This is again because the stack behaves in a Last In First Out manner. ==================================================================== Program No.20 Example 5.5 ; bubble sort subroutine taking parameters from stack [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98 dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5 swapflag: db 0 bubblesort: push bp ; save old value of bp mov bp, sp ; make bp our reference point push ax ; save old value of ax push bx ; save old value of bx

21 push cx ; save old value of cx push si ; save old value of si mov bx, [bp+6] ; load start of array in bx mov cx, [bp+4] ; load count of elements in cx dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero mov byte [swapflag], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order xchg ax, [bx+si+2] ; exchange ax with second number mov [bx+si], ax ; store second number in first mov byte [swapflag], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp byte [swapflag], 1 ; check if a swap has been done je mainloop ; if yes make another pass pop si ; restore old value of si pop cx ; restore old value of cx pop bx ; restore old value of bx pop ax ; restore old value of ax pop bp ; restore old value of bp ret 4 ; go back and remove two params start: mov ax, data push ax ; place start of array on stack mov ax, 10 push ax ; place element count on stack call bubblesort ; call our subroutine mov ax, data2 push ax ; place start of array on stack mov ax, 20 push ax ; place element count on stack call bubblesort ; call our subroutine again mov ax, 0x4c00 ; terminate program int 0x The value of the stack pointer is captured in the base pointer. With further pushes SP will change but BP will not and therefore we will read parameters from bp+4 and bp+6. The form of RET that takes an argument is used causing four to be added to SP after the return address has been popped in the instruction pointer. This will effectively discard the parameters that are still there on the stack. We push the address of the array we want to sort followed by the count of elements. As immediate cannot be directly pushed in the 8088 architecture, we first load it in the AX register and then push the AX register on the stack. ================================================================= Program No.21 Example 5.6 ; bubble sort subroutine using a local variable [org 0x0100] jmp start data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98 dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5 bubblesort: push bp ; save old value of bp mov bp, sp ; make bp our reference point sub sp, 2 ; make two byte space on stack push ax ; save old value of ax push bx ; save old value of bx push cx ; save old value of cx push si ; save old value of si mov bx, [bp+6] ; load start of array in bx mov cx, [bp+4] ; load count of elements in cx dec cx ; last element not compared shl cx, 1 ; turn into byte count mainloop: mov si, 0 ; initialize array index to zero

22 mov word [bp-2], 0 ; reset swap flag to no swaps innerloop: mov ax, [bx+si] ; load number in ax cmp ax, [bx+si+2] ; compare with next number jbe noswap ; no swap if already in order xchg ax, [bx+si+2] ; exchange ax with second number mov [bx+si], ax ; store second number in first mov word [bp-2], 1 ; flag that a swap has been done noswap: add si, 2 ; advance si to next index cmp si, cx ; are we at last index jne innerloop ; if not compare next two cmp word [bp-2], 1 ; check if a swap has been done je mainloop ; if yes make another pass pop si ; restore old value of si pop cx ; restore old value of cx pop bx ; restore old value of bx pop ax ; restore old value of ax mov sp, bp ; remove space created on stack pop bp ; restore old value of bp ret 4 ; go back and remove two params start: mov ax, data push ax ; place start of array on stack mov ax, 10 push ax ; place element count on stack call bubblesort ; call our subroutine mov ax, data2 push ax ; place start of array on stack mov ax, 20 push ax ; place element count on stack call bubblesort ; call our subroutine again mov ax, 0x4c00 ; terminate program int 0x21 A word gap has been created for swap flag. This is equivalent to a dummy push. The registers are pushed above this gap. The swapflag is accessed with [bp-2]. The parameters are accessed in the same manner as the last examples. We are removing the hole that we created. The hole is removed by restoring the value of SP that it had at the time of snapshot or at the value it had before the local variable was created. This can be replaced with add sp, 2 however the one used in the code is preferred since it does not require to remember how much space for local variables was allocated in the start. After this operation SP points to the old value of BP from where we can proceed as usual. ============================================================== Program No.22 Example 6.1 ; clear the screen [org 0x0100] mov ax, 0xb800 ; load video base in ax mov es, ax ; point es to video base mov di, 0 ; point di to top left column nextchar: mov word [es:di], 0x0720 ; clear next char on screen add di, 2 ; move to next screen location cmp di, 4000 ; has the whole screen cleared jne nextchar ; if no clear next position mov ax, 0x4c00 ; terminate program int 0x The code for space is 20 while 07 is the normal attribute of low intensity white on black with no blinking. Even to clear the screen or put a blank on a location there is a numeric code. DI is incremented twice since each screen location corresponds to two byte in video memory.di is compared with 80*25*2=4000. The last word location that corresponds to the screen is =============================================================== Program No.23 Example 6.2 ; hello world in assembly [org 0x0100] jmp start message: db 'hello world' ; string to be printed length: dw 11 ; length of the string ; subroutine to clear the screen

23 clrscr: push es push ax push di mov ax, 0xb800 mov es, ax ; point es to video base mov di, 0 ; point di to top left column nextloc: mov word [es:di], 0x0720 ; clear next char on screen add di, 2 ; move to next screen location cmp di, 4000 ; has the whole screen cleared jne nextloc ; if no clear next position pop di pop ax pop es ret ; subroutine to print a string at top left of screen ; takes address of string and its length as parameters printstr: push bp mov bp, sp push es push ax push cx push si push di mov ax, 0xb800 mov es, ax ; point es to video base mov di, 0 ; point di to top left column mov si, [bp+6] ; point si to string mov cx, [bp+4] ; load length of string in cx mov ah, 0x07 ; normal attribute fixed in al nextchar: mov al, [si] ; load next char of string mov [es:di], ax ; show this char on screen add di, 2 ; move to next screen location add si, 1 ; move to next char in string loop nextchar ; repeat the operation cx times pop di pop si pop cx pop ax pop es pop bp ret 4 start: call clrscr ; call the clrscr subroutine mov ax, message push ax ; push address of message push word [length] ; push message length call printstr ; call the printstr subroutine mov ax, 0x4c00 ; terminate program int 0x The string definition syntax discussed above is used to declare a string hello world of 11 bytes and the length is stored in a separate variable.the code to clear the screen from the last example is written in the form of a subroutine. Since the subroutine had no parameters, only modified registers are saved and restored from the stack.the standard subroutine format with parameters received via stack and all registers saved and restored is used.es is initialized to point to the video memory via the AX register.two pointer registers are used; SI to point to the string and DI to point to the top left location of the screen. CX is loaded with the length of the string. Normal attribute of low intensity white on black with no blinking is loaded in the AH register.the next character from the string is loaded into AL. Now AH holds the attribute and AL the ASCII code of the character. This pair is written on the video memory using DI with the segment override prefix for ES to access the video memory segment.the string pointer is incremented by one while the video memory pointer is incremented by two since one char corresponds to a word on the screen.the loop instruction used is equivalent to a combination of dec cx and jnz nextchar. The loop is executed CX times.the registers pushed on the stack are recovered in opposite order and the ret 4 instruction removes the two parameters placed on

24 the stack.memory can be directly pushed on the stack. ================================================================ Program No.24 Example 6.3 ; number printing algorithm [org 0x0100] jmp start ;;;;; COPY LINES FROM EXAMPLE 6.2 (clrscr) ;;;;; ; subroutine to print a number at top left of screen ; takes the number to be printed as its parameter printnum: push bp mov bp, sp push es push ax push bx push cx push dx push di mov ax, 0xb800 mov es, ax ; point es to video base mov ax, [bp+4] ; load number in ax mov bx, 10 ; use base 10 for division mov cx, 0 ; initialize count of digits nextdigit: mov dx, 0 ; zero upper half of dividend div bx ; divide by 10 add dl, 0x30 ; convert digit into ascii value push dx ; save ascii value on stack inc cx ; increment count of values cmp ax, 0 ; is the quotient zero jnz nextdigit ; if no divide it again mov di, 0 ; point di to top left column nextpos: pop dx ; remove a digit from the stack mov dh, 0x07 ; use normal attribute mov [es:di], dx ; print char on screen add di, 2 ; move to next screen location loop nextpos ; repeat for all digits on stack pop di pop dx pop cx pop bx pop ax pop es pop bp ret 2 start: call clrscr ; call the clrscr subroutine mov ax, 4529 push ax ; place number on stack call printnum ; call the printnum subroutine mov ax, 0x4c00 ; terminate program int 0x The registers are saved as an essential practice. The only parameter received is the number to be printed ES is initialized to video memory. AX holds the number to be printed. BX is the desired base, and can be loaded from a parameter.cx holds the number of digits pushed on the stack. This count is initialized to zero, incremented with every digit pushed and is used when the digits are popped one by one DX must be zeroed as our dividend is in AX and we want a 32bit division. After the division AX holds the quotient and DX holds the remainder. Actually the remainder is only in DL since the remainder can be from 0 to The remainder is converted into its ASCII representation and saved on the stack. The count of digits on the stack is incremented as well If the quotient is zero, all digits have been saved on the stack and if it is non-zero, we have to repeat the process to print the next digit.049 DI is initialized to point to the top left of the screen, called the cursor home. If the screen location is to become a parameter, the value loaded in DI will change A digit is popped off the stack, the attribute byte is appended to it and it is displayed on the screen The next screen location is two bytes ahead so DI is incremented by two. The process is repeated CX times which holds the number of digits pushed on the stack We pop the registers pushed and ret 2 to discard the only parameter on the stack The main program clears the screen and calls the print num subroutine to print 4529 on the top left of the screen. ==============================================================

25 Program No.25 Example 6.4 ; hello world at desired screen location [org 0x0100] jmp start message: db 'hello world' ; string to be printed length: dw 11 ; length of the string ;;;;; COPY LINES FROM EXAMPLE 6.2 (clrscr) ;;;;; ; subroutine to print a string at top left of screen ; takes x position, y position, string attribute, address of string ; and its length as parameters printstr: push bp mov bp, sp push es push ax push cx push si push di mov ax, 0xb800 mov es, ax ; point es to video base mov al, 80 ; load al with columns per row mull byte [bp+10] ; multiply with y position add ax, [bp+12] ; add x position shl ax, 1 ; turn into byte offset mov dial ; point di to required location mov si, [bp+6] ; point si to string mov cx, [bp+4] ; load length of string in cx mov ah, [bp+8] ; load attribute in ah nextchar: mov al, [si] ; load next char of string mov [es:di], ax ; show this char on screen add di, 2 ; move to next screen location add si, 1 ; move to next char in string loop nextchar ; repeat the operation cx times pop di pop si pop cx pop ax pop es pop bp ret 10 start: call clrscr ; call the clrscr subroutine mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 1 ; blue on black attribute push ax ; push attribute mov ax, message push ax ; push address of message push word [length] ; push message length call printstr ; call the printstr subroutine mov ax, 0x4c00 ; terminate program int 0x21 41 Push and pop operations always operate on words; however data can be read as a word or as a byte. For example we read the lower byte of the parameter y-position in this case. 43 Shifting is used for multiplication by two, which should always be the case when multiplication or division by a power of two is desired.61 The subroutine had 5 parameters so ret 10 is used The main program pushes 30 as x-position, 20 as y-position meaning 30th column on 20th row. It pushes 1 as the attribute meaning low intensity blue on black with no blinking. =============================================================== Program No.26 Example 7.1 ; clear screen using string instructions [org 0x0100] jmp start ; subroutine to clear the screen clrscr: push es push ax

26 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 in normal attribute mov cx, 2000 ; number of screen locations cld ; auto increment mode 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 0x A space efficient way to zero a 16bit register is to XOR it with itself.remember that exclusive or results in a zero whenever the bits at the source and at the destination are same. This instruction takes just two bytes compared to mov di, 0 which would take three. This is a standard way to zero a 16bit register. cld ; auto increment mode nextchar: lodsb ; load next char in al stosw ; print char/attribute pair loop nextchar ; repeat for the whole string pop di pop si pop cx pop ax pop es pop bp ret 10 start: call clrscr ; call the clrscr subroutine mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 1 ; blue on black attribute push ax ; push attribute mov ax, message push ax ; push address of message push word [length] ; push message length call printstr ; call the printstr subroutine mov ax, 0x4c00 ; terminate program int 0x Both operations are in auto increment mode DS is automatically initialized to our segment. ES points to video memory. SI points to the address of our string. DI points to the screen location. AH holds the attribute. Whenever we read a character from the string in AL, the attribute byte is implicitly attached and the pair is present in AX. The same effect could not be achieved with a REP prefix as the REP will repeat LODS and then start repeating STOS, but we need to alternate them. 054 CX holds the length of the string. Therefore LOOP repeats for each character of the string. ============================================================ Program No.27 Example 7.3 ; hello world printing with a null terminated string [org 0x0100] jmp start message: db 'hello world', 0 ; null terminated string ;;;;; COPY LINES FROM EXAMPLE 7.1 (clrscr) ;;;;; ; subroutine to print a string ; takes the x position, y position, attribute, and address of a null ; terminated string as parameters printstr: push bp mov bp, sp push es push ax push cx push si

27 push di push ds pop es ; load ds in es mov di, [bp+4] ; point 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 jz exit ; no printing if string is empty mov cx, ax ; load string length in cx mov ax, 0xb800 mov es, ax ; point es to video base mov al, 80 ; load al with columns per row mul byte [bp+8] ; multiply with y position add ax, [bp+10] ; add x position shl ax, 1 ; turn into byte offset mov di,ax ; point di to required location mov si, [bp+4] ; point si to string mov ah, [bp+6] ; load attribute in ah cld ; auto increment mode nextchar: lodsb ; load next char in al stosw ; print char/attribute pair loop nextchar ; repeat for the whole string exit: pop di pop si pop cx pop ax pop es pop bp ret 8 start: call clrscr ; call the clrscr subroutine mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 1 ; blue on black attribute push ax ; push attribute mov ax, message push ax ; push address of message call printstr ; call the printstr subroutine mov ax, 0x4c00 ; terminate program int 0x Another way to load a segment register is to use a combination of push and pop. The processor doesn t match pushes and pops. ES is equalized to DS in this pair of instructions. ========================================================== Program No.28 Example 7.4 ; hello world printing with length calculation subroutine [org 0x0100] jmp start message: db 'hello world', 0 ; null terminated string ;;;;; COPY LINES FROM EXAMPLE 7.1 (clrscr) ;;;;; ; 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

28 pop di pop cx pop es pop bp ret 4 ; subroutine to print a string ; takes the x position, y position, attribute, and address of a null ; terminated string as parameters printstr: push bp mov bp, sp push es push ax push cx push si push di push ds ; push segment of string mov ax, [bp+4] push ax ; push offset of string call strlen ; calculate string length cmp ax, 0 ; is the string empty jz exit ; no printing if string is empty mov cx, ax ; save length in cx mov ax, 0xb800 mov es, ax ; point es to video base mov al, 80 ; load al with columns per row mul byte [bp+8] ; multiply with y position add ax, [bp+10] ; add x position shl ax, 1 ; turn into byte offset mov di,ax ; point di to required location mov si, [bp+4] ; point si to string mov ah, [bp+6] ; load attribute in ah cld ; auto increment mode nextchar: lodsb ; load next char in al stosw ; print char/attribute pair loop nextchar ; repeat for the whole string exit: pop di pop si pop cx pop ax pop es pop bp ret 8 start: call clrscr ; call the clrscr subroutine mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 0x71 ; blue on white attribute push ax ; push attribute mov ax, message push ax ; push address of message call printstr ; call the printstr subroutine mov ax, 0x4c00 ; terminate program int 0x The LES instruction is used to load the DI register from BP+4 and the ES register from BP The convention 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. ========================================================== Program No.29 Example 7.5 ; scroll up the screen [org 0x0100] jmp start ; subroutine to scroll up the screen ; take the number of lines to scroll as parameter scrollup: push bp mov bp,sp push ax

29 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 of 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 start: mov ax,5 push ax ; push number of lines to scroll call scrollup ; call the scroll up subroutine mov ax, 0x4c00 ; terminate program int 0x21 =========================================================== Program No.30 Example 7.6 ; scroll down the screen [org 0x0100] jmp start ; subroutine to scrolls down the screen ; take the number of lines to scroll as parameter scrolldown: 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 push ax ; save position for later use shl ax, 1 ; convert to byte offset mov si, 3998 ; last location on the screen sub si, ax ; load source position in si mov cx, 2000 ; number of screen locations sub cx, ax ; count of words to move mov ax, 0xb800 mov es, ax ; point es to video base mov ds, ax ; point ds to video base mov di, 3998 ; point di to lower right column std ; set auto decrement 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

30 pop es pop di pop si pop cx pop ax pop bp ret 2 start: mov ax,5 push ax ; push number of lines to scroll call scrolldown ; call scroll down subroutine mov ax, 0x4c00 ; terminate program int 0x21 =========================================================== Program No.31 Example 7.7 ; comparing null terminated strings [org 0x0100] jmp start msg1: db 'hello world', 0 msg2: db 'hello WORLD', 0 msg3: db 'hello world', 0 ;;;;; COPY LINES FROM EXAMPLE 7.4 (strlen) ;;;;; ; subroutine to compare two strings ; takes segment and offset pairs of two strings to compare ; returns 1 in ax if they match and 0 other wise strcmp: push bp mov bp,sp push cx push si push di push es push ds lds si, [bp+4] ; point ds:si to first string les di, [bp+8] ; point es:di to second string push ds ; push segment of first string push si ; push offset of first string call strlen ; calculate string length mov cx, ax ; save length in cx push es ; push segment of second string push di ; push offset of second string call strlen ; calculate string length cmp cx, ax ; compare length of both strings jne exitfalse ; return 0 if they are unequal mov ax, 1 ; store 1 in ax to be returned repe cmpsb ; compare both strings jcxz exitsimple ; are they successfully compared exitfalse: mov ax, 0 ; store 0 to mark unequal exitsimple: pop ds pop es pop di pop si pop cx pop bp ret 8 start: push ds ; push segment of first string mov ax, msg1 push ax ; push offset of first string push ds ; push segment of second string mov ax, msg2 push ax ; push offset of second string call strcmp ; call strcmp subroutine push ds ; push segment of first string mov ax, msg1 push ax ; push offset of first string push ds ; push segment of third string mov ax, msg3 push ax ; push offset of third string call strcmp ; call strcmp subroutine

31 mov ax, 0x4c00 ; terminate program int 0x Three strings are declared out of which two are equal and one is different LDS and LES are used to load the pointers to the two strings in DS:SI and ES:DI. 070 Since there are 4 parameters to the subroutine ret 8 is used. ==================================================== Program No.32 Example 8.1 ; hooking divide by zero interrupt [org 0x0100] jmp start message: db 'You divided something by zero.', 0 ;;;;; COPY LINES FROM EXAMPLE 7.4 (strlen) ;;;;; ;;;;; COPY LINES FROM EXAMPLE 7.1 (clrscr) ;;;;; ;;;;; COPY LINES FROM EXAMPLE 7.4 (printstr) ;;;;; ; divide by zero interrupt handler myisrfor0: push ax ; push all regs push bx push cx push dx push si push di push bp push ds push es push cs pop ds ; point ds to our data segment call clrscr ; clear the screen mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 0x71 ; white on blue attribute push ax ; push attribute mov ax, message push ax ; push offset of message call printstr ; print message pop es pop ds pop bp pop di pop si pop dx pop cx pop bx pop ax iret ; return from interrupt ; subroutine to generate a divide by zero interrupt genint0: mov ax, 0x8432 ; load a big number in ax mov bl, 2 ; use a very small divisor div bl ; interrupt 0 will be generated ret start: xor ax, ax mov es, ax ; load zero in es mov word [es:0*4], myisrfor0 ; store offset at n*4 mov [es:0*4+2], cs ; store segment at n*4+2 call genint0 ; generate interrupt 0 mov ax, 0x4c00 ; terminate program int 0x We often push all registers in an interrupt service routine just to be sure that no unintentional modification to any register is made.since any code may be interrupted an unintentional modification will be hard to debug Since interrupt can be called from anywhere we are not sure about the value in DS so we reset it to our code segment. ======================================================== Program No.33 Example 8.2 ; print string using bios service [org 0x0100]

32 jmp start message: db 'Hello World' start: mov ah, 0x13 ; service 13 - print string mov al, 1 ; subservice 01 update cursor mov bh, 0 ; output on page 0 mov bl, 7 ; normal attrib mov dx, 0x0A03 ; row 10 column 3 mov cx, 11 ; length of string push cs pop es ; segment of string mov bp, message ; offset of string int 0x10 ; call BIOS video service mov ax, 0x4c00 ; terminate program int 0x The sub-service are versions of printstring that update and do not update the cursor after printing the string etc. 008 Text video screen is in the form of pages which can be upto 32. At one time one page is visible which is by default the zeroth page unless we change it ============================================================ Program No.34 Example 8.3 ; print string and keyboard wait using BIOS services [org 0x100] jmp start msg1: db 'hello world', 0 msg2: db 'hello world again', 0 msg3: db 'hello world again and again', 0 ;;;;; COPY LINES FROM EXAMPLE 7.1 (clrscr) ;;;;; ;;;;; COPY LINES FROM EXAMPLE 7.4 (printstr) ;;;;; ;;;;; COPY LINES FROM EXAMPLE 7.4 (strlen) ;;;;; start: mov ah, 0x10 ; service 10 vga attributes mov al, 03 ; subservice 3 toggle blinking mov bl, 01 ; enable blinking bit int 0x10 ; call BIOS video service mov ah, 0 ; service 0 get keystroke int 0x16 ; call BIOS keyboard service call clrscr ; clear the screen mov ah, 0 ; service 0 get keystroke int 0x16 ; call BIOS keyboard service mov ax, 0 push ax ; push x position mov ax, 0 push ax ; push y position mov ax, 1 ; blue on black push ax ; push attribute mov ax, msg1 push ax ; push offset of string call printstr ; print the string mov ah, 0 ; service 0 get keystroke int 0x16 ; call BIOS keyboard service mov ax, 0 push ax ; push x position mov ax, 0 push ax ; push y position mov ax, 0x71 ; blue on white push ax ; push attribute mov ax, msg2 push ax ; push offset of string call printstr ; print the string mov ah, 0 ; service 0 get keystroke int 0x16 ; call BIOS keyboard service mov ax, 0 push ax ; push x position mov ax, 0 push ax ; push y position mov ax, 0xF4 ; red on white blinking push ax ; push attribute mov ax, msg3 push ax ; push offset of string

33 call printstr ; print the string mov ah, 0 ; service 0 get keystroke int 0x16 ; call BIOS keyboard service mov ax, 0x4c00 ; terminate program int 0x This service has no parameters so only the service number is initialized in AH. This is the only service so there is no sub-service number as well. The ASCII code of the char pressed is returned in AL after this service. ============================================================= FAQ of CS401(Latest Updated) Question: What is Computer Architecture Answer: Computer Architecture is the science and art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals. Computer architecture is not about using computers to design buildings. OR The set of layers and protocols (including formats and standards that different hardware/software must comply with to achieve stated objectives) which define a computer system. Computer architecture features can be available to application programs and system programmers in several modes, including a protected mode. For example, the system-level features of computer architecture may include: (1) memory management, (2) protection, (3) multitasking, (4) input/output, (5) exceptions and multiprocessing, (6) initialization, (7) co processing and multiprocessing, (8) debugging, and (9) cache management Question: Explain Segment Override prefix Answer: To override the association for one instruction of one of the registers BX, BP, SI or DI, we use the segment override prefix. For example mov ax, [cs:bx] associates BX with CS for this one instruction. The processor places a special byte before the instruction called a prefix.no prefix is needed or placed for default association. Opcode has not changed, but the prefix byte has modified the default association to association with the desired segment register for this one instruction. Question: What is offset? Answer: A distance from a given paragraph boundary in memory. The offset usually is given as a number of bytes. Question: What is Subroutine? Answer: A self-contained coding segment designed to do a specific task, sometimes referred to as procedure. Question: Explain Segmented memory model Answer: The segmented memory model allows multiple functional windows into the main memory, a code window, a data window etc. The processor sees code from the code window and data from the data window. The size of one window is restricted to 64K. However the maximum memory iapx88 can access is 1MB which can be accessed with 20 bits. Question: What is Address wraparound? Answer: In physical address calculation a carry if generated is dropped without being stored anywhere, for example BX=0100, DS=FFF0 and the access under consideration is [bx+0x0100]. The effective address will be 0200 and the physical address will be This is a 21bit answer and cannot be sent on the address bus which is 20 bits wide. The carry is dropped and just like the segment wraparound our physical memory has wrapped around at its very top. Question: Explain Linear memory model. Answer: In linear memory model the whole memory appears like a single array of data and 8085 could access a total memory of 64K using the 16 lines of their address bus. Question: What's the difference between.com and.exe formats? Answer: To oversimplify: a.com file is a direct image of how the program will look in main memory, and a.exe file will undergo some further relocation when it is run (and so it begins with a relocation header). A.COM file is limited to 64K for all segments combined, but a.exe file can have as many segments as your linker will handle and be as large as RAM can take. The actual file extension doesn't matter. DOS knows that a file being loaded is in.exe format if its first two bytes are MZ or ZM; otherwise it is assumed to be in.com format. Actually they must be less than 0xFF00 bytes long, since the PSP, which isn't included in the COM file but is within those 64K, is 256 bytes long. Then CAN use many segments, but they don't have to. In particular, any.com file can be converted to an.exe file by adding an appropriate header to it. There are some other differences between a.com file and a single segment.exe file (both of which must be smaller than 64K).The entry point of the.com file is _always_ 0x100, while the entry point of the.exe file can be at any address. The stack size of the.com file is the remainder of those 64K which isn't used by the code image, while the stack size if the single segment.exe file can be set at any size as long as it fits within those 64K.Thus the stack can be smaller in the.exe file.

34 Question: Is MS-DOS Dead? Answer: No. Though Microsoft may not be actively developing MS-DOS there are still many computers that are not capable of running Microsoft Windows. The current versions of Microsoft Windows will also run most MS-DOS programs; therefore, MS-DOS is not dead, and will most- likely never die just as Commodore- 64s and Amigas have not completely died. Indeed, DOS has found a new life in embedded systems. Other parties continue to develop MS-DOS compatible operating systems. Windows NT, 2000, and XP all have a "Command Prompt" which is similar to the orignal MS-DOS command prompt. Question: How can I read a character without echoing it to the screen, and without waiting for the user to press the Enter key? Answer: In Assembly language, execute INT 21 AH=8; AL is returned with the character from standard input (possibly redirected). If you don't want to allow redirection, or you want to capture Ctrl-C and other special keys, use INT 16 AH=10; this will return the scan code in AH and ASCII code (if possible) in AL, but AL=E0 with AH nonzero indicates that one of the gray "extended" keys was pressed. (If your BIOS doesn't support the extended keyboard, use INT 16 AH=0 not 10.) Question: What is NASM? Answer: NASM, the Netwide Assembler, is a free assembler for Intel 80x86 series of microprocessors. Not only is the assembler compatible with MS-DOS, but it will also work under Windows 95, Linux, and OS/2. Question: What is difference b/w assembler and disassembler? Answer: Assembler An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. Some people call these instructions assembler language and others use the term assembly language. In programming terminology, to disassemble is to convert a program in its executable (ready-to-run) form (sometimes called object code) into a representation in some form of assembler language so that it is readable by a human. A program used to accomplish this is called a disassembler, because it performs the inverse of the task that an assembler does. Disassembly is a type of reverse engineering. Another such program, called a decompiler, converts object code back into the code of a higher-level language. Question: What are the functions of Parity and Sign flag? Answer: Dear Student P Parity Parity is the number of one bits in a binary number. Parity is either odd or even. This information is normally used in communications to verify the integrity of data sent from the sender to the receiver. S Sign Flag A signed number is represented in its two s complement form in the computer. The most significant bit (MSB) of a negative number in this representation is 1 and for a positive number it is zero. The sign bit of the last mathematical or logical operation s destination is copied into the sign flag. Thanks Question: WHAT IS MACHINE LANGUAGE? Answer: Although programmers tend to use C or C++ or Pascal these days, the language closest to the PC hardware is machine language. Not one second during a PCS powered on lifetime passes where the computer is not executing machine language. Question: WHEN TO USE ASSEMBLY LANGUAGE Answer: I personally think that except as a learning exercise it is a waste of time writing something in ASM that can be written acceptably fast in a high-level language. Assembly language fits for the following: * Low level control. When you need to change the flags, or the control registers of the processor, as when entering protected mode. * Speed. Programs written in machine language execute fast! It can execute times the speed of BASIC, and about twice as fast as a program written in C or Pascal. * Time Critical Code. Critical sections of programs written in higher level languages can be written in assembly to speed up sections. * Small program size. When you write a TSR for example this is very useful. Writing interrupt handlers is where assembly language shines. Assembly language is very flexible and powerful; anything that the hardware of the computer is capable of doing can be done in assembly. Question: What are interrupts? Answer: The hardware and software designed for original PC communicated with the CPU by means of a hierarchical and predetermined set of signals called interrupts. When a device or a program needed some action on the part of the CPU it would signal this by sending an interrupt signal. The CPU would sort out the priority of the incoming interrupt requests, with lower number interrupts being handled first (it is common for the CPU to be handling several interrupts concurrently) and then locate the code associated with the interrupt (the Interrupt Request Handler) by examining the Interrupt Vector Table. Each interrupt (starting with interrupt 00H) is allocated four bytes in the vector table. These four bytes serve as an address pointer to

35 the actual software routine associated with the interrupt. These routines may be stored in the ROM BIOS or more commonly in system RAM (where copies of ROM BIOS routines are often uploaded to provide faster access). The interrupt vector table is first initialized by the Start-up ROM but changes are made to it's contents as first the ROM Extensions and later the operating system files are loaded. The ability to update the contents of the interrupt vector table provides a means to easily expand operating system services by making a standard interrupt point to a new Interrupt Handler. Question: What are registers? Answer: One of a small number of high-speed memory locations in a computer's CPU. Registers differ from ordinary random access memory in several respects: There are only a small number of registers (the "register set"), typically 32 in a modern processor though some, e.g. SPARC, have as many as 144. A register may be directly addressed with a few bits. In contrast, there are usually millions of words of main memory (RAM), requiring at least twenty bits to specify a memory location. Main memory locations are often specified indirectly, using an {indirect addressing} mode where the actual memory address is held in a register. Registers are fast; typically, two registers can be read and a third written -- all in a single cycle. Memory is slower; a single access can require several cycles. Question: What is control bus and what function it performs? Answer: The physical connections that carry control information between the CPU and other devices within the computer. Whereas the data bus carries actual data that is being processed, the control bus carries signals that report the status of various devices. For example, one line of the bus is used to indicate whether the CPU is currently reading from or writing to main memory. Question: What do you mean by Peripherl devices? Answer: Peripherals Any piece of hardware connected to a computer; any part of the computer outside the CPU and working memory; Any input or output device connected to a computer. Some examples of peripherals are keyboards, mice, monitors, printers, scanners, disk and tape drives, microphones, speakers, joysticks, plotters, and cameras. Question: What is difference b/w physical and logical address? Answer: The segment, offset pair is called a logical address, while the 20bit address is a physical address which is the real thing. Logical addressing is a mechanism to access the physical memory. However I recommend you to read topic 1.8 Segmented memory Model in handouts to get you understand well. Question: What is difference between DATA LABEL and CODE LABEL? Answer: Data Label is the label that we use to define data as we defined memory locations num1,num2...etc in our programs. Code Label is the label that we have on code as we see in case of conditional jump (Label l1) and is normally used for loop control statements. Question: What is Segment Wrap Around? Answer: Dear Student For the whole megabyte we need 20 bits while CS and IP are both 16bit registers. We need a mechanism to make a 20bit number out of the two 16bit numbers. Consider that the segment value is stored as a 20 bit number with the lower four bits zero and the offset value is stored as another 20 bit number with the upper four bits zeroed. The two are added to produce a 20bit absolute address. A carry if generated is dropped without being stored anywhere and the phenomenon is called address wraparound. Question: What is BIOS and how it can be updated? Answer: Dear Student One of the most common uses of Flash memory is for the basic input/output system of your computer, commonly known as the BIOS (pronounced "bye-ose"). On virtually every computer available, the BIOS makes sure all the other chips, hard drives, ports and CPU function together. Question: What BIOS Does? The BIOS software has a number of different roles, but its most important role is to load the operating system. When you turn on your computer and the microprocessor tries to execute its first instruction, it has to get that instruction from somewhere. It cannot get it from the operating system because the operating system is located on a hard disk, and the microprocessor cannot get to it without some instructions that tell it how. The BIOS provides those instructions. Some of the other common tasks that the BIOS performs include: A power-on self-test (POST) for all of the different hardware components in the system to make sure everything is working properly Activating other BIOS chips on different cards installed in the computer - For example, SCSI and graphics cards often have their own BIOS chips.

36 Providing a set of low-level routines that the operating system uses to interface to different hardware devices - It is these routines that give the BIOS its name. They manage things like the keyboard, the screen, and the serial and parallel ports, especially when the computer is booting. Managing a collection of settings for the hard disks, clock, etc. The BIOS is special software that interfaces the major hardware components of your computer with the operating system. It is usually stored on a Flash memory chip on the motherboard, but sometimes the chip is another type of ROM. When you turn on your computer, the BIOS does several things. This is its usual sequence: 1. Check the CMOS Setup for custom settings 2. Load the interrupt handlers and device drivers 3. Initialize registers and power management 4. Perform the power-on self-test (POST) 5. Display system settings 6. Determine which devices are bootable 7. Initiate the bootstrap sequence Updating BIOS Occasionally, a computer will need to have its BIOS updated. This is especially true of older machines. As new devices and standards arise, the BIOS needs to change in order to understand the new hardware. Since the BIOS is stored in some form of ROM, changing it is a bit harder than upgrading most other types of software. To change the BIOS itself, you'll probably need a special program from the computer or BIOS manufacturer. Look at the BIOS revision and date information displayed on system startup or check with your computer manufacturer to find out what type of BIOS you have. Then go to the BIOS manufacturer's Web site to see if an upgrade is available. Download the upgrade and the utility program needed to install it. Sometimes the utility and update are combined in a single file to download. Copy the program, along with the BIOS update, onto a floppy disk. Restart your computer with the floppy disk in the drive, and the program erases the old BIOS and writes the new one. You can find a BIOS Wizard that will check your BIOS at BIOS Upgrades. Question: What is Interrupt vector Table? Answer: Dear Student 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 zero. Each entry of the table is four bytes long containing the segment and offset of the interrupt routine for the corresponding interrupt number. The first two bytes in the entry contain the offset and the next two bytes contain the segment. The little endian rule of putting the more significant part (segment) at a higher address is seen here as well. Mathematically offset of the interrupt n will be at nx4 while the segment will be at nx4+2. One entry in this table is called a vector. If the vector is changed for interrupt 0 then INT 0 will take execution to the new handler whose address is now placed at those four bytes. INT 1 vector occupies location 4, 5, 6, and 7 and similarly vector for INT 2 occupies locations 8, 9, 10, and 11. As the table is located in RAM it can be changed anytime. Immediately after changing it the interrupt mapping is changed and now the interrupt will result in execution of the new routine. This indirection gives the mechanism extreme flexibility. Question: What are the terms ASCII CODE and SCAN CODE? Answer: Dear Student Scan Code Each key on the keyboard is assigned a unique number called a Scan Code; When a key is pressed, the keyboard circuit sends the corresponding scan code to the computer. Scan code table is given on MDB of Lecture#24. ASCII Code I/O devices such as the video monitor and printer are character oriented, and programs such as word processors deal with characters exclusively. Like all data, characters must be coded in binary in order to be processed by the computer. The most popular encoding scheme for characters is ASCII (American Standard Code for Information Interchange) code. Question: What is Virtual Machine? Answer: Dear Student Virtual machine is a term used by Sun Microsystems, developers of the Java programming language and runtime environment, to describe software that acts as an interface between compiler Java binary code and the microprocessor (or "hardware platform") that actually performs the program's instructions. Once a Java virtual machine has been provided for a platform, any Java program (which, after compilation, is called bytecode) can run on that platform. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. Java's virtual machine makes this possible.

37 The Java virtual machine specification defines an abstract rather than a real "machine" (or processor) and specifies an instruction set, a set of registers, a stack, a "garbage heap," and a method area. The real implementation of this abstract or logically defined processor can be in other code that is recognized by the real processor or be built into the microchip processor itself. The output of "compiling" a Java source program (a set of Java language statements) is called bytecode. A Java virtual machine can either interpret the bytecode one instruction at a time (mapping it to a real microprocessor instruction) or the bytecode can be compiled further for the real microprocessor using what is called a just-in-time compiler. Question: What are Registers and why these are needed? Answer: Registers are like a scratch pad ram inside the processor and their operation is very much like normal memory cells. They have precise locations and remember what is placed inside them. They are used when we need more than one data element inside the processor at one time. Question: What is Big-Endian and Little-Endian? Answer: Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4F52 would be stored as 4F52 in storage (if 4F is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524F (52 at address 1000, 4F at 1001). IBM's 370 computers, most RISC-based computers, and Motorola microprocessors use the big-endian approach.on the other hand, Intel processors (CPUs) and DEC Alphas and at least some programs that run on them are little-endian. Question: How we calculate Physical Address? Answer: for the whole megabyte we need 20 bits while CS and IP are both 16bit registers. We need a mechanism to make a 20bit number out of the two 16bit numbers. Consider that the segment value is stored as a 20 bit number with the lower four bits zero and the offset value is stored as another 20 bit number with the upper four bits zeroed. The two are added to produce a 20bit absolute address. A carry if generated is dropped without being stored anywhere and the phenomenon is called address wraparound. The process is explained with the help of the following diagram. Therefore memory is determined by a segment-offset pair and not alone by any one register which will be an ambiguous reference. Every offset register is assigned a default segment register to resolve such ambiguity. For example the program we wrote when loaded into memory had a value of 0100 in IP register and some value say 1DDD in the CS register. Making both 20 bit numbers, the segment base is 1DDD0 and the offset is and adding them we get the physical memory address of 1DED0 where the opcode B80500 is placed. Question: What is a Stack? Answer: Stack is a data structure that behaves in a first in last out manner. It can contain many elements and there is only one way in and out of the container. When an element is inserted it sits on top of all other elements and when an element is removed the one sitting at top of all others is removed first. To visualize the structure 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 can 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. The last thing pushed is popped out first; the last in first out behavior.

38 GLOSSARY Updated Version Absolute Address: A virtual (not physical) address within the process address space that is computed as an absolute number. Address Bus: The group of bits that the processor uses to inform the memory about which element to read or write is collectively known as the address bus. The address bus is unidirectional and address always travels from processor to memory. Address Wraparound: In physical address calculation a carry if generated is dropped without being stored anywhere, for example BX=0100, DS=FFF0 and the access under consideration is [bx+0x0100]. The effective address will be 0200 and the physical address will be This is a 21bit answer and cannot be sent on the address bus which is 20 bits wide. The carry is dropped and just like the segment wraparound our physical memory has wrapped around at its very top. AND Operation: AND performs the logical bitwise and of the two operands (byte or word) and returns the result to the destination operand. A bit in the result is set if both corresponding bits of the original operands are set; otherwise the bit is cleared Archive Bit: sed to indicate the most recently modified version of a file. Assembler: A program that translates assembly language into machine language. Base + Index + Offset Addressing: The values of the base register, the index register, and the constant offset are all added together to get the effective address. For example mov [bx+si+300], ax moves the word contents of the AX register to the word in memory starting at offset attained by adding BX, SI, and 300 in the current data segment. Default segment association is again based on the base register. Base + Index Addressing: The value of the base register and the index register are added together to get the effective address. For example mov [bx+si], ax moves the word contained in the AX register to offset attained by adding BX and SI in the current data segment. Base Register Indirect + Offset Addressing: A base register is used with a constant offset in this addressing mode. The value contained in the base register is added with the constant offset to get the effective address. For example mov [bx+300], ax stores the word contained in AX at the offset attained by adding 300 to BX in the current data segment Base Register Indirect Addressing: A base register is used in brackets and the actual address accessed depends on the value contained in that register. Binary: A binary number is expressed in the base two. Its possible value is either 0 or 1. Binary Coded Decimal (BCD): A system of coding in which each decimal digit is as 4 binary digits, like 6 decimal in BCD is 0110 Nibble: A nibble is a unit of 4 bits. Byte: A byte is a unit of 8 bits. Word: A word is a unit of 8 bits. Byte : A byte is a unit of 8 bits CALL : An assembly language instruction telling the assembler to perform the subroutine. Carry flag : The bit in the flag register that indicates whether the previous operation resulted in a carry out of or borrow into high order bit of the resulting byte or word.

39 Cell width : The number of bits in a memory cell is called the cell width. Command : Command is an instruction to a computer or device to perform a specific task Compare Instruction :The operation of CMP is to subtract the source operand from the destination operand, updating the flags without changing either the source or the destination. Data Bus : Data bus is used to move data from the memory to the processor in a read operation and from the processor to the memory in a write operation. Data Transfer Area : Area of memory that DOS uses to store data from a file. Debugger : A utility program that allows the programmer to execute a program one line at a time and view the contents of registers and memory in order to help locate the source of bugs or other problems. Examples are CodeView. Declaration : A construct that associates the name and the attributes of a variable, function, or type. Default : A setting or value that is assumed unless specified otherwise. Direct addressing : A fixed offset is given in brackets and the memory at that offset is accessed. Directory : A logical grouping of files on a disk for the purpose of organizing files is known as directory. Each directory can contain files and/or other directories, so a hierarchy of files and directories can be created. Far Jump : Far jump is not position relative but is absolute. Two byte segment and two byte offset must be given to a far jump. We use this when we need to go from one code segment to another. It loads CS with the segment part and IP with the offset part. Far procedure : A procedure that can be called by procedures residing in any segment. File : A unit of information stored on a disk. Each file has a specification of the form filename. extension, where the filename identifies the file, and the 3-letter extension identifies the file type. Some standard extensions are:.asm assembler source file.com executable program file.lst list file.obj object file.exe executable program file High-level programming : Programming that does not need to consider, aspects of the underlying hardware and operating system Indexed Register Indirect + Offset Addressing : An index register is used with a constant offset in this addressing mode. The value contained in the index register is added with the constant offset to get the effective address. For example mov [si+300], ax moves the word contained in AX to the offset attained by adding 300 to SI in the current data segment Indexed Register Indirect Addressing : An index register is used in brackets and the actual address accessed depends on the value contained in that register. For example mov [si], ax moves the contents of the AX register to the word starting at address contained in SI in the current data segment. Instruction : A command that tells the processor to do something, like add two numbers or get some data from the memory. Interrupt : An interrupt is a request for service from an external device seeking attention. The external device requests service by asserting an interrupt request line connected to the processor. The processor may or may not deal with the interrupt depending on whether the interrupt is masked (i.e., ignored). If the interrupt is not masked, the processor deals with it by executing a piece of code called an interrupt handler. Once this handler has been executed, the processor returns to the point that it had reached immediately before the interrupt

40 Interrupt flag : The bit in the flag register that indicates whether the CPU should handle mask able interrupts. If this flag is set, interrupt are handled. If it is clear, interrupts are ignored. Linear memory model : In linear memory model the whole memory appears like a single array of data and 8085 could access a total memory of 64K using the 16 lines of their address bus. Listing File : Listing file is an optional output file from the assembly process that shows how the assembly language program has been translated into object code. A listing file has the extension.lst. Local variable : A variable whose scope is confined to a particular unit of code, such as module-level code, or a procedure. Logical Address : The address of an operand generated by the CPU is called a logical address. The logical address is mapped onto the actual address (physical address) of an operand by a memory management unit. Low-level programming : Programming that uses direct access to machine-level features such as programs that are part of a machine's control systems Machine language : The series of binary digits a microprocessor executes to perform individual tasks. People program in assembly language, and an assembler translates their instructions into machine language. Memory : Memory is where data is stored. One byte allows you to store an eight digit binary number, so the largest number you can store in each location is a binary , or 255 in decimal. The lowest is 0. If we want to use larger numbers, we group several chunks together. One common grouping is two bytes, or a "word". Two bytes together can hold a value between 0 and (2^16). memory stack : A contiguous array of memory locations, commonly referred to as the stack, used in many processors to save the state of the calling procedure, pass parameters to the called procedure and store local variables for the currently executing procedure. Mnemonic : A word, abbreviation, or acronym that replaces something too complex to remember or type easily. For example, ADC is the mnemonic for the 8086 s add-with-carry instruction. The assembler converts it into machine (binary) code, so it is not necessary to remember or calculate the binary form. Near Jump : When the relative address stored with the instruction is in 16 bits the jump is called a near jump. Using a near jump we can jump anywhere within a segment. If we add a large number it will wrap around to the lower part. NEAR Procedure : A procedure that can only be called by another procedure residing in the same segment. NOT operation : NOT inverts the bits (forms the one s complement) of the byte or word operand. Offset : A distance from a given paragraph boundary in memory. The offset usually is given as a number of bytes. Op-code : The op-code or operation code is the binary pattern that represents an instruction. OR operation : OR operation performs the logical bitwise inclusive or of the two operands (byte or word) and returns the result to the destination operand. A bit in the result is set if either or both corresponding bits in the original operands are set otherwise the result bit is cleared Overflow flag : The bit in the flag register that indicates whether the signed result of the preceding operation can be represented in the result byte or word. Parameter : The name given in a procedure definition to a variable that is passed to the procedure.

41 Passing by reference : Transferring the address of an argument to a procedure. This allows the procedure to modify the argument s value Passing by value : Transferring the value (rather than the address) of an argument to a procedure. This prevents the procedure from changing the argument s original value. Peripheral : The term peripheral is somewhat ambiguous. It is used to describe external devices like disk drives, keyboards, mouse, and displays. It is also used to describe the hardware that interfaces these devices to the processor. For example, both the floppy disk controller chip that interfaces a floppy disk drive to a processor and the floppy disk drive itself are often called peripherals. PROC : An assembly language directive indicating start of procedure. Procedure call : An expression that invokes a procedure and passes actual arguments (if any) to the procedure. Procedure definition : A definition that specifies a procedure s name, its formal parameters, the declarations and statements that define what it does, and (optionally) its return type and storage class. Procedure prototype : A procedure declaration that includes a list of the names and types of formal parameters following the procedure name Process : Generally, any executing program or code unit Program : An organized list of instructions, that when executed causes the computer to work in a predetermined manner Program Counter : The program counter contains the address of the next instruction to be executed. The program counter is incremented after each instruction is executed. Prompt : A message displayed at the beginning of a line by a program to request a response from the user. DOS prompts for commands with the current disk drive and directory name followed by an angle bracket (e.g., C:\Assembly). Registers : A register is a piece of high-speed memory located directly on the processor. It is used to store data while the processor manipulates it. On the iapx8088, there are 14 registers. RET : At the end of the subroutine, a RET instruction pops the old value of IP from the stack into the instruction pointer, and execution resumes right where the CALL instruction left off. Routine : A generic name for the procedure or a function Segment : A particular area of memory of 64 K in size. Segment Override Prefix : To override the association for one instruction of one of the registers BX, BP, SI or DI, we use the segment override prefix. For example mov ax, [cs:bx] associates BX with CS for this one instruction. The processor places a special byte before the instruction called a prefix. No prefix is needed or placed for default association. Opcode has not changed, but the prefix byte has modified the default association to association with the desired segment register for this one instruction Segment wraparound : Segment wraparound occurs when during the effective address calculation a carry is generated. This carry is dropped giving the effect that when we try to access beyond the segment limit, we are actually wrapped around to the first cell in the segment. For example if BX=9100, DS=1500 and the access is [bx+0x7000] we form the effective address = The carry generated is dropped forming the actual effective address of Segmented memory model : The segmented memory model allows multiple functional windows into the main memory, a code window, a data window etc. The processor sees code from the code window and data

42 from the data window. The size of one window is restricted to 64K. However the maximum memory iapx88 can access is 1MB which can be accessed with 20 bits. Shift : A shift operation moves the bits of a memory location or a data register one or more places left or right. There are three types of shift (logical, arithmetic, and rotate). In a logical shift, a zero enters the bit at the end that is vacated. In an arithmetic operation, the sign bit is replicated during a shift right. In a rotate operation, the bit that falls off one end is copied to the vacated bit. Short Jump : The jump in which if the offset is stored in a single byte then it is called a short jump. Conditional jumps can only be short. A short jump can go +127 bytes ahead in code and -128 bytes backwards and no more. Signed integer : An integer value that uses the most-significant bit to represent the value s sign. If the bit is one, the number is negative; if zero, the number is positive. Source File : A file which contains a program written in assembly language is the source file. It is an input to the assembler. An assembly language source file usually has the extension.asm. Stack : An area of memory in which data items are consecutively stored and removed on a last in, first out basis. A stack can be used to pass parameters to procedures. Subroutine : A self-contained coding segment designed to do a specific task, sometimes referred to as procedure. TOP of the stack : The last word of data added to the stack Unsigned integer : An integer in which the most significant bit serves as part of the number, rather than as an indication of sign. For example, an unsigned byte integer can have a value from 0 to 255. A signed byte integer, which reserves its eighth bit for the sign, can range from -127 to Variable Declaration : A statement that initializes and allocates storage for a variable of a given type. Word : Two consecutive bytes of data i.e., 16 bits XOR operation : Exclusive OR performs the logical bitwise exclusive or of the two operands and returns the result to the destination operand. A bit in the result is set if the corresponding bits of the original operands contain opposite values (one is set, the other is cleared) otherwise the result bit is cleared. Past Solved Assignments Questions Q1) Differentiate Between register and Memory location (4) 1) Registers are storage locations internal to the processor but RAM is located external to the CPU. 2) All data must be moved into a register before it can be operated whereas data has to be loaded into a CPU register from memory before the CPU can process it. 3) Registers are faster where as memory is much slower than registers. 4) In general, registers hold the data the processor is currently working on, while Memory holds the program instructions and the data the program requires. Note: A best practice is to draw a table with two columns and highlight the difference with specifying the features in separate columns Q2) Commands to view data in Memory Window 1 & 2: A) Command to view data in memory window 1 Syntax: M1 Segment-Base-Address : Offset-Address Example M1 DS : 0100 Explanation: The above example will display the contents of memory location at offset address 0x0100 in Data Segment register. The data will be displayed in Memory Window 1 B) Command to view data in memory window 2 Syntax: M2 Segment-Base-Address : Offset-Address Example M2 DS : 0100 Explanation: The above example will display the contents of memory location at offset address 0x0100 in Data Segment register. The data will be displayed in Memory Window 2

43 Q3) Code to Swap two numbers: [org 0x0100] jmp Start var1: dw 5 ; First Variable var2: dw 10 ; Second variable Start: mov ax, [var1] ; AX=Var1 mov dx, [var2] ; BX= Var2 mov [var1],dx ; Interchanged value mov [var2],ax int 0x21 Explanation: in this code we used two variables Var1 and Var2 whose values were to be swapped we first moved the contents of first variable in AX and those of second register in DX and finally we swapped the variables by assigning the variables, the value of other variable (stored in register). We used to registers because we can t move data directly from one memory location to other. Q4) Explain the instructions with example. JNZ: JNE: Both of the above instructions are synonyms of each other and belong to set of instructions from conditional jump, both test the condition that ZF is set or not if ZF=0 (i.e. the last mathematical/logical operation did not produce zero result) a jump will occur to specified location. Syntax: JNZ labelname JNE labelname Example JNZ Swap Explanation: here JNZ will check the ZF and a jump will occur to accordingly depending on the value of CF and execution will start from the first instruction after labelname label. CMP: The cmp instruction is used to compare two operands. It subtracts the right operand from the left operand; however no register is modified except the CF and ZF flags, which are set. Syntax: CMP destination, source Example CMP Ax, 0x0100 Explanation: By comparing the contents of AX register with 0x0100 the target flags are modified accordingly: Rules to Set Flags: A < B CF = 1 ZF = 0 A = B CF = 0 ZF = 1 A > B CF = 0 ZF = 0 Q6) which instructions are legal. If illegal correct them. i. mov [05], [ 24] ii. mov [label1], 501 iii. mov bx, al iv. mov bx,[bs+bp+200] Solution: mov [05], [ 24] Memory to Memory referencing is not allowed. The correct instructions for this operation could be mov ax, [24] mov [05],ax mov [label1], 50l Here the size of data to be moved is ambiguous, so assembler will complain: One option can be: mov ax,501 mov [label1],ax mov bx, al Size Mismatch, BX is 16 bits where as AL is 8-bits: the desired result can be received as mov bx, ax or mov bl, al mov bx,[bs+bp+200] Two base registers are involved which is illegal. We can only add index register with base. mov ax, [bp+ si+100] Q7) Calculating physical address. 1) Suppose CS register contains the value 1DDD in hexadecimal and IP register contains the following value 0436 again in hexadecimal.

44 2) The binary value of CS will be ) Append four binary zeros to the Least Significant Side, now it becomes: ) The binary value of IP register is ) Append four binary bits to the Most Significant Side, now it becomes: ) Now the Segment Value is ) Offset Value is ) Add Both of these binary numbers and you get the actual physical address: = ) So the actual physical address is How these instructions are legal or illegal. If illegal tell the reason and how we can make this legal, if legal then what these instructions do. a. mov ax, bx b. mov 10,ax c. mov bx, [num2] d. mov [num1],[num2] e. add [num2],[num1] f. mov [num1],al Solution: a. mov ax, bx This instruction is legal because register to register move is allowed. b. mov 10,ax This instruction is illegal because the we cant move a register or memory address into a constant. It can be rectify mov bx,ax or mov [var],ax. c. mov bx, [num2] This instruction is legal because memory to register is also allowed. d. mov [num1],[num2] This instruction is illegal because memory to memory is not allowed. It can be rectify Mov ax, [num2] Mov [num1], ax e. add [num2],[num1] This instruction is illegal because memory to memory operation is not allowed. It can be rectify mov ax,[num1] add [num2], ax f. mov [num1],al This instruction is legal because register to memory is allowed. Assemble the following code and step through it inside the debugger. Observer the values of AX, BX, and the four words starting at num1 after every instruction and fill them in the table given below. All number entered in the table must be in hexadecimal. Also give the reason why the result in [num1+6] is not 30 as expected. [org 0x100] mov ax, [num1] mov bx, [num1+2] add ax, bx mov bx, [num1+4] add ax, bx mov [num1+6], ax mov ax, 0x4c00 int 0x21 num1: db 5, 10, 15, 0 Solution: AX BX [num1] [num1+2] [num1+4] [num1+6] Mov ax, [num1] 0x0A05 0x0000 0x05 0x0F 0x00 0x14 Mov bx, [num1+2] 0x0A05 0x000F 0x05 0x0F 0x00 0x14 Add ax, bx 0x0A14 0x000F 0x05 0x0F 0x00 0x14 Mov bx, [num1+4] 0x0A14 0x0000 0x05 0x0F 0x00 0x14 Add ax, bx 0x0A14 0x0000 0x05 0x0F 0x00 0x14 Mov [num1+6], ax 0x0A14 0x0000 0x05 0x0F 0x00 0x14 Reason that why result in [num1+6] is not 30 as expected: The problem here is that data is defined as BYTE num1: db 5, 10, 15, 0 and we are moving it into 16 bit registers

45 mov ax, [num1] i.e. interpreting data as WORD. Now num1 points to 5, num1+2 points to 15 and num1+4, num1+6 both points to garbage values. Also, after execution of mov ax, [num1] AX will contain 0x0A05 instead of 0x0005. All these issues lead to the wrong value in num1+6. Calculate the effective address and the physical address accessed by each of the following instructions. Also give the value of the designated register in each instruction by looking up the dump of a portion of physical memory given below. All questions are independent of each other. Assume the registers are initialized as ES = 0x4020 DS = 0x40A0 BX = 0x0010 SI = 0x000E BP = 0x0000 SS = 0x4010 If you calculate a physical address and it is not present in the table given above then simple write that Address is not given in table. Solution: mov ax, [30] First we have to calculate offset which is decimal 30 (0x1E). Effective Address = 0x0030 Physical Address = (Segment Address * 0x10) + Effective Address = (0x40A0 * 0x10) + 0x001E = 0x40A1E The Address is not present in the Memory Dump. mov cx,[es:bx-0x10] Effective Address = bx 0x10 = 0x0010 0x10 = 0x0000 Physical Address = (Segment Address * 0x10) + Effective Address = (0x4020 * 0x10) + 0x0000 = 0x40200 The Value of CX Register from the Memory Dump is = 0x0A43 mov bx,[bp + 0x0F] Effective Address = bp + 0x0F = 0x x000F = 0x000F Physical Address = (Segment Address * 0x10) + Effective Address = (0x4010 * 0x10) + 0x000F = 0x4010F The Address is not present in the Memory Dump (One byte is missing). mov cx, [0x30 + 0x15] Effective Address = 0x45 = 0x0045 Physical Address = (Segment Address * 10) + Effective Address = (0x40A0 * 0x10) + 0x0045 = 0x40A45 The Address is not present in the Memory Dump. mov byte al,[0x0e] Effective Address = 0x000E Physical Address = (Segment Address * 0x10) + Effective Address = (0x40A0 * 0x10) + 0x000E = 0x40A0E The Value of AL register from the Memory Dump is 75. mov ax, [bx+si+0x15] Effective Address = 0x x000E + 0x0015 = 0x0033 Physical Address = (Segment Address * 0x10) + Effective Address = (0x40A0 * 0x10) + 0x0033 = 0x40A33 The Address is not present in the Memory Dump. mov bx,[0x11] Effective Address = 0x0011 Physical Address = (Segment Address * 0x10) + Effective Address = (0x40A0 * 0x10) + 0x0011 = 0x40A11 The Address is not present in the Memory Dump. Effective Address Physical Address Register Value

46 Mov ax, [30] 0x001E 0x40A1E Not given Mov cx, [es:bx-0x10] 0x0000 0x x0A43 Mov bx, [bp+0x0f] 0x000F 0x4010F Byte not there Mov cx, [0x30+0x15] 0x0045 0x40A45 Not given Mov byte al, [0x0E] 0x000E 0x40A0E 0x75 Mov ax, [bx+si+0x15] 0x0033 0x40A33 Not given Mov bx, [0x11] 0x0011 0x40A11 Not given Question # 1. What is wrong with following instructions? mov [byte1], 20 mov [111],[333] mov [BX],[SI] mov CS, SS mov DL, CX Solution: a. Size of movement is not specified. b. Memory to memory data movement is not allowed c. Memory to memory data movement is not allowed. d. Segment to Segment movement is not allowed. e. Size mismatch. Question # 2 What is the effective address generated by the following combinations if they are valid. Initially BX= 0x0200, SI= 0x0020, DI= 0x0002, BP= 0X400 AND SP= 0XFFFF? bx + bp a) bx + sp b) bx + di c) bx-si d) bx Solution: a) Invalid b) Invalid c) 0x0202 d) Invalid e) 0x300 If AX=0x8000 and BX=0x0001 and cmp ax, bx is executed, which of the following jumps will be taken? Each part is independent of others. Also give the value of Z, S, and C flags. a. jg greater b. jl smaller c. ja above d. jb below Solution: Instructions Jump ZF SF CF Jg greater Not taken Jl smaller Taken Ja above Taken Jb below Not taken Write a program in Assembly Language to find the maximum number and the minimum number from an array of ten numbers. Solution: [org 0x0100] jmp start ; unconditionally jump over data array1: dw 10, 5, 30, 4, 50, 1, 20, 6, 40, 8 min: dw 0 max: dw 0 start: ; for finding minimum number mov bx, 0 ; initialize array index to zero mov ax, 0 ; initialize min to zero mov ax, [array1+bx] ; minimum number to ax mov cx,10 top1: cmp ax, [array1+bx] ; are we find the minimum number jle end1 ; if less or equal number mov ax,[array1+bx] ;ax contains the minimum number end1: add bx, 2 ; advance bx to next index

47 loop top1 mov [min], ax ; write back minimum in memory ; for maximum number mov bx, 0 ; initialize array index to zero mov ax, 0 ; initialize max to zero mov ax, [array1+bx] ; maximum number to ax mov cx,10 top2: cmp ax, [array1+bx] ; are we find the maximum number jge end2 ; if greater or equal number mov ax,[array1+bx] ;ax contains the maximum number end2: add bx, 2 loop top2 mov [max], ax mov ax, 0x4c00 int 0x21 ; advance bx to next index ; write back maximum number in memory ; terminate program Suppose AL contains b and CF= 0. Give the new contents of AL after each of the following instructions is executed. Assume the preceding initial conditions for each part of this question. a. SHL AL,1 b. SHR AL, CL if CL contains 3 c. ROL AL,1 d. SAR AL, CL if CL contains 3 e. RCR AL,CL if CL contains 2 Solution: a. AL= CF=1 b. AL= CF=0 c. AL= CF=1 d. AL= CF=0 e. AL= CF=1 Q#1 AX contains a number between Write code to complement the corresponding bit in BX. For example if AX contains 6; complement the 6th bit of BX. (Note: First bit in BX is at 0th position and last bit is at 15th position) Solution: [org 0x0100] mov ax,3 ;suppose ax contain 3 mov dx,1 ; initial value for complement with bx cmp ax,0 ;if ax contain 0 je complement ; go for complement ist bit mov cx,ax shl dx,cl complement: xor bx,dx ;other wise move the value in cx ; shift 1 to left for number value in ax ;perform comlement operation mov ax,4ch int 21h Q#2 Suppose that AX=0x3412, BX=0x7856, CX= 0x1CAB, and SP=0x100. Given the contents of AX, BX, CX, and SP after executing the following instructions: PUSH AX PUSH BX XCHG AX, CX POP CX PUSH AX POP BX SOLUTION: AX BX CX SP

48 PUSH AX 0x3412 0x7856 0x1CAB 0xFE PUSH BX 0x3412 0x7856 0x1CAB 0XFC XCHG AX,CX 0x1CAB 0x7856 0x3412 0XFC POP CX 0x1CAB 0x7856 0x7856 0xFE PUSH AX 0x1CAB 0x7856 0x7856 0XFC POP BX 0x1CAB 0x1CAB 0x7856 0xFE Identify the problems in the following instructions and correct them by replacing them with one or two instruction having the same effect. v. mov [05], [ 24] ; Memory to memory move is illegal in Intel architecture. The correct instructions for this operation could be mov ax, [24] mov [24],ax vi. mov [label1], 501 ; Constant to memory move is illegal in Intel architecture. The correct instruction could be mov ax,501 mov [label1],ax vii. mov bx, al ; Size mismatch i.e. bx is 16 bit register and al is 8 bit register. The correct statement could be mov bx, ax or mov bl, al viii. mov ax, [si+di+100] ; Addition of two index register in one memory access is disallowed. We can do this operation by addition of index and base register. mov ax,[si+ bx+100] ix. mov bx,[bs+bp+200] ; Addition of two based register in one memory access is disallowed. We can do this operation by addition of index and base register. mov ax,[bp+ si+100] Write a program to calculate the square of 10 by using a loop that adds 10 to the accumulator 10 times. Solution: [org 0x0100] mov bx,10 mov cx,10 mov ax,0 l1: add ax, bx sub cx, 1 jnz l1 mov [total], ax mov ax,0x4c00 int 0x21 total: dw 0 If AX=8FFF and BX=0FFF and cmp ax, bx is executed, which of the following jumps will be taken? Each part is independent of others. Also give the value of Z, S, and C flags. i. jg greater ii. jl smaller iii. ja above iv. jb below Instructions Jump ZF SF CF

49 Jg greater Not taken Jl smaller Taken Ja above Taken Jb below Not taken a. As an application of the shift and rotate instruction, let s consider the problem of reversing the bit pattern in a byte or word. For example, if AL contains , we want to make it Write the code that reverses the bit pattern in AL register. b. Show the values of each register which you have used in your program after the each iteration of shifting or rotating bits with the following pattern. No of iteration Values of Register 1 Values of Register 2 Values of Register 3 1 st iteration... 2 nd iteration Solution: (a) [ORG 0X100] MOV AL, b MOV BL,0 MOV CX, 8 REV: SHL AL, 1 RCR BL, 1 LOOP REV MOV AL, BL MOV AX, 0x4c00 INT 0x21 Solution (b) CX AL BL 1 st iteration nd iteration rd iteration th iteration th iteration th iteration th iteration th iteration th iteration Write a program to swap every pair of bits in the AX register. Solution: [org 0x0100] mov ax, b mov bx,0 mov dx, 0 ; initialization mov bx, ax ; get a copy of ax and bx, b ; bx now has 01, 45, 89, 1213 bits rol bx, 2 mov dx, ax ; get a copy of ax and dx, b ; dx now has 23, 67, 1011, 1415 bits ror dx,2 mov cx, 0 mov cx, bx or cx, dx mov ax, cx ; ORing of bx and dx will produce desired result ; ax now has the result end: mov ax, 4c00h int 21h

50 Write a program to count the number of 1 bits in BX, without changing BX. put the answer in AX and use ROL instruction only. Solution: XOR AX, AX MOV CX, 16 TOP: ROL BX, 1 JNC NEXT INC AX NEXT: LOOP TOP Calculate the physical memory address generated by the following segment offset pairs. i. 74F0:2123 Physical Address = Segment x10 + Offset Physical Address = 74F0 x Physical Address = 774F Physical Address = 77023h 0000:6727 Physical Address = Segment x10 + Offset Physical Address = 0000 x Physical Address = Physical Address = 6727h FFFF:4336 Physical Address = Segment x10 + Offset Physical Address = FFFF x Physical Address = FFFF Physical Address = h To make 20bit physical address we have to drop the carry bit so Physical Address = 04326h AB01:FFFF Physical Address = Segment x10 + Offset Physical Address = AB01 x10 + FFFF Physical Address = AB010 + FFFF Physical Address = BB00Fh 0FFF:FFFF Physical Address = Segment x10 + Offset Physical Address = 0FFF x10 + FFFF Physical Address = 0FFF0 + FFFF Physical Address = 1FFEFh A. Identify the problems in the following instructions and correct them by replacing them with one or two instruction having the same effect. x. mov [02], [ 22] ; Memory to memory move is illegal in Intel architecture. The correct instructions for this operation could be mov ax, [22] mov [22],ax xi. mov [wordvar], 20l ; Constant to memory move is illegal in Intel architecture. The correct instruction could be mov ax,201 mov [wordvar],ax xii. mov bx, al ; Size mismatch i.e. bx is 16 bit register and al is 8 bit register. The correct statement could be mov bx, ax or mov bl, al xiii. mov ax, [si+di+100]

51 ; Addition of two index register in one memory access is disallowed. We can do this operation by addition of index and base register. mov ax,[si+ bx+100] xiv. mov bx,[bs+bp+200] ; Addition of two based register in one memory access is disallowed. We can do this operation by addition of index and base register. mov ax,[bp+ si+100] a. Write a program in assembly language that calculate the factorial of a number where factorial is defined as: Factorial(x) = x*(x-1)*(x-2)*...*1 factorial (0) = 1 [org 0x0100] mov ax, 1 mov cx, 5 ; ax hold the factorial ; suppose cx contain the value for which factorial is to ; determined. top: mul cx loop top ; ax = ax * cx mov ax,0x4c00 int 0x21 ;terminate program b. If AX=8FFF and BX=0FFF and cmp ax, bx is executed, which of the following jumps will be taken? Each part is independent of others. Also give the value of Z, S, and C flags. a) jg greater b) jl smaller c) ja above d) jb below Instructions Jump ZF SF CF Jg greater Not taken Jl smaller Taken Ja above Taken Jb below Not taken a. What is the difference between shift right (SHR) and shit arithmetic right (SAR) instructions? The SAR instruction operates like SHR, with one difference, the msb retains its original value. b. What is the difference between AND and TEST instructions? The TEST instruction perform an AND operation of the destination with the source but does not change the destination contents c. The relations of CALL and RET instructions with PUSH and POP instructions. When CALL instruction is executed the PUSH operation is to be perfumed to save the address of next instruction and when the RET instruction is executed the POP operations is to be performed to get the return address of next instruction to be executed Write a sequence of instruction to do each of the following: a. Put the sum in AX Solution: MOV AX, 0 ; initialize AX MOV BX, 1 ; contain every added value WHILE_: CMP BX, 148 JG ENDWHILE_ ADD AX, BX ADD BX, 3 JMP WHILE_ ; compare with last vale ; AX hold the sum ; BX contain the new adding value ENDWHILE_: b. Put the sum in AX Solution: MOV AX, 0 ; initialize AX

52 MOV BX, 100 WHILE_: CMP BX, 5 JL ENDWHILE_ ADD AX, BX SUB BX, 5 JMP WHILE_ ; contain every adding value ; compare with last vale ; AX hold the sum ; BX contain the new adding value ENDWHILE_: ==================================================================================== 1. Identify the problems in the following instructions and correct them by replacing them with one or two instruction having the same effect. a. mov [02], [22] b. mov [wordvar], 20 c. mov bx, al d. mov ax, [si+di+100] Solution: a) mov ax, [22] mov [02], ax OR mov al, [22] mov [02], [al] b) mov al, 22 mov [wordvar], al c) mov bl, al d) Mov bx, si Mov ax, [bx+di+100] Write instructions to do the following. a. Copy contents of memory location with offset 0025 in the current data segment into AX. b. Copy AX into memory location with offset 0FFF in the current data segment. c. Move contents of memory location with offset 0010 to memory location with offset 002F in the current data segment. Solution: a. mov SI, 0x0025 mov AX, [SI] b. mov [DI], 0x0FFF mov [DI], AX c. mov DI, 0x002F mov SI, 0x0010 mov AX, [SI] mov [DI], AX

53 Replace the following invalid instructions with a single instruction that has the same effect. a. pop ip b. mov ip, L5 c. sub sp, 2 mov [ss:sp], ax d. mov ax, [ss:sp] add sp, 2 e. add sp, 6 mov ip, [ss:sp-6] Solution: a. ret b. jmp L5 c. push ax d. pop ax e. call As an application of the shift and rotate instruction, let s consider the problem of reversing the bit pattern in a byte or word. For example, if AL contains , we want to make it Write the code that reverses the bit pattern in AL register. Solution: MOV AL, b MOV BL,0 MOV CX, 8 REV: SHL AL, 1 RCR BL, 1 LOOP REV MOV AL, BL MOV AX, 0x4c00 INT 0x21 Consider the given block of code from an assembly language program. And suppose that AX= 1234h, BX= 5678h, CX= 9ABCh and SP= 100h. Give the contents of AX, BX, CX and SP after executing the following block of instructions. PUSH AX PUSH BX XCHG AX, CX POP CX PUSH AX POP BX VALUES AFTER THE EXECUTION OF INSTRUCTION Instructions AX BX CX SP Stack Top --- 0x1234 0x5678 0x9ABC 0x PUSH AX 0x1234 0x5678 0x9ABC 0x00FE 0x1234 PUSH BX 0x1234 0x5678 0x9ABC 0x00FC 0x5678 XCHG AX, CX 0x9ABC 0x5678 0x1234 0x00FC 0x5678 POP CX 0x9ABC 0x5678 0x5678 0x00FE 0x1234 PUSH AX 0x9ABC 0x5678 0x5678 0x00FC 0x9ABC POP BX 0x9ABC 0x9ABC 0x5678 0x00FE 0x1234 SO THE FINAL VALUES ARE 0x9ABC 0x9ABC 0x5678 0x00FE 0x1234h ===================================================================

54 Spring 2011 Latest Papers (Current) Paper No.1 Which flag affected by often AND operator Selective Bit Testing AND can be used to check whether particular bits of a number are set or not. Previously we used shifting and JC to test bits one by one. Now we introduce another way to test bits, which is more powerful in the sense that any bit can be tested anytime and not necessarily in order. AND can be applied on a destination with a 1-bit in the desired position and a source, which is to be checked. If the destination is zero as a result, which can be checked with a JZ instruction, the bit at the desired position in the source was clear. However the AND operation destroys the destination mask, which might be needed later as well. Therefore Intel provided us with another instruction analogous to CMP, which is non-destructive subtraction. This is the TEST instruction and is a non-destructive AND operation. It doesn t change the destination and only sets the flags according to the AND operation. By checking the flags, we can see if the desired bit was set or cleared. Question: Explain divide overflow error. Suppose higher word is stored in DX and the lower word in AX. If a large number is divided by a very small number it is possible that the quotient is larger than the space provided for it in the implied destination. In this case an interrupt is automatically generated and the program is usually terminated as a result. This is called a divide overflow error; just like the calculator shows an E when the result cannot be displayed. Question: for what purpose "INT4" is reserved. The interrupts reserved by the processor and having special functions in 8088 are listed below: INT 4, Arithmetic Overflow, change of sign bit The overflow flag is set if the sign bit unexpectedly changes as a result of a mathematical or logical instruction. However the overflow flag signals a real overflow only if the numbers in question are treated as signed numbers. So this interrupt is not automatically generated but as a result of a special instruction INTO (interrupt on overflow) if the overflow flag is set. Otherwise the INTO instruction behaves like a NOP (no operation). ======================================================= INT 0, Division by zero Meaning the quotient did not fit in the destination register. This is a bit different as this interrupt does not return to the next instruction, rather it returns to the same instruction that generated it, a DIV instruction of course. Here INT 0 is automatically generated by a DIV when a specific situation arises, there is no INT 0 instruction. INT 1, Trap, Single step Interrupt This interrupt is used in debugging with the trap flag. If the trap flag is set the Single Step Interrupt is generated after every instruction. By hooking this interrupt a debugger can get control after every instruction and display the registers etc was the first processor that has this ability to support debugging. INT 2, NMI-Non Maskable Interrupt

55 Real interrupts come from outside the processor. INT 0 is not real as it is generated from inside. For real interrupts there are two pins in the processor, the INT pin and the NMI pin. The processor can be directed to listen or not to listen to the INT pin. Consider a recording studio, when the recording is going on, doors are closed so that no interruption occurs, and when there is a break, the doors are opened so that if someone is waiting outside can come it. However if there is an urgency like fire outside then the door must be broken and the recording must not be catered for. For such situations is the NMI pin which informs about fatal hardware failures in the system and is tied to interrupt 2. INT pin can be masked but NMI cannot be masked. INT 3, Debug Interrupt The only special thing about this interrupt is that it has a single byte opcode and not a two byte combination where the second byte tells the interrupt number. This allows it to replace any instruction whatsoever. It is also used by the debugger and will be discussed in detail with the debugger working. Question: Double working of Exchange instruction with help of an example. xchg ax, [bx+si+2] ; exchange ax with second number What is the difference between LES and LDS intruction. 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. Paper No.2 Two form of String Moves Instruction? MOVS has the two forms MOVSB and MOVSW. REP allows the instruction be repeated CX times allowing blocks of memory to be copied. We will perform this copy of the video screen. Scrolling is the process when all the lines on the screen move one or more lines towards the top of towards the bottom and the new line that appears on the top or the bottom is cleared. Scrolling is a process on which string movement is naturally applicable. REP with MOVS will utilize the full processor power to do the scrolling in minimum time. Describe push & pop with help of example? PUSH PUSH decrements SP (the stack pointer) by two and then transfers a word from the source operand to the top of stack now pointed to by SP. PUSH often is used to place parameters on the stack before calling a procedure; more generally, it is the basic means of storing temporary data on the stack. POP POP transfers the word at the current top of stack (pointed to by SP) to the destination operand and then increments SP by two to point to the new top of stack. POP can be used to move temporary variables from the stack to registers or memory. Observe that the operand of PUSH is called a source operand since the data is moving to the stack from the

56 operand, while the operand of POP is called destination since data is moving from the stack to the operand. Question No: 20 ( Marks: 3 ) Describe the working of the CALL instruction with the reference of Stack. CALL CALL activates an out-of-line procedure, saving information on the stack to permit a RET (return) instruction in the procedure to transfer control back to the instruction following the CALL. For an intra segment direct CALL, SP is decremented by two and IP is pushed onto the stack. The target procedure s relative displacement from the CALL instruction is then added to the instruction pointer. For an inter segment direct CALL, SP is decremented by two, and CS is pushed onto the stack. CS is replaced by the segment word contained in the instruction. SP again is decremented by two. IP is pushed onto the stack and replaced by the offset word in the instruction. The out-of-line procedure is the temporary division, the concept of roundabout that we discussed. Near calls are also called intra segment calls, while far calls are called inter-segment calls. There are also versions that are called indirect calls; however they will be discuss later when they are used. Describe the working of the RET with the reference of Stack. RET RET (Return) transfers control from a procedure back to the instruction following the CALL that activated the procedure. RET pops the word at the top of the stack (pointed to by register SP) into the instruction pointer and increments SP by two. If RETF (inter segment RET) is used the word at the top of the stack is popped into the IP register and SP is incremented by two. The word at the new top of stack is popped into the CS register, and SP is again incremented by two. If an optional pop value has been specified, RET adds that value to SP. This feature may be used to discard parameters pushed onto the stack before the execution of the CALL instruction. Q3: what is stack n define with example? Stack Stack is a data structure that behaves in a first in last out manner. It can contain many elements and there is only one way in and out of the container. When an element is inserted it sits on top of all other elements and when an element is removed the one sitting at top of all others is removed first. To visualize the structure 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 can 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. The last thing pushed is popped out first; the last in first out behavior. How value of IP Register is saved & updated when call. instruction executed. Instruction Pointer (IP) 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. Playing with it is dangerous and needs special care. Program control instructions change the IP register. AX = 0x3412, BX=0x7856, CX= 0x1CAB, Sp=0x100 Give contents of AX, BX,CX,SP After creating instruction push AX, Push BX, chg, AX,CX, POP CX

57 How many parameter a subroutine can receive through stack PARAMETER PASSING THROUGH STACK Due to the limited number of registers, parameter passing by registers is constrained in two ways. The maximum parameters a subroutine can receive are seven when all the general registers are used. Also, with the subroutines are themselves limited in their use of registers, and this limited increases when the subroutine has to make a nested call thereby using certain registers as its parameters. Due to this, parameter passing by registers is not expandable and generalizable. However this is the fastest mechanism available for passing parameters and is used where speed is important. Considering stack as an alternate, we observe that whatever data is placed there, it stays there, and across function calls as well. For example the bubble sort subroutine needs an array address and the count of elements. If we place both of these on the stack, and call the subroutine afterwards, it will stay there. The subroutine is invoked with its return address on top of the stack and its parameters beneath it. To access the arguments from the stack, the immediate idea that strikes is to pop them off the stack. And this is the only possibility using the given set of information. However the first thing popped off the stack would be the return address and not the arguments. This is because the arguments were first pushed on the stack and the subroutine was called afterwards. The arguments cannot be popped without first popping the return address. If a heaving thing falls on someone s leg, the heavy thing is removed first and the leg is not pulled out to reduce the damage. Same is the case with our parameters on which the return address has fallen. Paper No.3 Mid-Term Past Papers (Updated Version) Short Question Paper (Set-1) Q What is difference between SHR and SAR instructions? SHR The SHR inserts a zero from the left and moves every bit one position to the right and copy the rightmost bit in the carry flag. SAR The SAR shift every bit one place to the right with a copy of the most significant bit left at the most significant place. The bit dropped from the right is caught in the carry basket. The sign bit is retained in this operation. ====================================================

58 The bit Shift Logical Right (SHR) The shift logical right operation inserts a zero from the left and moves every bit one position to the right and copies the rightmost bit in the carry flag. Imagine that there is a pipe filled to capacity with eight balls. The pipe is open from both ends and there is a basket at the right end to hold anything dropping from there. The operation of shift logical right is to force a white ball from the left end. The operation is depicted in the following illustration. White balls represent zero bits while black balls represent one bits. Sixteen bit shifting is done the same way with a pipe of double capacity. Shift Arithmetic Right (SAR) A signed number holds the sign in its most significant bit. If this bit was one a logical right shifting will change the sign of this number because of insertion of a zero from the left. The sign of a signed number should not change because of shifting. The operation of shift arithmetic right is therefore to shift every bit one place to the right with a copy of the most significant bit left at the most significant place. The bit dropped from the right is caught in the carry basket. The sign bit is retained in this operation. The operation is further illustrated below. The left shifting operation is basically multiplication by 2 while the right shifting operation is division by two. However for signed numbers division by two can be accomplished by using shift arithmetic right and not shift logical right. The left shift operation is equivalent to multiplication except when an important bit is dropped from the left. The overflow flag will signal this condition if it occurs and can be checked with JO. For division by 2 of a signed number logical right shifting will give a wrong answer for a negative number as the zero inserted from the left will change its sign. To retain the sign flag and still effectively divide by two the shift arithmetic right instruction must be used on signed numbers. Q Every charcther is displayed on the screen in the form of word. What each byte of this word represents? 2marks Answer: Upper bye represent Character code Lower byte represents character attributes like color. There is one word per character in which a byte is needed for the ASCII code and the other byte is used for the character s attributes discussed later. Now the first 80 words will correspond to the first row of the screen and the next 80 words will correspond to the next row. Q When the instruction push ax is excuted in decrement stack how the value of SP will change? Or Operation of PUSH..Marks 3 Answer: PUSH

59 PUSH decrements SP (the stack pointer) by two and then transfers a word from the source operand to the top of stack now pointed to by SP. PUSH often is used to place parameters on the stack before calling a procedure; more generally, it is the basic means of storing temporary data on the stack. Q Define address bus? 5 marks Answer: The group of bits that the processor uses to inform the memory about which element to read or write is collectively 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 always travels from processor to memory. This is because memory is a dumb device and cannot predict which element the processor at a particular instant of time needs. Data moves from both, processor to memory and memory to processor, so the data bus is bidirectional. Control bus is special and relatively complex, because different lines comprising it behave differently. Some take information from the processor to a peripheral and some take information from the peripheral to the processor. There can be certain events outside the processor that are of its interest. To bring information about these events the data bus cannot be used as it is owned by the processor and will only be used when the processor grants permission to use it. Therefore certain processors provide control lines to bring such information to processor s notice in the control bus. Knowing these signals in detail is unnecessary but the general idea of the control bus must be conceived in full. Q Explain the working of shift logical left SHL? 5 marks Answer: Shift Logical Left (SHL) / Shift Arithmetic Left (SAL) The shift logical left operation is the exact opposite of shift logical right. In this operation the zero bit is 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. The operation is again exemplified with the following illustration of ball and pipes. =========================================================> Short Question Paper (Set-2) Question No: 17 ( Marks: 1 ) Write any two control instructions. Program Control Instructions

60 The instruction pointer points to the next instruction and instructions run one after the other with the help of this register. We can say that the instructions are tied with one another. In some situations we don t want to follow this implied path and want to order the processor to break its flow if some condition becomes true instead of the spatially placed next instruction. In certain other cases we want the processor to first execute a separate block of code and then come back to resume processing where it left. These are instructions that control the program execution and flow by playing with the instruction pointer and altering its normal behavior to point to the next instruction. Some examples are: cmp ax, 0 jne 1234 We are changing the program flow to the instruction at 1234 address if the condition that we checked becomes true. Question No: 18 ( Marks: 1 ) RET instruction take how many arguments The RET The word return holds in its meaning that we are to return from where we came and need no explicit destination. Therefore RET takes no arguments and transfers control back to the instruction following the CALL that took us in this subroutine. Question No: 19 ( Marks: 2 ) Explain the fuction of rotate right (ROR) instruction Rotate Right (ROR) 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. This bit is also copied into the carry flag. The operation can be understood by imagining that the pipe used for shifting has been molded such that both ends coincide. Now when the first ball is forced to move forward, every ball moves one step forward with the last ball entering the pipe from its other end occupying the first ball s old position. The carry basket takes a snapshot of this ball leaving one end of the pipe and entering from the other. Question No: 21 ( Marks: 3 ) Write down the names of four segment registers? CS code Segment DS data Segment ES Extra Segment SS Stack Segment. Question No: 23 ( Marks: 5 ) Given that [BX+0x0100] Ds=0xFFF0 Calculate the physical address BX=0x0100 =========================================================>

61 Short Question Paper (Set-3) Q#21 Mark 2 What are the instructions used by assembly language for permanent and temporary diversions. However there are roundabouts on roads as well that take us back from where we started after having traveled on the boundary of the round. This is the concept of a temporary diversion. Two or more permanent diversions can take us back from where we started, just like two or more road turns can take us back to the starting point, but they are still permanent diversions in their nature. We need some way to implement the concept of temporary diversion in assembly language. We want to create a roundabout of bubble sort, another roundabout of our multiplication algorithm, so that we can enter into the roundabout whenever we need it and return back to wherever we left from after completing the round. These diversions are Call and RET 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#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

62 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. Q#26 Mark 5 Describe MOVS and CMPS instructions =========================================================> Short Question Paper (Set-4) What is direct addressing"? Direct addressing : A fixed offset is given in brackets and the memory at that offset is accessed. What is conditional jump"? The JNZ instruction is from the program control group and is a conditional jump, meaning that if the condition NZ is true (ZF=0) it will jump to the address mentioned and otherwise it will progress to the next instruction. It is a selection between two paths. If the condition is true go right and otherwise go left. Or we can say if the weather is hot, go this way, and if it is cold, go this way. Conditional jump is the most important instruction, as it gives the processor decision making capability, so it must be given a careful thought. Some processors call it branch, probably a more logical name for it, however the functionality is same. Intel chose to name it jump. How are strings handled"? Differentiate between SHR, SAL, SAR". Answered above Write a calculator for adding strings". =========================================================> Short Question Paper (Set-5) Q:1 data clear algorithum in assmly language code? 5 MARKS ; clear the screen [org 0x0100] mov ax, 0xb800 ; load video base in ax mov es, ax ; point es to video base mov di, 0 ; point di to top left column nextchar: mov word [es:di], 0x0720 ; clear next char on screen add di, 2 ; move to next screen location cmp di, 4000 ; has the whole screen cleared jne nextchar ; if no clear next position mov ax, 0x4c00 ; terminate program int 0x21

63 Q4: multiplication in assmbley language 5 marks For this purpose the multiplication routine written previously can be used. However we introduce an instruction of the 8088 microprocessor at this time that can multiply 8bit or 16bit numbers. MUL Instruction 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 and AL. 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. ; 4bit multiplication algorithm [org 0x100] jmp start multiplicand: db 13 ; 4bit multiplicand (8bit space) multiplier: db 5 ; 4bit multiplier result: db 0 ; 8bit result start: mov cl, 4 ; initialize bit count to four mov bl, [multiplicand] ; load multiplicand in bl mov dl, [multiplier] ; load multiplier in dl checkbit: shr dl, 1 ; move right most bit in carry jnc skip ; skip addition if bit is zero add [result], bl ; accumulate result skip: shl bl, 1 ; shift multiplicand left dec cl ; decrement bit count jnz checkbit ; repeat if bits left mov ax, 0x4c00 ; terminate program int 0x21 =========================================================> Short Question Paper (Set-6) Question No: 18 ( Marks: 2 ) For what purpose "INT 1" is reserved? INT 1, Trap, Single step Interrupt This interrupt is used in debugging with the trap flag. If the trap flag is set the Single Step Interrupt is generated after every instruction. By hooking this interrupt a debugger can get control after every instruction and display the registers etc was the first processor that has this ability to support debugging. Question No: 19 ( Marks: 2 ) Define implied operand? It is always in a particular register say the accumulator. It needs to not be mentioned in the instruction. Question No: 21 ( Marks: 3 ) Tell the Formula to scroll up the screen rep movsw scrollup: push bp mov bp,sp push ax push cx scroll up

64 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 of 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 Question No: 23 ( Marks: 5 ) Explain the process of ADC? Normal addition has two operands and the second operand is added to the first operand. However ADC has three operands. The third implied operand is the carry flag. The ADC instruction is specifically placed for extending the capability of ADD. Further more consider an instruction ADC AX, BX. Normal addition would have just added BX to AX, however ADC first adds the carry flag to AX and then adds BX to AX. Therefore the last carry is also included in the result. The lower halves of the two numbers to be added are first added with a normal addition. For the upper halves a normal addition would lose track of a possible carry from the lower halves and the answer would be wrong. If a carry was generated it should go to the upper half. Therefore the upper halves are added with an addition with carry instruction. =========================================================> Short Question Paper (Set-7) 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 Why REP prefix is generally not used with LODS instruction?

65 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. 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 = and bx = The important thing about these operations is that they are bitwise. This means that if and ax, bx instruction is given, then the operation of AND is applied on corresponding bits of AX and BX. There are 16 AND operations as a result; one for every bit of AX. Bit 0 of AX will be set if both its original value and Bit 0 of BX are set, bit 1 will be set if both its original value and Bit 1 of BX are set, and so on for the remaining bits. These operations are conducted in parallel on the sixteen bits. Explain the complete operation of Interrupt when it is generated. Interrupt is the result of an INTinstruction (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 =========================================================> Short Question Paper (Set-8) Question No: 17 ( Marks: 2 )

66 Why is it necessary to provide the segment and offset address in case of FAR jump? Segment and offset must be given to a far jump. Because, sometimes we may need to go from one code segment to another, and near and short jumps cannot take us there. Far jump must be used and a two byte segment and a two byte offset are given to it. It loads CS with the segment part and IP with the offset part. Question No: 18 ( Marks: 2 ) What s your understanding about Incrementing and Decrementing Stack? Whenever an element is pushed on the stack SP is decremented by two and whenever an element is popped on the stack SP is incremented by two. 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. As the 8088 stack works on word sized elements. Single bytes cannot be pushed or popped from the stack. Question No: 19 ( Marks: 2 ) IF DF=0 what its represent and IF DF=1 what its represent? The direction of movement is controlled with the Direction Flag (DF) in the flags register. If this flag is cleared DF=0, the direction is from lower addresses towards higher addresses and if this flag is set DF=1, the direction is from higher addresses to lower addresses. If DF is cleared, DF = 0 this is called the autoincrement mode of string instruction, and if DF is set, DF=1, this is called the autodecrement mode. There are two instructions to set and clear the direction flag. Question No: 20 ( Marks: 3 ) What is the Difference between CALL and RET The CALL instruction allows temporary diversion and therefore reusability of code. The word return holds in its meaning that we are to return from where we came and need no explicit destination. Therefore RET takes no arguments and transfers control back to the instruction following the CALL that took us in this subroutine. Question No: 21 ( Marks: 3 ) Question No: 22 ( Marks: 5 ) 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 since our architecture is limited to word operations. The algorithm we use consists of just two instructions and we name it extended shifting. num1: dd shl word [num1], 1 rcl word [num1+2], 1 The DD directive reserves a 32bit space in memory; however the value we placed there will fit in 16bits. So we can safely shift the number left 16 times. The least significant word is accessible at num1 and the most significant word is accessible at num1+2.

67 The two instructions are carefully crafted such that the first one shifts the lower word towards the left and the most significant bit of that word is dropped in carry. With the next instruction we push that dropped bit into the least significant bit of the next word effectively joining the two 16bit words. The final carry after the second instruction will be the most significant bit of the higher word, which for this number will always be zero. Question No: 23 ( Marks: 5 ) 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 =========================================================> Short Question Paper (Set-9) Question No: 17 ( Marks: 2 ) Define short jump 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. F2 is added to IP as a signed byte. If the byte is negative the complement is negated from IP otherwise the byte is added. Unconditional jumps can be short, near, and far. The far type is yet to be discussed. Conditional jumps can only be short. A short jump can go +127 bytes ahead in code and -128 bytes backwards and no more. This is the limitation of a byte in singed representation. Question No: 20 ( Marks: 3 ) What is the Difference between CALL and RET The CALL instruction allows temporary diversion and therefore reusability of code. The word return holds in its meaning that we are to return from where we came and need no explicit destination. Therefore RET takes no arguments and transfers control back to the instruction following the CALL that took us in this subroutine. =========================================================>

68 Short Question Paper (Set-11) 1. Stack is a _ data structure 2. Standard ASCII has 128 characters 3. Which bit is refer to the red component of foreground color (2 is answer) Which bit is refer to the red component of background color (6 is answer) 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 After the execution of instruction RET 2 increment or decrement II. Question of 5 marks regarding CMPS. below is the answer CMPS subtracts the source location DS:SI from the destination location ES:DI. Source and Destination are unaffected. SI and DI are updated accordingly. CMPS compares two blocks of memory for equality or inequality of the block. It subtracts byte by byte or word by word. If used with a REPE or a REPNE prefix is repeats as long as the blocks are same or as long as they are different. For example it can be used for find a substring. A substring is a string that is contained in another string. For example has is contained in Mary has a little lamp. Using CMPS we can do the operation of a complex loop in a single instruction. Only the REPE and REPNE prefixes are meaningful with this instruction =========================================================> Short Question Paper (Set-15) Q19 Write down the purpose of define byte? To declare a part of our program as holding data instead of instructions we need a couple of very basic but special assembler directives. The first directive is define byte written as db. db somevalue As a result a cell in memory will be reserved containing the desired value in it and it can be used in a variety of ways. Now we can add variables instead of constants. The other directive is define word or dw with the same syntax as db but reserving a whole word of 16 bits instead of a byte. There are directives to declare a double or a quad word as well but we will restrict ourselves to byte and word declarations for now. For single byte we use db and for two bytes we use dw. Q21 How two dimensional coordinate system of the screen is converted into the one dimensional memory? Q22 Write down the purpose of FAR Jump Far Jump Far jump is not position relative but is absolute. Both segment and offset must be given to a far jump. The previous two jumps were used to jump within a segment. Sometimes we may need to go from one code segment to another, and near and short jumps cannot take us there. Far jump must be used and a two byte segment and a two byte offset are given to it. It loads CS wit the segment part and IP with the offset part. Execution therefore resumes from that location in physical memory. The three instructions that have a far

69 form are JMP, CALL, and RET, are related to program control. Far capability makes intra segment control possible. Q23 How the value of stack pointer (sp) changes after every PUSH or POP instruction? =========================================================> Short Question Paper (Set-17) Explain AND, OR and XOR operations with truth tables. [ 5 marks ] Explain the complete operation of interrupt when it is generated. [ 5 marks ] Tell the formula to scroll up the screen. [ 3 marks ] Why we need to clear the stack? [ 3 marks ] From where lds si, [bp + 4] will load SI and DS? [ 2 marks ] Which two registers are changed during CALL statement execution: 1. IP only 2. IP and SP only 3. SP only BP and IP only =========================================================> Short Question Paper (Set-18) Q22 Which instruction is used to determine the zero byte in string? (2) Q23 (3) 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 foreground character 6 Red component of background color 5 Green component of background color 4 Blue component of background color 3 Intensity component of foreground color 2 Red component of foreground color 1 Green component of foreground color 0 Blue component of foreground color Q25 How the data is displayed on monitor screen? (5) The computer listens, sees, and speaks in numbers. Even a character is a number inside the computer. For example the keyboard is labeled with characters however when we press A, a specific number is transferred from the keyboard to the computer. Our program interprets that number as the character A. When the same number comes on display, the Video Graphics Adapter (VGA) in our computer shows the shape of A. Even the shape is stored in binary numbers with a one bit representing a pixel on the screen that is turned on and a zero bit representing a pixel that is not glowing. This example is considering a white on black display and no colors. This is the

70 way a shape is drawn on the screen. The interpretation of A is performed by the VGA card, while the monitor or CRT (cathode ray tube) only glows the pixels on and turns them off. The keyboard has a key labeled A and pressing it the screen shows A but all that happened inside was in numbers. Q26 (5) Write an assembly language program that clear the screen using the string instruction? 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 in normal attribute mov cx, 2000 ; number of screen locations cld ; auto increment mode 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 =========================================================> Short Question Paper (Set-19) MCQz Lecture Wise Solved MCQz Question # 1 There are three busses to communicate the processor and memory named as 1) : address bus.,data bus and data bus. 2) : addressing bus.,data bus and data bus. 3) : address bus.,datamove bus and data bus. 4) : address bus.,data bus and control bus.. Correct Option : 4 Question # 2 From : Lecture 1.

71 The address bus is unidirectional and address always travels from processor to memory. 1) : TRUE 2) : FALSE 3) : 4) : Correct Option : 1 Question # 3 From : Lecture 1 Data bus is bidirectional because 1) : To way 2) : 3) :. Data moves from both, processor to memory and memory to processor, Data moves from both, processor to memory and memory to data Bus, 4) : None of the Given Correct Option : 3 Question # 4 Control bus From : Lecture 1 1) : is Not Important 2) : is Important 3) : bidirectional 4) : unidirectional Correct Option : 3 Question # 5 From : Lecture 1.. A memory cell is an n-bit location to store data, normally also called a byte 1) : 4-bit 2) : 8-bit 3) : 6-bit 4) : 80-bit Correct Option : 2 Question # 6 From : Lecture 1. The number of bits in a cell is called the cell width. define the

72 memory completely. 1) : Cell width and number of cells, 2) : cell number and width of the cells, 3) : width 4) : Height Correct Option : 1 Question # 7 From : Lecture 1. for memory we define two dimensions. The first dimension defines how many bits are there in a single memory cell. 1) : parallel 2) : Vertical 3) : long 4) : short Correct Option : 1 Question # 8 From : Lecture 1. operation requires the same size of data bus and memory cell width. 1) : Normal 2) : Best and simplest 3) : first 4) : None of the Given Correct Option : 2 Question # 9 From : Lecture 1 Control bus is only the mechanism. The responsibility of sending the appropriate signals on the control bus to the memory is of the. 1) : Data Bus 2) : processor 3) : Address Bus 4) : None of the Given Correct Option : 2 Question # 10 From : Lecture 1 In total: dw 0 Opcode total is a..

73 1) : Literal 2) : Variable 3) : Label 4) : Starting point Correct Option : 3 Question # 11 From : Lecture C is a example of 1) : Shl 2) : sar 3) : Shr 4) : Sal Correct Option : 3 Question # 12 From : Lecture 10 C is a example of 1) : Shl 2) : sar 3) : Shr 4) : Sal Correct Option : 1 Question # 13 From : Lecture 10 ADC has operands. 1) : two 2) : three 3) : Five 4) : Zero Correct Option : 2 Question # 14 From : Lecture The basic purpose of a computer is to perform operations, and operations need. 1) : order 2) : nothing 3) : operands

74 4) : bit Correct Option : 3 Question # 15 From : Lecture 2. Registers are like a scratch pad ram inside the processor and their operation is very much like normal. 1) : Number 2) : opreations 3) : memory cells 4) : None of the Given Correct Option : 3 Question # 16 From : Lecture 2. There is a central register in every processor called the and The word size of a processor is defined by the width of its. 1) : accumulator,accumulator 2) : data bus,accumulator 3) : accumulator, Address Bus 4) : accumulator, memory Correct Option : 1 Question # 17 From : Lecture 2 does not hold data but holds the address of data 1) : Pointer, Segment, or Base Register 2) : Pointer, Index, or Base Register 3) : General Registers 4) : Instruction Pointer Correct Option : 2 Question # 18 From : Lecture 2 The program counter holds the address of the next instruction to be 1) : executed 2) : called 3) : deleted 4) : copy Correct From : Lecture 2..

75 Option : 1 Question # 19 There are types of instruction groups 1) : 4 2) : 5 3) : 3 4) : 2 Correct Option : 1 Question # 20 From : Lecture 2 These instructions are used to move data from one place to another. 1) : TRUE 2) : FALSE 3) : 4) : Correct Option : 1 Question # 21 From : Lecture 2 mov instruction is related to the Group. 1) : Arithmetic and Logic Instructions 2) : Data Movement Instructions 3) : Program Control Instructions 4) : Special Instructions Correct Option : 2 Question # 22 From : Lecture allow changing specific processor behaviors and are used to play with it. 1) : Special Instructions 2) : Data Movement Instructions 3) : Program Control Instructions 4) : Arithmetic and Logic Instructions Correct Option : 1 Question # 23 From : Lecture 2.

76 8088 is a 16bit processor with its accumulator and all registers of. 1) : 32 bits 2) : 6 bits 3) : 16 bits 4) : 64 bits Correct Option : 3 Question # 24 From : Lecture 2. The of a processor means the organization and functionalities of the registers it contains and the instructions that are valid on the processor. 1) : Manufactures 2) : architecture 3) : Deal 4) : None of the Given Correct Option : 2 Question # 25 From : Lecture 2 Intel IAPX88 Architecture is 1) : More than 25 old 2) : New 3) : Not Good 4) : None of the Given Correct Option : 1 Question # 26 From : Lecture 2 The iapx88 architecture consists of registers. 1) : 13 2) : 12 3) : 9 4) : 14 Correct Option : 4 Question # 27 From : Lecture 3 General Registers are 1) : AX, BX, CX, and DX 2) : XA, BX, CX, and DX...

77 3) : SS,SI and DI 4) : 3 Correct Option : 1 Question # 28 From : Lecture 3. AX means we are referring to the extended 16bit A register. Its upper and lower byte are separately accessible as. 1) : AH and AL 2) : A Lower and A Upper 3) : AL, AU 4) : AX Correct Option : 1 Question # 29 From : Lecture 3 AX is General purpose Register where A stands for. 1) : Acadmic 2) : Ado 3) : Architecture 4) : Accumulator Correct Option : 4 Question # 30 From : Lecture 3.. The B of BX stands for because of its role in memory addressing. 1) : Busy 2) : Base 3) : Better 4) : None of the Given Correct Option : 2 Question # 31 From : Lecture 3 The D of DX stands for Destination as it acts as the destination in. 1) : I/O operations 2) : operations 3) : memory cells 4) : Memory I/O operations Correct From : Lecture 3.

78 Option : 1 Question # 32. The C of CX stands for Counter as there are certain instructions that work with an automatic count in the. 1) : DI register 2) : BX register 3) : CX register 4) : DX register Correct Option : 3 Question # 33 From : Lecture 3. are the index registers of the Intel architecture which hold address of data and used in memory access. 1) : SI and SS 2) : PI and DI 3) : SI and IP 4) : SI and DI Correct Option : 4 Question # 34 From : Lecture 3. In Intel IAPX88 architecture is the special register containing the address of the next instruction to be executed. 1) : AX 2) : PI 3) : IP 4) : SI Correct Option : 3 Question # 35 From : Lecture 3 SP is a memory pointer and is used indirectly by a set of. 1) : instructions 2) : Pointers 3) : Indexes 4) : Variables Correct Option : 1 From : Lecture 3.

79 Question # 36. is also a memory pointer containing the address in a special area of memory called the stack. 1) : SP 2) : BP 3) : PB 4) : AC Correct Option : 2 Question # 37 From : Lecture 3 is bit wise significant and accordingly each bit is named separately. 1) : AX 2) : FS 3) : IP 4) : Flags Register Correct Option : 4 Question # 38 From : Lecture 3.. When two 16bit numbers are added the answer can be 17 bits long, this extra bit that won t fit in the target register is placed in the where it can be used and tested 1) : carry flag 2) : Parity Flag 3) : Auxiliary Carry 4) : Zero Flag Correct Option : 1 Question # 39 From : Lecture 3 Program is an ordered set of instructions for the processor. 1) : TRUE 2) : FALSE 3) : 4) : Correct Option : 1 From : Lecture 3..

80 Question # 40 For Intel Architecture operation destination, source is way of writing things. 1) : TRUE 2) : FALSE 3) : 4) : Correct Option : 1 Question # 41 From : Lecture 3 Operation code add ax, bx. 1) : Add the bx to ax and change the bx 2) : Add the ax to bx and change the ax 3) : Add the bx to ax and change the ax 4) : Add the bx to ax and change nothing Correct Option : 3 Question # 42 From : Lecture 3 The maximum memory iapx88 can access is. 1) : 1MB 2) : 2MB 3) : 3MB 4) : 128MB Correct Option : 1 Question # 43 From : Lecture 4... The maximum memory iapx88 can access is 1MB which can be accessed with. 1) : 18 bits 2) : 20 bits 3) : 16 bits 4) : 2 bits Correct Option : 2 Question # 44 From : Lecture 4 address of 1DED0 where the opcode B80500 is placed. 1) : physical memory.

81 2) : memory 3) : efective 4) : None of the Given Correct Option : 1 Question # 45 From : Lecture bit of Segment and Offset Addresses can be converted to 20bit Address i.e Segment Address with lower four bits zero + Offset Address with four bits zero = 20bit Physical Address 1) : Middle 2) : lower 3) : Top 4) : upper Correct Option : 4 Question # 46 From : Lecture 4. When adding two 20bit Addresses a carry if generated is dropped without being stored anywhere and the phenomenon is called address. 1) : wraparound 2) : mode 3) : ping 4) : error Correct Option : 1 Question # 47 From : Lecture 4 Segments can only be defined a 16byte boundaries called boundaries. 1) : segment 2) : paragraph 3) : Cell 4) : RAM Correct Option : 1 Question # 48 From : Lecture 4.. in a Program CS, DS, SS, and ES all had the same value in them. This is called. 1) : equel memory

82 2) : overlapping segments 3) : segments hidding 4) : overlapping SI Correct Option : 2 Question # 49 From : Lecture 4 db num1 size of the memory is 1) : 1byte 2) : 4bit 3) : 16bit 4) : 2byte Correct Option : 1 Question # 50 From : Lecture [org 0x0100] mov ax, [num1] ; load first number in ax mov bx, [num2] ; load second number in bx add ax, bx int 0x num1: dw num2: dw 10.. Comments for the 4 are : 1) : No comments Will be 2) : ; accumulate sum in add 3) : ; accumulate sum in ax 4) : ; accumulate sum in Bx Correct Option : 3 Question # 51 From : Lecture 5 In mov ax, bx is Addressing Modes. 1) : Immediate 2) : Indirect 3) : Direct 4) : Register Correct Option : 4 From : Lecture 5..

83 Question # 52 In mov ax, [bx] is Addressing Modes 1) : Based Register Indirect 2) : Indirect 3) : Base Indirect 4) : Immediate Correct Option : 1 Question # 53 From : Lecture 5 In mov ax, 5 is Addressing Modes 1) : Immediate 2) : Indirect 3) : Indirect 4) : Register Correct Option : 1 Question # 54 From : Lecture 6 In mov ax, [num1+bx] is ADDRESSING 1) : OFFSET+ Indirect 2) : Register + Direct 3) : Indirect + Reference 4) : BASEd REGISTER + OFFSET Correct Option : 4 Question # 55 From : Lecture 7... base + offset addressing gives This number which came as the result of addition is called the. 1) : Address 2) : mode 3) : effective address 4) : Physical Address Correct Option : 3 Question # 56 From : Lecture 7 mov ax, [cs:bx] associates for this one instruction 1) : CS with BX.

84 2) : BX with CS 3) : BX with AX 4) : None of the Given Correct Option : 2 Question # 57 From : Lecture 7 For example BX=0100 DS=FFF0 And Opcode are; move [bx+0x0100], Ax now what is the effective memory address; 1) : ) : ) : ) : 0x02 Correct Option : 2 Question # 58 From : Lecture 7 For example BX=0100 DS=FFF0 And Opcode are; move [bx+0x0100], Ax now what is the physical memory address; 1) : ) : 0x0100 3) : 0x ) : 0x Correct Option : 2 Question # 59 From : Lecture 7 In mov [1234], al is Addressing Modes. 1) : Immediate 2) : Indirect 3) : Direct 4) : Register Correct Option : 3 From : Lecture 8....

85 Question # 60 In mov [SI], AX is Addressing Modes. 1) : Basef Register Indirect 2) : Indirect 3) : Indexed Register Indirect 4) : Immediate Correct Option : 3 Question # 61 From : Lecture 8 In mov ax, [bx - Si] is ADDRESSING 1) : Basef Register Indirect 2) : Indirect 3) : Direct 4) : illegal Correct Option : 4 Question # 62 From : Lecture 8 In mov ax, [BL] there is error i.e. 1) : Address must be 16bit 2) : Address must be 8bit 3) : Address must be 4bit 4) : 8 bit to 16 bit move illegal Correct Option : 4 Question # 63 From : Lecture 8 In mov ax, [SI+DI] there is error i.e. 1) : Two indexes can t use as Memory Address 2) : index can t use as Memory Address 3) : I don't Know 4) : None of the Given Correct Option : 1 Question # 64 From : Lecture 8 In JNE and JNZ there is difference for only ; 1) : Programmer or Logic 2) : Assembler....

86 3) : Debugger 4) : IAPX88 Correct Option : 1 Question # 65 From : Lecture 9. JMP is Instruction that on executing take jump regardless of the state of all flags is called 1) : Jump 2) : Conditional jump 3) : Unconditional jump 4) : Stay Correct Option : 3 Question # 66 From : Lecture 9. When result of the source subtraction from the destination is zero, zero flag is set i.e. ZF=1 its mean that; 1) : DEST = SRC 2) : DEST!= SRC 3) : DEST < SRC 4) : DEST > SRC Correct Option : 1 Question # 67 From : Lecture 9. When an unsigned source is subtracted from an unsigned destination and the destination is smaller, borrow is needed which sets the. 1) : carry flag i.e CF = 0 2) : carry flag i.e CF = 1 3) : Carry Flag + ZF=1 4) : None of the Given Correct Option : 2 Question # 68 From : Lecture 9. In the case of unassigned source and destination when subtracting and in the result ZF =1 OR CR=1 then 1) : DEST = SRC 2) : DEST!= SRC

87 3) : UDEST? USRC 4) : DEST > SRC Correct Option : 3 Question # 69 From : Lecture 9. In the case of unassigned source and destination when subtracting and in the result ZF =0 AND CR=0 then 1) : DEST = SRC 2) : DEST!= SRC 3) : UDEST < USRC 4) : UDEST > USRC Correct Option : 4 Question # 70 From : Lecture 9. In the case of unassigned source and destination when subtracting and in the result CR=0 then 1) : DEST = SRC 2) : DEST!= SRC 3) : UDEST < USRC 4) : UDEST? USRC Correct Option : 4 Question # 71 From : Lecture 9. This jump is taken if the last arithmetic operation produced a zero in its destination. After a CMP it is taken if both operands were equal. 1) : Jump if zero(jz)/jump if equal(je) 2) : Jump if equal(je) 3) : Jump if zero(jz) 4) : No Jump fot This Correct Option : 1 Question # 72 From : Lecture 9. This jump is taken after a CMP if the unsigned source is smaller than or equal to the unsigned destination. 1) : JBE(Jump if not below or equal) 2) : JNA(Jump if not above)/jbe(jump if not below or equal) 3) : JNA(Jump if not above)

88 4) : No Jump fot This Correct Option : 2 From : Lecture 9. Question # 1 Numbers of any size can be added using a proper combination of. 1) : ADD and ADC 2) : ABD and ADC 3) : ADC and ADC 4) : None of the Given Correct Option : 1 Question # 2 From : Lecture 11 Like addition with carry there is an instruction to subtract with borrows called. 1) : SwB 2) : SBB 3) : SBC 4) : SBBC Correct Option : 2 Question # 3 From : Lecture 11.. if and ax, bx instruction is given, There are operations as a result 1) : 16 AND 2) : 17 AND 3) : 32 AND 4) : 8 AND Correct Option : 1 Question # 4 From : Lecture 12. can be used to check whether particular bits of a number are set

89 or not. 1) : AND 2) : OR 3) : XOR 4) : NOT Correct Option : 1 Question # 5 From : Lecture 12. can also be used as a masking operation to invert selective bits. 1) : AND 2) : OR 3) : XOR 4) : NOT Correct Option : 3 Question # 6 From : Lecture 12 Masking Operations are Selective Bit 1) : Clearing, XOR, Inversion and Testing 2) : Clearing, Setting, Inversion and Testing 3) : Clearing, XOR, AND and Testing 4) : None of the Given Correct Option : 2 Question # 7 From : Lecture 12 The instruction allows temporary diversion and therefore reusability of code. 1) : CALL 2) : RET 3) : AND 4) : XOR Correct Option : 1 Question # 8 From : Lecture CALL takes a label as and execution starts from that label, 1) : argument 2) : Lable

90 3) : TXt 4) : Register Correct Option : 1 Question # 9 From : Lecture 13. When the instruction is encountered and it takes execution back to the instruction following the CALL. 1) : CALL 2) : RET 3) : AND 4) : XOR Correct Option : 2 Question # 10 From : Lecture 13. Both the instructions are commonly used as a pair, however technically they are independent in their operation. 1) : RET and ADC 2) : Cal and SSb 3) : CALL and RET 4) : ADC and SSB Correct Option : 3 Question # 11 From : Lecture 13. The CALL mechanism breaks the thread of execution and does not change registers, except. 1) : SI 2) : IP 3) : DI 4) : SP Correct Option : 2 Question # 12 From : Lecture 13 Stack is a that behaves in a first in last out manner. 1) : Program 2) : data structure 3) : Heap 4) : None of the Given.

91 Correct Option : 2 Question # 13 From : Lecture 14. If is not available, stack clearing by the callee is a complicated process. 1) : CALL 2) : SBB 3) : RET n 4) : None of the Given Correct Option : 3 Question # 14 From : Lecture 14. When the stack will eventually become full, SP will reach 0, and thereafter wraparound producing unexpected results. This is called stack 1) : Overflow 2) : Leakage 3) : Error 4) : Pointer Correct Option : 1 Question # 15 From : Lecture 14 The pop operation makes a copy from the top of the stack into its. 1) : Register 2) : operand 3) : RET n 4) : Pointer Correct Option : 2 Question # 16 From : Lecture 14.. decrements SP (the stack pointer) by two and then transfers a word from the source operand to the top of stack 1) : PUSH 2) : POP 3) : CALL 4) : RET Correct From : Lecture 14

92 Option : 1 Question # 17. POP transfers the word at the current top of stack (pointed to by SP) to the destination operand and then SP by two to point to the new top of stack. 1) : increments 2) : dcrements 3) : ++ 4) : -- Correct Option : 1 Question # 18 From : Lecture 14. The trick is to use the and operations and save the callers value on the stack and recover it from there on return. 1) : POP, ADC 2) : CALL, RET 3) : CALL, RET n 4) : PUSH, POP Correct Option : 4 Question # 19 From : Lecture 14. To access the arguments from the stack, the immediate idea that strikes is to them off the stack. 1) : PUSH 2) : POP 3) : CALL 4) : Register Correct Option : 2 Question # 20 push bp we are From : Lecture 15 1) : sending bp copy to stack 2) : making bp copy from stack 3) : pushing bp on the stack 4) : doing nothing Correct From : Lecture 15.

93 Option : 3 Question # 21. Local Variables means variables that are used within the 1) : Subroutine 2) : Program 3) : CALL 4) : Label Correct Option : 1 Question # 22 From : Lecture 15. Standard ASCII has 128 characters with assigned numbers from. 1) : 1to 129 2) : 0 to 127 3) : 0 to 128 4) : None of the Given Correct Option : 2 Question # 23 From : Lecture 16. When is sent to the VGA card, it will turn pixels on and off in such a way that a visual representation of A appears on the screen. 1) : 0x60 2) : 0x90 3) : 0x30 4) : 0x40 Correct Option : 4 Question # 24 From : Lecture 16 Which bit is refer to the Blinking of foreground character 1) : 6 2) : 7 3) : 5 4) : 3 Correct Option : 2 Question # 25 From : Lecture 16..

94 Which bit is refer to the Intensity component of foreground color 1) : 4 2) : 5 3) : 3 4) : 7 Correct Option : 3 Question # 26 From : Lecture 16 Which bit is refer to the Green component of background color 1) : 1 2) : 5 3) : 3 4) : 7 Correct Option : 2 Question # 27 From : Lecture 16 Which bit is refer to the Green component of foreground color 1) : 1 2) : 5 3) : 3 4) : 7 Correct Option : 1 Question # 28 From : Lecture 16 String can be indicate bye given 1) : db 0x61, 0x61, 0x63 2) : db 'a', 'b', 'c' 3) : db 'abc' 4) : All of the above Correct Option : 4 Question # 29 From : Lecture The first form divides a 32bit number in DX:AX by its 16bit operand and stores the quotient in AX 1) : 16bit 2) : 17bit

95 3) : 32bit 4) : 64bit Correct Option : 1 Question # 30 From : Lecture 17 The (division) used in the process is integer division and not floating point division. 1) : DIV instruction 2) : ADC instruction 3) : SSB instruction 4) : DIVI instruction Correct Option : 1 Question # 31 From : Lecture 17.. (multiply) performs an unsigned multiplication of the source operand and the accumulator. 1) : Multi 2) : DIV 3) : MUL 4) : Move Correct Option : 3 Question # 32 From : Lecture 18 The desired location on the screen can be calculated with the following formulae. 1) : location = ( hypos * 80 + SP ) * 3 2) : location = ( hypos * 80 + slocation ) * 2 3) : location = ( hypos * 80 + epos ) * 2 4) : None of the Given Correct Option : 3 Question # 33 From : Lecture 18 To play with string there are 5 instructions that are 1) : STOS, LODS, CMPS, SCAS, and MOVS 2) : MUL, DIV, ADD, ADC and MOVE 3) : SSB, ADD, CMPS, ADC, and MOVS 4) : None of the Given..

96 Correct Option : 1 Question # 34 From : Lecture 18. 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. 1) : LODS 2) : STOS 3) : SCAS 4) : MOVE Correct Option : 2 Question # 35 From : Lecture 18. transfers a byte or word from the source location DS:SI to AL or AX and updates SI to point to the next location. 1) : LODS 2) : STOS 3) : SCAS 4) : MOVE Correct Option : 1 Question # 36 From : Lecture 18 compares a source byte or word in register AL or AX with the destination string element addressed by ES: DI and updates the flags. 1) : LODS 2) : STOS 3) : SCAS 4) : MOVE Correct Option : 3 Question # 37 From : Lecture 18.. repeat the following string instruction while the zero flag is set and REPNE or REPNZ repeat the following instruction while the zero flag is not set. 1) : REP or REPZ 2) : REPE or REPZ 3) : REPE or RPZ 4) : RPE or REPZ

97 Correct Option : 2 Question # 38 LES loads 1) : ES 2) : DS 3) : PS 4) : LS Correct Option : 1 Question # 39 LDS loads. 1) : ES 2) : DS 3) : PS 4) : LS Correct Option : 2 Question # 40 From : Lecture 18 From : Lecture 20 From : Lecture REP allows the instruction to be repeated times allowing blocks of memory to be copied. 1) : DX 2) : CX 3) : BX 4) : AX Correct Option : 2 Question # 41 From : Lecture 20 pops IP, then CS, and then FLAGS. 1) : Ret n 2) : REZA 3) : REPE 4) : IRET Correct Option : 4 From : Lecture 21..

98 Question # 42, Trap, Single step Interrupt 1) : INT 0 2) : INT 1 3) : INT 3 4) : INT 0 Correct Option : 2 Question # 43 From : Lecture 21,NMI-Non Maskable Interrupt 1) : INT 0 2) : INT 1 3) : INT 3 4) : INT 0 Correct Option : 3 Question # 44 From : Lecture 21.. To hook an interrupt we change the corresponding to that interrupt. 1) : SX 2) : vector 3) : AX 4) : BX Correct Option : 2 From : Lecture 22. Powered By: Group of Virtual's Experts Question # 1 pops IP, then CS, and then FLAGS. 1) : Ret n 2) : REZA 3) : REPE 4) : IRET Correct Option : 4 From : Lecture 21

99 Question # 2, Trap, Single step Interrupt 1) : INT 0 2) : INT 1 3) : INT 3 4) : INT 0 Correct Option : 2 Question # 3 From : Lecture 21,NMI-Non Maskable Interrupt 1) : INT 0 2) : INT 1 3) : INT 3 4) : INT 0 Correct Option : 3 Question # 4 From : Lecture To hook an interrupt we change the corresponding to that interrupt. 1) : SX 2) : vector 3) : AX 4) : BX Correct Option : 2 From : Lecture 22 ========================================================== ====================================================> MCQz (Set-1) In primitive form, the block processing instructions operate on of memory at one time 1 whole block 2 A single cell PG # 89 3 A single bit 4 Whole segment After the execution of STOSWB, the cx will be 1 Decremented by 1 pg 90 2 Decremented by 2 3 Incremented by 1 4 Incremented by 2

100 In STOSW instructions when DF is set S1 is 1 Decremented by 1 2 Decremented by 2 pg 90 3 Incremented by 1 4 Incremented by 2 Which bit of the attribute byte represents the intensity component of foreground color? 1 4th 2 5th 3 6th 4 3rd 7 Blinking of foreground character 6 Red component of background color 5 Green component of background color 4 Blue component of background color 3 Intensity component of foreground color 2 Red component of foreground color 1 Green component of foreground color 0 Blue component of foreground color Which of the following flags will be affected by Movsw: 1 DF 2 PF 3 ZF 4 Not effect on flag ====================================================> MCQz (Set-2) Question # 1 of 5 ( Start time: 06:03:30 PM ) Total Marks: 1 The execution of the instruction "mov word [ES : 160], 0x1230" will print a character on the screen at: Select correct option: First column of second row Second column of first row Second column of second row First column of third row Question # 2 of 5 ( Start time: 06:04:33 PM ) Total Marks: 1 Which bit of the attributes byte represents the blue component of foreground color? Select correct option: Question # 3 of 5 ( Start time: 06:05:36 PM ) Total Marks: 1 The clear screen operation initializes whole block of video memory to: Select correct option: Question # 4 of 5 ( Start time: 06:06:57 PM ) Total Marks: 1 When the operand of DIV instruction is of 16 bits then implied dividend will be of

101 Select correct option: 64-bits 32-bits 16-bits 8-bits Question # 5 of 5 ( Start time: 06:08:29 PM ) Total Marks: 1 Which of the following is the pair of register used to access memory in string instructions? Select correct option: DI and BP SI and BP DI and SI DS and SI ====================================================> MCQz (Set-3) Stack is a that behaves in a first in last out manner. Program data structure Heap None of the Given The physical address of the stack is obtained by SS:SI combination SS:SP combination ES:BP combination ES:SP combination Foreground and background parameter will be 32bits 16bits 8bits 4bits The clear screen operation initialize whole block of memory In STOSB instruction, when DF is Set, SI is Incremented by 1 Incremented by 2 Decremented by 1 Decremented by 2 Assembly language is: Low-level programming language High-level programming language Also known as machine language Not considered closer to the computer A 32 Bit processor has accumulator of bit

102 16 bit 32 bit 64 bit To transfer control back the RET instruction take 1 argument 1 argument 3 arguments No arguments RET is executed, it recovers the values from Register Stack Data segment Code segment To convert any digit to its ASCII representation Add 0x30 in the digit Subtract 0x30 from the digit Add 0x61 in the digit Subtract 0x61 from the digit The prevalent convention in most high level languages is stack clearing by the Caller Callee RET Stack After execution of JCXZ instruction CX will changed with flag affect. CF OF DF None of Above Execution of the instruction mov word [ES : 0], 0x0741 will print A appear on the top left of screen A appear on the top right of screen A appear on the center of screen A appear on the bottom left of screen if contains decimal -2 and BX contains decimal 2 then after the execution of instructions: CMP AX, BX JA label Jump will be taken Zero flag will set ZF will contain value -4 Jump will not be taken Which of the following options contain the set of instructions to open a window to the video memory? mov AX, 0xb008 mov ES, AX mov AX, 0xb800 mov ES, AX mov AX, 0x8b00

103 mov ES, AX mov AX, 0x800b mov ES, AX If D is 35 is shift to left 2 bits the new value Execution of the instruction mov word [ES : 0], 0x1230 will print the character color will Grean White Red Black ====================================================> MCQz (Set-4) One screen location corresponds to a Byte Word pg 80 Double byte Double word After the execution of PUSH AX statement AX register will reside on the stack A copy of AX will go on the stack pg 67 The value of AX disappear after moving on stack Stack will send an acceptance message physical address of the stack is obtained by SS:SP combination SS:SI combination SS:SP combination ES:BP combination

104 ES:SP combination If the address of memory location Num1 is 0117 and its content is 0005 then after execution of the instruction mov bx, Num1 bx will contain Num In STOS instruction, the implied source will always be in AL or AX registers pg 90 DL or DX registers BL or BX registers CL or CX registers The shift logical right operation inserts A zero at right A zero at left A one at right A one at right REP will always Increment CX by 1 Increment CX by 2 Decrement CX by 1 Decrement CX by 2 When an item is pushed on the decrementing stack, the top of the stack is First decremented and then element copied on to the stack First incremented and then element copied on to the stack Decremented after the element copied on to the stack Incremented after the element copied on to the stack

105 assembly the CX register is used normally as a register. source counter index pointer Which is the unidirectional bus? (I) Control Bus (II) Data Bus (III) Address Bus I only II only III only I and II only The basic function of SCAS instruction is to Compare Scan Sort Move data register holds the address of next instruction is to be executed Base pointer Code segment Source index Program counter JC and JNC test the flag. Carry pg 39 parity zero sign After the execution of REP instruction CX will be decremented then which of the following flags will be affected?

106 CF OF DF No flags will be affected In string manipulation whenever an instruction needs a memory source, which of the following will hold the pointer to it? ES: DI ES: BP DS:BP DS:SI pg 89 which bit sets the character "blinking" on the screen? If we want to divide a signed number by 2, this operation can better be accomplished by SHR SAR SHL SAL After the execution of STOSWB,the CX wil be.. Incremented by 1 Incremented by 2 Decremented by 1 pg 90 Decremented by 2 Each screen location corresponds to a word, the lower byte of this word contains The character code The attribute byte The parameters The dimensions The lower address contains the code while the higher one contains the attribute. In a video memory, each screen location corresponds to

107 One byte Two bytes Four bytes Eight bytes ====================================================> MCQz (Set-5) Question No: 1 ( Marks: 1 ) - Please choose one address of the stack is obtained by SS:SP combination SS:SI combination The physical SS:SP combination ES:BP combination ES:SP combination Question No: 2 ( Marks: 1 ) - Please choose one execution of instruction RET SP is incremented by 2 SP is incremented by 2 After the SP is decremented by 2 SP is incremented by 1 SP is decremented by 1 Question No: 3 ( Marks: 1 ) - Please choose one byte in the word designated for one screen location holds Character color on the screen The second The dimensions of the screen Character position on the screen Character color on the screen ASCII code of the character Question No: 4 ( Marks: 1 ) - Please choose one always Decrement CX by 1 Increment CX by 1 REP will

108 Increment CX by 2 Decrement CX by 1 Decrement CX by 2 Question No: 5 ( Marks: 1 ) - Please choose one function of SCAS instruction is to The basic Compare Compare Scan Sort Move data Question No: 6 ( Marks: 1 ) - Please choose one are used to store Index registers mediate result Question No: 7 ( Marks: 1 ) - Please choose one work independently and individually The bits of the gister Question No: 8 ( Marks: 1 ) - Please choose one digit to its ASCII representation Add 0x30 in the digit Add 0x30 in the digit To convert any Subtract 0x30 from the digit Add 0x61 in the digit Subtract 0x61 from the digit Question No: 9 ( Marks: 1 ) - Please choose one When a 32 bit number is divided by a 16 bit number, the quotient is of

109 4 bits 32 bits 16 bits 8 bits 4 bits Question No: 10 ( Marks: 1 ) - Please choose one number is divided by an 8 bit number, the quotient will be in AL AX AL AH DX When a 16 bit Question No: 11 ( Marks: 1 ) - Please choose one Which mathematical operation is dominant during the execution of SCAS instruction Division Division Multiplication Addition Subtraction Question No: 12 ( Marks: 1 ) - Please choose one If AX contains decimal -2 and BX contains decimal 2 then after the execution of instructions: CMP AX, BX JA label Zero flag will set Jump will be taken Zero flag will set ZF will contain value -4 Jump will not be taken Question No: 13 ( Marks: 1 ) - Please choose one The execution of the instruction mov word [ES : 160], 0x1230 will print a character 0 on the screen at First column of second row Second column of first row First column of second row Second column of second row First column of third row Question No: 14 ( Marks: 1 ) - Please choose one

110 If the direction of the processing of a string is from higher addresses towards lower addresses then DF is cleared ZF is cleared DF is cleared ZF is set DF is set Question No: 15 ( Marks: 1 ) - Please choose one instruction ADC has Operand(s) 3 The Question No: 16 ( Marks: 1 ) - Please choose one the attributes byte represents the red component of background color? 3 Which bit of ====================================================> MCQz (Set-6) 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

111 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 ====================================================> MCQz (Set-7) Question No: 1 ( Marks: 1 ) - Please choose one execution of SAR instruction After the The msb is replaced by a 0 The msb is replaced by 1 The msb retains its original value The msb is replaced by the value of CF Question No: 2 ( Marks: 1 ) - Please choose one the offset in the BP IP SP SI Question No: 3 ( Marks: 1 ) - Please choose one that executes in response to an INT instruction is called RETF will pop The routine ISR IRS ISP IRT

112 Question No: 4 ( Marks: 1 ) - Please choose one instruction of COM file must be at offset: 0x0010 0x0100 0x1000 0x0000 Question No: 5 ( Marks: 1 ) - Please choose one not position relative but is memory dependent Absolute temporary indirect The first Far jump is Question No: 6 ( Marks: 1 ) - Please choose one instructions allow moving data from memory to memory. Only string word indirect stack Question No: 7 ( Marks: 1 ) - Please choose one execution of instruction RET 2 After the SP is incremented by 2 SP is decremented by 2 SP is incremented by 4 SP is decremented by 4 Question No: 8 ( Marks: 1 ) - Please choose one instruction has DIV Two forms Three forms Four forms Five forms Question No: 9 ( Marks: 1 ) - Please choose one When the operand of DIV instruction is of 16 bits then implied dividend will be of

113 8 bits 16 bits 32 bits 64 bits Question No: 10 ( Marks: 1 ) - Please choose one execution of MOVS instruction which of the following registers are updated SI only After the DI only SI and DI only SI, DI and BP only Question No: 11 ( Marks: 1 ) - Please choose one architecture, whenever an element is pushed on the stack SP is decremented by 1 SP is decremented by 2 SP is decremented by 3 SP is decremented by 4 In 8088 Question No: 12 ( Marks: 1 ) - Please choose one When a very large number is divided by very small number so that the quotient is larger than the space provided, this is called Divide logical error Divide overflow error Divide syntax error An illegal instruction Question No: 13 ( Marks: 1 ) - Please choose one designated for one screen location, the higher address contains In the word The character code The attribute byte The parameters The dimensions Question No: 14 ( Marks: 1 ) - Please choose one Which of the following options contain the set of instructions to open a window to the video memory? mov AX, 0xb008 mov ES, AX mov AX, 0xb800

114 mov ES, AX mov AX, 0x8b00 mov ES, AX mov AX, 0x800b mov ES, AX Question No: 15 ( Marks: 1 ) - Please choose one memory, each screen location corresponds to One byte Two bytes Four bytes Eight bytes In a video Question No: 16 ( Marks: 1 ) - Please choose one The execution of the instruction mov word [ES : 0], 0x0741 will print character A on screen, background color of the screen will be Black Blue White Red ====================================================> MCQz (Set-8) Question No: 1 ( Marks: 1 ) - Please choose one contains 5 decimal then after two left shifts produces the value as Suppose AL Question No: 2 ( Marks: 1 ) - Please choose one instruction, the implied source will always be in In STOS AL or AX registers DL or DX registers BL or BX registers CL or CX registers Question No: 3 ( Marks: 1 ) - Please choose one execution of STOSW the CX will be After the Decremented by 1

115 Decremented by 2 Incremented by 1 Incremented by 2 Question No: 4 ( Marks: 1 ) - Please choose one function of SCAS instruction is to The basic Compare Scan Sort Move data Question No: 5 ( Marks: 1 ) - Please choose one unidirectional bus? (I) Control Bus (II) Data Bus (III) Address Bus Which is the Question No: 6 ( Marks: 1 ) - Please choose one of CMP is to The operation Question No: 7 ( Marks: 1 ) - Please choose one IP, SP, BP, SI, DI, and BX all can contain a offset. -bit -bit -bit -bit Question No: 8 ( Marks: 1 ) - Please choose one the CX register is used normally as a register. source counter index pointer The registers In assembly

116 Question No: 9 ( Marks: 1 ) - Please choose one All the addressing mechanisms in iapx88 return a number called address. effective faulty indirect direct Question No: 10 ( Marks: 1 ) - Please choose one the attributes byte represents the blue component of foreground color Question No: 11 ( Marks: 1 ) - Please choose one number is divided by a 16 bit number, the quotient will be stored in Which bit of When a 32 bit AX BX CX DX Question No: 12 ( Marks: 1 ) - Please choose one [num1], 5 is instruction. mov byte legal illegal stack based memory indirect Question No: 13 ( Marks: 1 ) - Please choose one Which of the following options contain the set of instructions to open a window to the video memory? mov AX, 0xb008 mov ES, AX mov AX, 0xb800 mov ES, AX mov AX, 0x8b00 mov ES, AX mov AX, 0x800b mov ES, AX Question No: 14 ( Marks: 1 ) - Please choose one The execution of the instruction mov word [ES : 0], 0x0741 will print character A on screen, color of the character will be Black White

117 Red Blue Question No: 15 ( Marks: 1 ) - Please choose one following flags will be affected by MOVSW? Which of the DF PF ZF No effect on flags Question No: 16 ( Marks: 1 ) - Please choose one the attributes byte represents the blue component of background color? Which bit of ====================================================> MCQz (Set-9) Question No: 1 ( Marks: 1 ) - Please choose one execution of SAR instruction After the The msb is replaced by a 0 The msb is replaced by 1 The msb retains its original value The msb is replaced by the value of CF Question No: 2 ( Marks: 1 ) - Please choose one the offset in the BP IP SP SI Question No: 3 ( Marks: 1 ) - Please choose one that executes in response to an INT instruction is called RETF will pop The routine ISR IRS ISP

118 IRT Question No: 4 ( Marks: 1 ) - Please choose one instruction of COM file must be at offset: 0x0010 0x0100 0x1000 0x0000 Question No: 5 ( Marks: 1 ) - Please choose one not position relative but is memory dependent Absolute temporary indirect The first Far jump is Question No: 6 ( Marks: 1 ) - Please choose one instructions allow moving data from memory to memory. Only string word indirect stack Question No: 7 ( Marks: 1 ) - Please choose one execution of instruction RET 2 After the SP is incremented by 2 SP is decremented by 2 SP is incremented by 4 SP is decremented by 4 Question No: 8 ( Marks: 1 ) - Please choose one instruction has DIV Two forms Three forms Four forms Five forms

119 Question No: 9 ( Marks: 1 ) - Please choose one operand of DIV instruction is of 16 bits then implied dividend will be of When the 8 bits 16 bits 32 bits pg bits Question No: 10 ( Marks: 1 ) - Please choose one execution of MOVS instruction which of the following registers are updated SI only After the DI only SI and DI only SI, DI and BP only Question No: 11 ( Marks: 1 ) - Please choose one architecture, whenever an element is pushed on the stack SP is decremented by 1 SP is decremented by 2 SP is decremented by 3 SP is decremented by 4 In 8088 Question No: 12 ( Marks: 1 ) - Please choose one When a very large number is divided by very small number so that the quotient is larger than the space provided, this is called Divide logical error Divide overflow error Divide syntax error An illegal instruction Question No: 13 ( Marks: 1 ) - Please choose one designated for one screen location, the higher address contains In the word The character code The attribute byte The parameters The dimensions Question No: 14 ( Marks: 1 ) - Please choose one Which of the following options contain the set of instructions to open a window to the video memory?

120 mov AX, 0xb008 mov ES, AX mov AX, 0xb800 mov ES, AX mov AX, 0x8b00 mov ES, AX mov AX, 0x800b mov ES, AX Question No: 15 ( Marks: 1 ) - Please choose one memory, each screen location corresponds to One byte Two bytes Four bytes Eight bytes In a video Question No: 16 ( Marks: 1 ) - Please choose one The execution of the instruction mov word [ES : 0], 0x0741 will print character A on screen, background color of the screen will be Black White Red Blue ====================================================> MCQz (Set-10)

121

122

123

124

125 ====================================================> MCQz (Set-11) Correct Answer is True:

126 Correct Answer is LIFO (Last in First out) Correct Answer is Move Memory to Memory

127 Correct Answer is DI and SI. Correct Answer is False.

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM FALL 2011 CS401 Assembly Language Q: Affected flag of AND operation

More information

CS401 Assembly Language Solved MCQS From Midterm Papers

CS401 Assembly Language Solved MCQS From Midterm Papers CS401 Assembly Language Solved MCQS From Midterm Papers May 14,2011 MC100401285 Moaaz.pk@gmail.com MC100401285@gmail.com PSMD01(IEMS) Question No:1 ( Marks: 1 ) - Please choose one The first instruction

More information

CS401 - Computer Architecture and Assembly Language Programming Glossary By

CS401 - Computer Architecture and Assembly Language Programming Glossary By CS401 - Computer Architecture and Assembly Language Programming Glossary By absolute address : A virtual (not physical) address within the process address space that is computed as an absolute number.

More information

if 2 16bit operands multiplied the result will be

if 2 16bit operands multiplied the result will be how many operands in ADC? ans:3 how 32 bit word is defined? ans define double if 2 16bit operands multiplied the result will be ans 32bit if div by ero occurs then?? ans div by zero int for software int

More information

Computer Architecture and Assembly Language Programming CS401 Lecture No: 1 Address, Data, and Control Buses A computer system comprises of a

Computer Architecture and Assembly Language Programming CS401 Lecture No: 1 Address, Data, and Control Buses A computer system comprises of a Computer Architecture and Assembly Language Programming CS401 Lecture No: 1 Address, Data, and Control Buses A computer system comprises of a processor, memory, and I/O devices. I/O is used for interfacing

More information

1. Introduction to Assembly Language

1. Introduction to Assembly Language www.vchowk.com 1. Introduction to Assembly Language Solved EXERCISE 1 Note: Dear fellows I tried my best to solve this exercise questions if there s any mistake or doubt in any question correct it and

More information

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY BACKGROUND 8086 CPU has 8 general purpose registers listed below: AX - the accumulator register (divided into AH / AL): 1. Generates shortest machine code 2. Arithmetic, logic and data transfer 3. One

More information

Intel 8086: Instruction Set

Intel 8086: Instruction Set IUST-EE (Chapter 6) Intel 8086: Instruction Set 1 Outline Instruction Set Data Transfer Instructions Arithmetic Instructions Bit Manipulation Instructions String Instructions Unconditional Transfer Instruction

More information

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad Introduction to MS-DOS Debugger DEBUG In this laboratory, we will use DEBUG program and learn how to: 1. Examine and modify the contents of the 8086 s internal registers, and dedicated parts of the memory

More information

Code segment Stack segment

Code segment Stack segment Registers Most of the registers contain data/instruction offsets within 64 KB memory segment. There are four different 64 KB segments for instructions, stack, data and extra data. To specify where in 1

More information

ADVANCE MICROPROCESSOR & INTERFACING

ADVANCE MICROPROCESSOR & INTERFACING VENUS INTERNATIONAL COLLEGE OF TECHNOLOGY Gandhinagar Department of Computer Enggineering ADVANCE MICROPROCESSOR & INTERFACING Name : Enroll no. : Class Year : 2014-15 : 5 th SEM C.E. VENUS INTERNATIONAL

More information

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine Computer Organization & Assembly Language Programming CSE 2312 Lecture 15 Addressing and Subroutine 1 Sections in 8088 Code TEXT section, for the processor instructions. DATA section for the initialization

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST 2 Date : 02/04/2018 Max Marks: 40 Subject & Code : Microprocessor (15CS44) Section : IV A and B Name of faculty: Deepti.C Time : 8:30 am-10:00 am Note: Note: Answer any five complete

More information

CC411: Introduction To Microprocessors

CC411: Introduction To Microprocessors CC411: Introduction To Microprocessors OBJECTIVES this chapter enables the student to: Describe the Intel family of microprocessors from 8085 to Pentium. In terms of bus size, physical memory & special

More information

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017) Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017) High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one

More information

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) UNIT I THE 8086 MICROPROCESSOR PART A (2 MARKS) 1. What are the functional

More information

EC 333 Microprocessor and Interfacing Techniques (3+1)

EC 333 Microprocessor and Interfacing Techniques (3+1) EC 333 Microprocessor and Interfacing Techniques (3+1) Lecture 6 8086/88 Microprocessor Programming (Arithmetic Instructions) Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC

More information

CS-202 Microprocessor and Assembly Language

CS-202 Microprocessor and Assembly Language CS-202 Microprocessor and Assembly Language Lecture 2 Introduction to 8086 Assembly Language Dr Hashim Ali Spring - 2019 Department of Computer Science and Engineering HITEC University Taxila!1 Lecture

More information

8086 INTERNAL ARCHITECTURE

8086 INTERNAL ARCHITECTURE 8086 INTERNAL ARCHITECTURE Segment 2 Intel 8086 Microprocessor The 8086 CPU is divided into two independent functional parts: a) The Bus interface unit (BIU) b) Execution Unit (EU) Dividing the work between

More information

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM EXPERIMENT WRITE UP AIM: Assembly language program for 16 bit BCD addition LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM TOOLS/SOFTWARE

More information

9/25/ Software & Hardware Architecture

9/25/ Software & Hardware Architecture 8086 Software & Hardware Architecture 1 INTRODUCTION It is a multipurpose programmable clock drive register based integrated electronic device, that reads binary instructions from a storage device called

More information

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans. INSTRUCTOR: ABDULMUTTALIB A H ALDOURI Conditional Jump Cond Unsigned Signed = JE : Jump Equal JE : Jump Equal ZF = 1 JZ : Jump Zero JZ : Jump Zero ZF = 1 JNZ : Jump Not Zero JNZ : Jump Not Zero ZF = 0

More information

Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2

Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2 COS2621/103/3/2012 Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2 School of Computing Solutions to self tests Bar code 2 Self-test A Question 1 Alternative 1 Which one of the

More information

PRACTICAL WORKBOOK. Department of Computer Engineering University of Lahore. Designed and Compiled by : Engineer Zahid Muneer. Batch.

PRACTICAL WORKBOOK. Department of Computer Engineering University of Lahore. Designed and Compiled by : Engineer Zahid Muneer. Batch. PRACTICAL WORKBOOK Computer Architecture and Organization Name : Year : Batch : Roll No : Department of Computer Engineering University of Lahore Designed and Compiled by : Engineer Zahid Muneer 1 Contents

More information

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000 Declaring Variables in Assembly Language As in Java, variables must be declared before they can be used Unlike Java, we do not specify a variable type in the declaration in assembly language Instead we

More information

Summer 2003 Lecture 4 06/14/03

Summer 2003 Lecture 4 06/14/03 Summer 2003 Lecture 4 06/14/03 LDS/LES/LSS General forms: lds reg,mem lseg reg,mem Load far pointer ~~ outside of current segment {E.g., load reg w/value @ mem, & seg w/mem+2 XCHG Exchange values General

More information

Basic Assembly SYSC-3006

Basic Assembly SYSC-3006 Basic Assembly Program Development Problem: convert ideas into executing program (binary image in memory) Program Development Process: tools to provide people-friendly way to do it. Tool chain: 1. Programming

More information

EC-333 Microprocessor and Interfacing Techniques

EC-333 Microprocessor and Interfacing Techniques EC-333 Microprocessor and Interfacing Techniques Lecture 4 Addressing Modes Dr Hashim Ali Spring - 2018 Department of Computer Science and Engineering HITEC University Taxila Slides taken from Computer

More information

3.1 DATA MOVEMENT INSTRUCTIONS 45

3.1 DATA MOVEMENT INSTRUCTIONS 45 3.1.1 General-Purpose Data Movement s 45 3.1.2 Stack Manipulation... 46 3.1.3 Type Conversion... 48 3.2.1 Addition and Subtraction... 51 3.1 DATA MOVEMENT INSTRUCTIONS 45 MOV (Move) transfers a byte, word,

More information

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 02/06/2018 Section 1 Weighting 40% of

More information

EEM336 Microprocessors I. Data Movement Instructions

EEM336 Microprocessors I. Data Movement Instructions EEM336 Microprocessors I Data Movement Instructions Introduction This chapter concentrates on common data movement instructions. 2 Chapter Objectives Upon completion of this chapter, you will be able to:

More information

Lecture (08) x86 programming 7

Lecture (08) x86 programming 7 Lecture (08) x86 programming 7 By: Dr. Ahmed ElShafee 1 Conditional jump: Conditional jumps are executed only if the specified conditions are true. Usually the condition specified by a conditional jump

More information

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil Microprocessor By Mrs. R.P.Chaudhari Mrs.P.S.Patil Chapter 1 Basics of Microprocessor CO-Draw Architecture Of 8085 Salient Features of 8085 It is a 8 bit microprocessor. It is manufactured with N-MOS technology.

More information

ORG ; TWO. Assembly Language Programming

ORG ; TWO. Assembly Language Programming Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify

More information

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Note: PUSHF / POPF have no operands The figure below shows that if (SS) = 3000H, (SP) = 0042H, so the execution of POP CX loads CX by the word 4050H form the stack segment. The SP is incremented by 2.

More information

icroprocessor istory of Microprocessor ntel 8086:

icroprocessor istory of Microprocessor ntel 8086: Microprocessor A microprocessor is an electronic device which computes on the given input similar to CPU of a computer. It is made by fabricating millions (or billions) of transistors on a single chip.

More information

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H. Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H. MOV AX, 5000H MOV DS, AX MOV AL, 20H MOV CL, 30H ADD AL, CL MOV CL, 10H MUL CL

More information

Chapter Four Instructions Set

Chapter Four Instructions Set Chapter Four Instructions set Instructions set 8086 has 117 instructions, these instructions divided into 6 groups: 1. Data transfer instructions 2. Arithmetic instructions 3. Logic instructions 4. Shift

More information

Question Bank Part-A UNIT I- THE 8086 MICROPROCESSOR 1. What is microprocessor? A microprocessor is a multipurpose, programmable, clock-driven, register-based electronic device that reads binary information

More information

Week /8086 Microprocessor Programming I

Week /8086 Microprocessor Programming I Week 4 8088/8086 Microprocessor Programming I Example. The PC Typewriter Write an 80x86 program to input keystrokes from the PC s keyboard and display the characters on the system monitor. Pressing any

More information

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU 5 Years Integrated M.Sc.(IT) Semester 4 060010402 System Programming Question Bank Unit 1: Introduction 1. Write the decimal equivalent for each integral power of 2 from 2! to 2!". 2. Convert the following

More information

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers. Lecture 5: Computer Organization Instruction Execution Computer Organization Addressing Buses Fetch-Execute Cycle Computer Organization CPU Control Unit U Input Output Memory Components Control Unit fetches

More information

Intel 8086 MICROPROCESSOR. By Y V S Murthy

Intel 8086 MICROPROCESSOR. By Y V S Murthy Intel 8086 MICROPROCESSOR By Y V S Murthy 1 Features It is a 16-bit μp. 8086 has a 20 bit address bus can access up to 2 20 memory locations (1 MB). It can support up to 64K I/O ports. It provides 14,

More information

Come and join us at WebLyceum

Come and join us at WebLyceum Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

More information

16-Bit Intel Processor Architecture

16-Bit Intel Processor Architecture IBM-PC Organization 16-Bit Intel Processor Architecture A-16 bit microprocessor can operate on 16 bits of data at a time. 8086/8088 have the simplest structure 8086/8088 have the same instruction set,

More information

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language 4345 Assembly Language Assembly Language Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology Assembly Language 3-1 Overview of Assembly Language Advantages: Faster as compared

More information

Experiment N o 8. String Handling Instructions

Experiment N o 8. String Handling Instructions Experiment N o 8 String Handling Instructions Introduction: In this experiment you will deal with string handling instructions, such as reading a string, moving a string from one memory location to another,

More information

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A Segment 4A Logic Instructions Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Course Instructor Mohammed Abdul kader Lecturer, EEE, IIUC Basic

More information

Intel 8086 MICROPROCESSOR ARCHITECTURE

Intel 8086 MICROPROCESSOR ARCHITECTURE Intel 8086 MICROPROCESSOR ARCHITECTURE 1 Features It is a 16-bit μp. 8086 has a 20 bit address bus can access up to 2 20 memory locations (1 MB). It can support up to 64K I/O ports. It provides 14, 16

More information

Week /8086 Microprocessor Programming II

Week /8086 Microprocessor Programming II Week 5 8088/8086 Microprocessor Programming II Quick Review Shift & Rotate C Target register or memory SHL/SAL 0 C SHR 0 SAR C Sign Bit 2 Examples Examples Ex. Ex. Ex. SHL dest, 1; SHL dest,cl; SHL dest,

More information

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler: Assembling, Linking and Executing 1) Assembling: - Assembling converts source program into object program if syntactically correct and generates an intermediate.obj file or module. - It calculates the

More information

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات 1) Input/output In computing, input/output or I/O, is the communication between an information processing system (such as a computer) and the outside world, possibly a human or another information processing

More information

Internal architecture of 8086

Internal architecture of 8086 Case Study: Intel Processors Internal architecture of 8086 Slide 1 Case Study: Intel Processors FEATURES OF 8086 It is a 16-bit μp. 8086 has a 20 bit address bus can access up to 220 memory locations (1

More information

CS401 - Computer Architecture and Assembly Language Programming FAQs By

CS401 - Computer Architecture and Assembly Language Programming FAQs By CS401 - Computer Architecture and Assembly Language Programming FAQs By What are Registers and why these are needed? Registers are like a scratch pad ram inside the processor and their operation is very

More information

UNIT 2 PROCESSORS ORGANIZATION CONT.

UNIT 2 PROCESSORS ORGANIZATION CONT. UNIT 2 PROCESSORS ORGANIZATION CONT. Types of Operand Addresses Numbers Integer/floating point Characters ASCII etc. Logical Data Bits or flags x86 Data Types Operands in 8 bit -Byte 16 bit- word 32 bit-

More information

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10] The following pages contain references for use during the exam: tables containing the x86 instruction set (covered so far) and condition codes. You do not need to submit these pages when you finish your

More information

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string. 1 od 5 17. 12. 2017 23:53 (https://github.com/schweigi/assembler-simulator) Introduction This simulator provides a simplified assembler syntax (based on NASM (http://www.nasm.us)) and is simulating a x86

More information

WINTER 12 EXAMINATION Subject Code : Model Answer Page No : / N. a) Describe the function of SID and SOD pins of 8085 microprocessor

WINTER 12 EXAMINATION Subject Code : Model Answer Page No : / N. a) Describe the function of SID and SOD pins of 8085 microprocessor Subject Code : Model Answer Page No : / N Q.1) SOLVE ANY FIVE : (20 MARKS) a) Describe the function of SID and SOD pins of 8085 microprocessor Ans: - SID: - (2 Mark) Serial Input Data SID pin is used to

More information

x86 architecture et similia

x86 architecture et similia x86 architecture et similia 1 FREELY INSPIRED FROM CLASS 6.828, MIT A full PC has: PC architecture 2 an x86 CPU with registers, execution unit, and memory management CPU chip pins include address and data

More information

8086 INSTRUCTION SET

8086 INSTRUCTION SET 8086 INSTRUCTION SET Complete 8086 instruction set Quick reference: AAA AAD AAM AAS ADC ADD AND CALL CBW CLC CLD CLI CMC CMP CMPSB CMPSW CWD DAA DAS DEC DIV HLT IDIV IMUL IN INC INT INTO I JA JAE JB JBE

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

Arithmetic Instructions

Arithmetic Instructions Segment 3C Arithmetic Instructions This topic covers the following instructions: Addition (ADD, INC, ADC) Subtraction (SUB, DEC, SBB,CMP) Multiplication (MUL, IMUL) Division (DIV, IDIV) BCD Arithmetic

More information

Module 3 Instruction Set Architecture (ISA)

Module 3 Instruction Set Architecture (ISA) Module 3 Instruction Set Architecture (ISA) I S A L E V E L E L E M E N T S O F I N S T R U C T I O N S I N S T R U C T I O N S T Y P E S N U M B E R O F A D D R E S S E S R E G I S T E R S T Y P E S O

More information

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY BACKGROUND Segment The "SEGMENT" and "ENDS" directives indicate to the assembler the beginning and ending of a segment and have the following format label SEGMENT [options] ;place the statements belonging

More information

Introduction to Microprocessor

Introduction to Microprocessor Introduction to Microprocessor The microprocessor is a general purpose programmable logic device. It is the brain of the computer and it performs all the computational tasks, calculations data processing

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Marking Scheme. Examination Paper. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 12/06/2017 Section 1 Weighting 40% of

More information

Memory address space is selected when which of the following instructions is given to the processor MOV DEC IN ADD My Ok Page # 115

Memory address space is selected when which of the following instructions is given to the processor MOV DEC IN ADD My Ok Page # 115 Muhammad Rizwan Ashraf 0300-7487664 bits of the work independently and individually index register base register flags register accumulator Page # 12 Motorola 68K processors have 23bit general purpose

More information

Chapter 3: Addressing Modes

Chapter 3: Addressing Modes Chapter 3: Addressing Modes Chapter 3 Addressing Modes Note: Adapted from (Author Slides) Instructor: Prof. Dr. Khalid A. Darabkh 2 Introduction Efficient software development for the microprocessor requires

More information

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Computer Architecture and System Software Lecture 06: Assembly Language Programming Computer Architecture and System Software Lecture 06: Assembly Language Programming Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Assignment 3 due thursday Midterm

More information

EC-333 Microprocessor and Interfacing Techniques

EC-333 Microprocessor and Interfacing Techniques EC-333 Microprocessor and Interfacing Techniques Lecture 3 The Microprocessor and its Architecture Dr Hashim Ali Fall - 2018 Department of Computer Science and Engineering HITEC University Taxila Slides

More information

8088/8086 Programming Integer Instructions and Computations

8088/8086 Programming Integer Instructions and Computations Unit3 reference 2 8088/8086 Programming Integer Instructions and Computations Introduction Up to this point we have studied the software architecture of the 8088 and 8086 microprocessors, their instruction

More information

UNIT III MICROPROCESSORS AND MICROCONTROLLERS MATERIAL OVERVIEW: Addressing Modes of Assembler Directives. Procedures and Macros

UNIT III MICROPROCESSORS AND MICROCONTROLLERS MATERIAL OVERVIEW: Addressing Modes of Assembler Directives. Procedures and Macros OVERVIEW: UNIT III Addressing Modes of 8086 Assembler Directives Procedures and Macros Instruction Set of 8086 Data Transfer Group Arithmetic Group Logical Instructions Rotate and Shift instructions Loop

More information

Architecture and components of Computer System Execution of program instructions

Architecture and components of Computer System Execution of program instructions Execution of program instructions Microprocessor realizes each program instruction as the sequence of the following simple steps: 1. fetch next instruction or its part from memory and placing it in the

More information

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte.

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte. SHEET-2 ANSWERS [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte. TITLE PROG2-3 PURPOSE: TRANSFER 6 WORDS OF DATA PAGE 60,132.MODEL SMALL.STACK 64.DATA ORG 10H DATA_IN DW 234DH,

More information

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN ROAD MAP SDK-86 Intel 8086 Features 8086 Block Diagram 8086 Architecture Bus Interface Unit Execution Unit 8086 Architecture 8086 Programmer s Model Flag Register

More information

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to: Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This chapter explains the operation of the stack

More information

Ethical Hacking. Assembly Language Tutorial

Ethical Hacking. Assembly Language Tutorial Ethical Hacking Assembly Language Tutorial Number Systems Memory in a computer consists of numbers Computer memory does not store these numbers in decimal (base 10) Because it greatly simplifies the hardware,

More information

Computer Architecture 1 ح 303

Computer Architecture 1 ح 303 Lecture 4 A. Addressing MODES 1. Introduction to assembly language programming: Program is a sequence of commands used to tell a microcomputer what to do. Each command in a program is an instruction Programs

More information

Basic Execution Environment

Basic Execution Environment Basic Execution Environment 3 CHAPTER 3 BASIC EXECUTION ENVIRONMENT This chapter describes the basic execution environment of an Intel Architecture processor as seen by assembly-language programmers.

More information

Section 001. Read this before starting!

Section 001. Read this before starting! Points missed: Student's Name: Total score: /100 points East Tennessee State University Department of Computer and Information Sciences CSCI 2150 (Tarnoff) Computer Organization TEST 3 for Fall Semester,

More information

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)

More information

Arithmetic and Logic Instructions And Programs

Arithmetic and Logic Instructions And Programs Dec Hex Bin 3 3 00000011 ORG ; FOUR Arithmetic and Logic Instructions And Programs OBJECTIVES this chapter enables the student to: Demonstrate how 8-bit and 16-bit unsigned numbers are added in the x86.

More information

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit 1 1. introduction The internal function of 8086 processor are partitioned logically into processing units,bus Interface Unit(BIU)

More information

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS 1. Object of laboratory The x86 microprocessor family has a large variety of instructions that allow instruction flow control. We have 4 categories: jump,

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1 Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD 21252 rkarne@towson.edu 11/12/2014 Slide 1 Intel x86 Aseembly Language Assembly Language Assembly Language

More information

Assignment no:4 on chapter no :3 : Instruction set of 8086

Assignment no:4 on chapter no :3 : Instruction set of 8086 Assignment no:4 on chapter no :3 : Instruction set of 8086 1) Describe any two string operation instruction of 8086 with syntax & one example of each. 1] REP: REP is a prefix which is written before one

More information

Experiment 3 3 Basic Input Output

Experiment 3 3 Basic Input Output Experiment 3 3 Basic Input Output Introduction The aim of this experiment is to introduce the use of input/output through the DOS interrupt. Objectives: INT Instruction Keyboard access using DOS function

More information

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 1: Assembly Language Terms & Directives

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 1: Assembly Language Terms & Directives Introduction: US06CCSC04: Introduction to Microprocessors and A microprocessor is the chip containing some control and logic circuits that is capable of a making arithmetic and logical decision based on

More information

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Computer Architecture and System Software Lecture 07: Assembly Language Programming Computer Architecture and System Software Lecture 07: Assembly Language Programming Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements New assembly examples uploaded to

More information

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 3: Assembly Language Instructions II

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 3: Assembly Language Instructions II Unconditional & Conditional JUMP instructions: Conditional JUMP instructions: JA/JNBE Jump if above / Jump if not Below or Equal These two mnemonics represent the same instruction. The term above and below

More information

Northern India Engineering College, Delhi (GGSIP University) PAPER I

Northern India Engineering College, Delhi (GGSIP University) PAPER I PAPER I Q1.Explain IVT? ANS. interrupt vector table is a memory space for storing starting addresses of all the interrupt service routine. It stores CS:IP PAIR corresponding to each ISR. An interrupt vector

More information

Assembly Language Programming of 8085

Assembly Language Programming of 8085 Assembly Language Programming of 8085 Topics 1. Introduction 2. Programming model of 8085 3. Instruction set of 8085 4. Example Programs 5. Addressing modes of 8085 6. Instruction & Data Formats of 8085

More information

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM EXPERIMENT WRITE UP AIM: Assembly language program to search a number in given array. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

More information

Addressing Modes on the x86

Addressing Modes on the x86 Addressing Modes on the x86 register addressing mode mov ax, ax, mov ax, bx mov ax, cx mov ax, dx constant addressing mode mov ax, 25 mov bx, 195 mov cx, 2056 mov dx, 1000 accessing data in memory There

More information

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters Lecture 10 Jump Loop Homework 3 Outputting prompts Reading single characters Transfer of Control The CPU loads and executes programs sequentially. You d like to be able to implement if statements, gotos,

More information

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 8400: Computer Systems. Machine-Level Representation of Programs CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages

More information

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

Q1: Multiple choice / 20 Q2: Protected mode memory accesses 16.317: Microprocessor-Based Systems I Summer 2012 Exam 2 August 1, 2012 Name: ID #: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic devices (e.g.,

More information

Program Control Instructions

Program Control Instructions Program Control Instructions Introduction This chapter explains the program control instructions, including the jumps, calls, returns, interrupts, and machine control instructions. This chapter also presents

More information