12
Opcode Address Instruction Format 15 14 12 0 I 11 Addressing mode MID-I Examinations Feb 2018 Course: B. Tech Branch:CSE Year: II Subject: CO Semester :II Date of Exam:07-02-18 AN Max.Marks 30 TIME :02:00PM TO 03:00PM Answer ANY TWO of the following 2 x 15 = 30 Marks SCHEME OF EVALUATION 1.A)What is an instruction code?[2M] Definition of instruction code -----1 mark Define basic fields of instruction---1 mark An instruction code is a group of bits that instruct the computer to perform a specific operation., each having its own particular interpretation. A computer instruction is often divided into two parts, each having its own particular interpretation. The basic parts of the instruction are opcode and address field. An opcode (Operation Code) that specifies the operation for that instruction. An address that specifies the registers and/or locations in memory to use for that operation

Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

Opcode AddressInstruction Format

15 14 12 0I 11

Addressing mode

MID-I Examinations Feb 2018Course: B. Tech Branch:CSE Year: II Subject: CO Semester :II Date of Exam:07-02-18 AN Max.Marks 30 TIME :02:00PM TO 03:00PM

Answer ANY TWO of the following 2 x 15 = 30 Marks

SCHEME OF EVALUATION

1.A)What is an instruction code?[2M]

Definition of instruction code -----1 mark Define basic fields of instruction---1 mark

An instruction code is a group of bits that instruct the computer to perform a specific operation., each having its own particular interpretation. A computer instruction is often divided into two parts, each having its own

particular interpretation. The basic parts of the instruction are opcode and address field.

An opcode (Operation Code) that specifies the operation for that instruction. An address that specifies the registers and/or locations in memory to use for that

operation

Page 2: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

1.B)Differentiate between Von Neumann architecture and Harvard architecture?[3marks]

Define Von Neumann architecture -----1.5marks Define Harvard architecture ------1.5marks

In the von Neumann architecture programs and data should be stored together in thesame memory area of the computer. Instructions are carried out sequentially, oneinstruction at atime.A von Neumann architecture has only one bus which is used for both data transfers andinstruction fetches, and therefore data transfers and instruction fetches must be scheduled- they can not be performed at the same time.

Harvard architecture uses physically separate storage for programs and data.Harvard architecture has separate data and instruction busses, allowing transfers to beperformed simultaneously on both busses.

1 C)Explain different types of computer instructions with their formats? [10 marks]

Define Computer instruction ----------1Mark

A computer instruction is a group of bits that instruct the computer to perform a specific operation.

Basic Computer Instruction Formats- --- 4 marks

Page 3: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

15 12 11 0I/O operation1 1 1 1

List and explain the instructions ------5 marks

2A) Discuss about control flags? [2Marks]

Define Direction flags,trap flag,interrupt flag----------2 marks

8086 has 3 control flags

D- Dirction flag: This is used by string manipulation instructions. If this flag bit is ‘0’,the string is processed beginning from the lowest address to highest address , i.eautoincrementing mode. Otherwise , the string is processed from the highest addresstowards thre lowest address , i.e autodecrement mode.

Page 4: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

T- Trap flag: If the flag is set, the processor enters the single step execution mode. A trapinterrupt is generated after execution of each instruction. The processor executes thecurrent instruction and the control is transferred to the Trap interrupt service routine.

I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU,otherwise they are ignored.

2B) Write about Register to Register instruction format in 8086? [3Marks]

Define instruction format--------1 Mark

A machine language instruction format has one or more number of fields associated withit. Opcode field, operand fields(Address fields)

Operation code filed or opcde field, which indicates the type of the operation to be performed by the CPU.

Operand fields specify where the data is available to perform the operation specified by the opcode field.

Define

Define Register to Register instruction format------2 marks

This format is 2 bytes long. The first byte of the code specifies the operation code and the

width of the operand specifies by w bit. The second byte of the opcode shows the registeroperands and R/M field.

The register represented by the REG field is one of the operands. The R/M field specifies

another register or memory location, ie., the other operand. The register specified byREG is a source operand if , else it is a destination operand.

2 C)Describe the data transfer instructions in 8086? [10 marks]

List the different categories of 8086 instructions- --- 2 marks

The 8086 instructions are categorized into the following types,

Data transfer instructions

Arithmetic and Logical Instructions

Branch Instructions

Loop instructions

Machine control instructions

Flag manipulation instructions

Shift and Rotate instructions

String Instructions

List the Data transfer instructions-------------2 Marks

Page 5: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

Data transfer instructions are used to transfer data from source operand to destination operand. The instructions are MOV, PUSH, POP, XCHG, IN, OUT XLAT ,LEA ,LDS/LES ,LAHF, SAHF,PUSHF, POPF.

Define the data transfer instructions with example------------6 Marks

MOVThis instruction copies a word or a byte of data from some source to a destination. This destination can be a register or a memory location. The source can be a register, a memory location or an immediate number.Example MOV AX,BXMOV AX,500HMOV AX,[SI]MOV AX,[2000H]MOV AX,50H[BX]Direct loading of the segment registers with immediate data is not permitted.PUSH : Push to stackThis instruction pushes the contents of the specified register/memory location on to the stack. The stack pointer is decremented by 2, after each execution of this instruction.ExamplePUSH AXPUSH DXPUSH [5000H]POP : Pop from stack This instruction when executed, loads the specified register/memory location with the contents ofthe memory location of which the address is formed using the current stack segment and stack pointer. The stack pointer is incremented by 2.ExamplePOP AXPOP DSPOP [5000H]XCHG : Exchange byte or wordThis instruction exchange the contentrs of a specified source and destination operandsExampleXCHG [5000H], AXXCHG BX,AXXLAT Translate byte using look up tableExampleLEA BX, TABLE1MOV AL, 04HXLATSimple input and output port transfer instructionsIN : Copy a byte or word from a specified port to accumulator.ExampleIN AL, 03HIN AX, DXOUT: Copy a byte or word from accumulator specified port.ExampleOUT 03H, ALOUT DX, AXLEA : Load effective address of the operands in specified register.Eg.LEA reg, offsetLDS : Load DS register with other specified register from memory[reg] [mem][DS] [mem +2]Eg.LDS reg, memLES : Load ES register and other specified register from memory.[reg] [mem][reg] [mem +2]Eg.

Page 6: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

LES reg, mem

FLAG TRANSFER INSTRUCTIONS LAHFLoad AH with the low byte of the flag register.[AH] <—- [Flags low byte]Eg LAHFSAHFStore AH register to low byte of flag register.[Flags low byte] <—- [AH]Eg. SAHFPUSHFCopy flag register to top of stack.[SP] <—- [SP]-2[[SP]] <— [ Flags]Eg. PUSHFPOPFCopy word at top of stack to flag register.[Flags] <—- [[SP]][SP] <— [SP+2]

3 A) List the disadvantages with machine level programming. [2 Marks]

List the disadvantages of machine level programming-------2 marks

The process is complicated and time consuming. The chance of error being committed are more ate the machine level in hand coding and

entering the program byte by byte into the system. Debugging a program at the machine level is more difficult. The programs are not understood by everyone and the results are not stored in a user

friendly form

3 B) Write an assembly language program to add a data byte located at offset 0500H in 2000H segment to another data byte available at 0600H in the same segment and store the result at 0700H in the same segment. [3 marks]

Program-----2 marks

Comeents----1 mark

MOV AX,2000H ;Initialize DS with the value 2000H

MOV DS,AX

MOV AX,[5000H] ;Get first data byte from 0500H

ADD AX,[0600H] ;Add this to the second byte from 0600H

MOV [0700H],AX ;Store Ax in 0700H

HLT ;Stop

3 C) What is an assembly language program? Explain the advantages of assembly languageprogramming over machine language? [5 Marks]

Define assembly language program-----2 Marks

An assembly language is a low-level programming language for microprocessors and otherprogrammable devices. It is not just a single language, but rather a group of languages. An

Page 7: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

assembly language implements a symbolic representation of the machine code needed toprogram a given CPU architecture.

advantages of assembly language programming over machine language---3 Marks

The programming in assembly language is not so complicated as in machine language

because the function of coding is performed by an assembler. The chances of error being committed are less because the mnemonics are used instead of

numerical opcodes. It is easier to enter an assembly language program. As the mnemonics are purpose suggestive the debugging is easier. The constants and address location can be labeled with suggestive labels hence imparting

a more friendly interface to user. Advanced assemblers provide facilities like macros, listsetc . making the task of programming much easier.

The memory control is in the hands of users as in machine language., The results may be stored in a more user friendly form The flexibility of programming is more in assembly language programming as compared

to machine language because of advanced facilities available with the modernassemblers.

3 D) Explain the steps are involved to develop an assembly language program.[5 marks]

List the components involved to develop the assembly language program-----2 marks

Editors: any editor like notepad

Assembler: MASM,TASM,NASM

Linker: LINK

Debugger: DEBUG

Steps to develop an assembly language program with diagram -------3 marks

Define assembler,linker,debugger Enter the program in editor and save the file with extension .asm, this file should be

saved in the directory which contains the masm, link and debug executable files. Assemble the program with masm assembler .

Assembler is a program which converts assembly level language into machine levellanguage . The input is .asm file and produce .obj file.

Run the link program, the input is .obj file and produce .exe file Run the debug program to debug and troubleshooting the program

4A) Explain symbolic micro instruction? [2 Marks]

Define the fields of symbolic micro instruction-------2 marks

Symbols are used in microinstructions as in assembly language A symbolic microprogram can be translated into its binary equivalent by a

microprogram assembler. The symbolic micro instruction contains 5 fields

five fields: label; micro-ops; CD; BR; AD

Label: may be empty or may specify a symbolic

address terminated with a colon

Page 8: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

Micro-ops: consists of one, two, or three symbols

separated by commas

CD: one of {U, I, S, Z}, where U: Unconditional Branch

I: Indirect address bit

S: Sign of AC

Z: Zero value in AC

BR: one of {JMP, CALL, RET, MAP}

AD: one of {Symbolic address, NEXT, empty}

4 B) Discuss about control memory and its organization? 3M

Define control memory----------2 marks

Organization of control memory --------1 Marks

A memory that is part of a control unit is referred to as a control memory. It stores the

micro programs for the microprogrammed control unit. The list of micro instructions is called as micro program.

Page 9: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

4C) Explain in detail the addressing modes of 8086 with examples. [10 marks]

Define addressing mode----2 marks

List the addressing modes-----2 marks

Addressing mode indicates a way of locating data or operands. According to flow of instruction execution, the instructions may may be

categorised as

1. Sequential control flow instructions

2. Control transfer instructions

Sequential control flow instructions are the instructions which after execution,

transfer control to the next instruction appearing immediately after it(in the sequence) in the program.

Page 10: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

Example: Arithmetic instructions,logical,data transfer and processor control instructions

The control tranfer instructions, transfer control to some predefined address or

the address somehow specified in the instruction, after the execution. Example: CALL,RET,JUMP,INT

Addressing modes for Sequential control flow instructions: Immediate Addressing Mode Direct Addressing Mode Regiter Addressing Mode Register Indirect Addressing Mode Indexed Addressing Mode Register Relative Addressing Mode Based Indexed Addressing Mode Relative Based Indexed Addressing Mode

ADDRESSING MODES for Control transfer instructions Intrasegment Direct Addressing Mode Intrasegment Indirect Addressing Mode Intersegment Direct Addressing Mode Intersegment Indirect Addressing Mode

Define the each addressing mode with example-----6 marks

Immediate Addressing Mode :In this addressing mode, immediate data is a part of instruction, and appears in theform of successive byte or bytes.

Example MOV AX, 0050H ; AX <---- 0050H MOV BL,06H ; BL <----06H

Direct Addressing Mode :

In the direct addressing mode, a 16 bit address (offset) is directly specified in the instruction as a part of it.

ex.

MOV AX, [ 1000 H ]

Here data resides in a memory location in the data segment, whose effective address is

DS X 10H + 1000H

Regiter Addressing Mode:

In register addressing mode, the data is stored in a register and it is referred using the particular register. All the registers except IP may be used in this mode.

ex. MOV AX,BX ; AX <----- BX

Register Indirect Addressing Mode :

In this addressing mode, the address of the memory location which contains data or operand is determined in an indirect way using offset registers. The offset address of data is in either BX or SI or DI register. The default segment register is either DS or ES.

e.g. MOV AX, [BX]

Page 11: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

The data is present in a memory location in DS whose offset is in BX. The effective address is DS X 10H + [BX]

Indexed Addressing Mode :

In this addressing mode offset of the operand is stored in one of the index register. DS and ES are the default segments for index registers SI and DI respectively

e.g. MOV AX, [SI] The effective address of the data is DS X 10H + [SI]

Register Relative Addressing Mode In this addressing mode the data is available at an effective address formed by adding an 8-bit or 16-bit displacement with the content of any one of the registers BX, BP, SI and DI in the default either DS or ES segment. e.g. MOV AX, 50H [BX] The effective address of the data is DS X 10H + 50H + [BX]

Based Indexed Addressing Mode :In this addressing mode the effective address of the data is formed by adding the content of a base register (any one of BX or BP) to the content of an index register(any one of SI or DI). The default segment register may be ES or DS. Ex: MOV AX, [BX] [SI] The effective address of the data is DS X 10H + [BX] + [SI]

Relative Based Indexed Addressing Mode :

The effective address is formed by adding an 8-bit or 16-bit displacement with the sum ofcontents of any one of the base register (BX or BP) and any one of the index registers in adefault segment. Example:

MOV AX, 50H [BX] [SI] The effective address of the data is DS X 10H + [BX] + [SI] + 50H

Intrasegment Direct Addressing Mode :

In this mode, the address to which the control is to be transferred lies in the same segmentin which the control transfer instruction lies and appears directly in the instruction as an immediate displacement value. In this addressing mode, the displacement is computed relative to the content of the instruction pointer IP. The effective address to which the control will be transferred is given by the sum of 8 or 16 bit displacement and current content of IP. In case of jump instruction, if the signed displacement (d) is of 8 bits (i.e. –128 to +127) 16 bits (i.e. –32768<+32768), it is termed as long jump. Example: JMP SHORT LABEL

JMP NEAR PTR LABEL Intrasegment Indirect Addressing Mode :

In this mode, the displacement to which the control is to be transferred, is in the same segment in which the control transfer instruction lies, but it is passed to the instruction indirectly.

Here, the branch address is found as the content of a register or a memory location.

This addressing mode may be used in unconditional branch instructions.

Page 12: Instruction Format 15 14 12 0 I Opcode 11 Address Addressing … · 2018-02-08 · I-Interrupt flag: if this flag is set, the maskable interrupts are recognized by the CPU, otherwise

Example: JMP [BX]

Intersegment Direct Addressing Mode :

In this mode, the address to which the control is to be transferred is in a different segment. This addressing mode provides a means of branching from one code segment to another code segment.

Here, the CS and IP of the destination address are specified directly in the instruction.

Example: JMP 5000H : 2000H Jump to effective address 2000H in segment 5000H

Intersegment Indirect Addressing Mode :

In this mode, the address to which the control is to be transferred lies in a different segment and it is passed to the instruction indirectly, i.e. contents of a memory block containing four bytes, i.e. IP (LSB), IP (MSB), CS (LSB) and CS (MSB) sequentially. The starting address of the memory block may be referred using any of the addressing modes, except immediate mode. Example: JMP [2000H] Jump to an address in the other segment specified at effective address 2000H in DS, that points to the memory block as said above