Instruction Design & format 1 - 5 Flashcards

GeeksForGeeks Instruction Design and Format: Section 1 - 5

1
Q

Instruction Set Architecture (ISA)

A

part of the abstract model of a computer that defines how the CPU is controlled by the software. The ISA acts as an interface between the hardware and the software, specifying both what the processor is capable of doing as well as how it gets done.

The ISA provides the only way through which a user is able to interact with the hardware. It can be viewed as a programmer’s manual because it’s the portion of the machine that’s visible to the assembly language programmer, the compiler writer, and the application programmer.

The ISA defines the supported data types, the registers, how the hardware manages main memory, key features (such as virtual memory), which instructions a microprocessor can execute, and the input/output model of multiple ISA implementations. The ISA can be extended by adding instructions or other capabilities, or by adding support for larger addresses and data values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Memory address register(MAR)

A

It is connected to the address lines of the system bus. It specifies the address in memory for a read or write operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Memory Buffer Register (MBR)

A

t is connected to the data lines of the system bus. It contains the value to be stored in memory or the last value read from the memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Program Counter (PC)

A

Holds the address of the next instruction to be fetched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Instruction Register (IR)

A

Holds the last instruction fetched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In computer organization, an instruction cycle, also known as a fetch-decode-execute cycle, is the basic operation performed by a central processing unit (CPU) to execute an instruction. The instruction cycle consists of several steps, each of which performs a specific function in the execution of the instruction. The major steps in the instruction cycle are:

A

Fetch: In the fetch cycle, the CPU retrieves the instruction from memory. The instruction is typically stored at the address specified by the program counter (PC). The PC is then incremented to point to the next instruction in memory.

Decode: In the decode cycle, the CPU interprets the instruction and determines what operation needs to be performed. This involves identifying the opcode and any operands that are needed to execute the instruction.

Execute: In the execute cycle, the CPU performs the operation specified by the instruction. This may involve reading or writing data from or to memory, performing arithmetic or logic operations on data, or manipulating the control flow of the program.

There are also some additional steps that may be performed during the instruction cycle, depending on the CPU architecture and instruction set:

Fetch operands: In some CPUs, the operands needed for an instruction are fetched during a separate cycle before the execute cycle. This is called the fetch operands cycle.

Store results: In some CPUs, the results of an instruction are stored during a separate cycle after the execute cycle. This is called the store results cycle.

Interrupt handling: In some CPUs, interrupt handling may occur during any cycle of the instruction cycle. An interrupt is a signal that the CPU receives from an external device or software that requires immediate attention. When an interrupt occurs, the CPU suspends the current instruction and executes an interrupt handler to service the interrupt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The Instruction Cycle

A

Each phase of Instruction Cycle can be decomposed into a sequence of elementary micro-operations. In the above examples, there is one sequence each for the Fetch, Indirect, Execute and Interrupt Cycles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Indirect Cycle

A

always followed by the Execute Cycle. The Interrupt Cycle is always followed by the Fetch Cycle. For both fetch and execute cycles, the next cycle depends on the state of the system.

We assumed a new 2-bit register called Instruction Cycle Code (ICC). The ICC designates the state of processor in terms of which portion of the cycle it is in:-

00 : Fetch Cycle
01 : Indirect Cycle
10 : Execute Cycle
11 : Interrupt Cycle

At the end of the each cycles, the ICC is set appropriately. The above flowchart of Instruction Cycle describes the complete sequence of micro-operations, depending only on the instruction sequence and the interrupt pattern(this is a simplified example). The operation of the processor is described as the performance of a sequence of micro-operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fetch Cycle

A

At the beginning of the fetch cycle, the address of the next instruction to be executed is in the Program Counter(PC).

MAR
MBR
PC 00000000001100100
IR
AC

Step 1: The address in the program counter is moved to the memory address register(MAR), as this is the only register which is connected to address lines of the system bus.

MAR 00000000001100100
MBR
PC 00000000001100100
IR
AC

Step 2: The address in MAR is placed on the address bus, now the control unit issues a READ command on the control bus, and the result appears on the data bus and is then copied into the memory buffer register(MBR). Program counter is incremented by one, to get ready for the next instruction. (These two action can be performed simultaneously to save time)

MAR 00000000001100100
MBR 00010000000100100
PC 00000000001100101
IR
AC

Step 3: The content of the MBR is moved to the instruction register(IR).

MAR 00000000001100100
MBR 00010000000100000
PC 00000000001100100
IR 00010000000100000
AC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Thus, a simple Fetch Cycle consist of three steps and four micro-operation. Symbolically, we can write these sequence of events as follows:-

A

t1: MAR <- PC
t2: MBR <- Memory
PC <- (PC) + 1
t3: IR <- (MBR)

Here ‘I’ is the instruction length. The notations (t1, t2, t3) represents successive time units. We assume that a clock is available for timing purposes and it emits regularly spaced clock pulses. Each clock pulse defines a time unit. Thus, all time units are of equal duration. Each micro-operation can be performed within the time of a single time unit.
First time unit: Move the contents of the PC to MAR.
Second time unit: Move contents of memory location specified by MAR to MBR. Increment content of PC by I.
Third time unit: Move contents of MBR to IR.
Note: Second and third micro-operations both take place during the second time unit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The indirect Cycles

A

Once an instruction is fetched, the next step is to fetch source operands. Source Operand is being fetched by indirect addressing( it can be fetched by any addressing mode, here its done by indirect addressing). Register-based operands need not be fetched. Once the opcode is executed, a similar process may be needed to store the result in main memory. Following micro-operations takes place:-

t1: MAR <- (IR(address))
t2: MBR <- Memory
t3: IR(address <- (MBR(Address))

Step 1: The address field of the instruction is transferred to the MAR. This is used to fetch the address of the operand.
Step 2: The address field of the IR is updated from the MBR.(So that it now contains a direct addressing rather than indirect addressing)
Step 3: The IR is now in the state, as if indirect addressing has not been occurred.
Note: Now IR is ready for the execute cycle, but it skips that cycle for a moment to consider the Interrupt Cycle .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The executable Cycle

A

The other three cycles(Fetch, Indirect and Interrupt) are simple and predictable. Each of them requires simple, small and fixed sequence of micro-operation. In each case same micro-operation are repeated each time around.
Execute Cycle is different from them. Like, for a machine with N different opcodes there are N different sequence of micro-operations that can occur.
Lets take an hypothetical example :-
consider an add instruction:

ADD R , X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The indirect Cycles

A

Once an instruction is fetched, the next step is to fetch source operands. Source Operand is being fetched by indirect addressing( it can be fetched by any addressing mode, here its done by indirect addressing). Register-based operands need not be fetched. Once the opcode is executed, a similar process may be needed to store the result in main memory. Following micro-operations takes place:-

t1: MAR <- (IR(address))
t2: MBR <- Memory
t3: IR(address <- (MBR(Address))

Step 1: The address field of the instruction is transferred to the MAR. This is used to fetch the address of the operand.
Step 2: The address field of the IR is updated from the MBR.(So that it now contains a direct addressing rather than indirect addressing)
Step 3: The IR is now in the state, as if indirect addressing has not been occurred.
Note: Now IR is ready for the execute cycle, but it skips that cycle for a moment to consider the Interrupt Cycle .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The executable Cycle

A

The other three cycles(Fetch, Indirect and Interrupt) are simple and predictable. Each of them requires simple, small and fixed sequence of micro-operation. In each case same micro-operation are repeated each time around.
Execute Cycle is different from them. Like, for a machine with N different opcodes there are N different sequence of micro-operations that can occur.
Lets take an hypothetical example :-
consider an add instruction:

ADD R , X

Here, this instruction adds the content of location X to register R. Corresponding micro-operation will be:-

t1: MAR <- (IR(adress))
t2: MBR <- Memory
t3: R <- (R) + (MBR)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

We begin with the IR containing the ADD instruction.
Step 1: The address portion of IR is loaded into the MAR.
Step 2: The address field of the IR is updated from the MBR, so the reference memory location is read.
Step 3: Now, the contents of R and MBR are added by the ALU.
Lets take a complex example :-

ISZ C

A

Here, the content of location X is incremented by 1. If the result is 0, the next instruction will be skipped. Corresponding sequence of micro-operation will be :-

t1: MAR <- (IR(adress))
t2: MBR <- memory
t3: MBR <- (MBR) + 1
t4: memory <- (MBR)

If ((MBR) = 0) then
(PC <- (PC) + i)

Here, the PC is incremented if (MBR) = 0. This test (is MBR equal to zero or not) and action (PC is incremented by 1) can be implemented as one micro-operation.
Note : This test and action micro-operation can be performed during the same time unit during which the updated value MBR is stored back to memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The Interrupt Cycle:
At the completion of the Execute Cycle, a test is made to determine whether any enabled interrupt has occurred or not. If an enabled interrupt has occurred then Interrupt Cycle occurs. The nature of this cycle varies greatly from one machine to another.
Lets take a sequence of micro-operation:-

t1: MBR <- (PC)
t2: MAR <- save_address
PC <- Rountine_address
t3: memory <- (MBR)

A

Step 1: Contents of the PC is transferred to the MBR, so that they can be saved for return.
Step 2: MAR is loaded with the address at which the contents of the PC are to be saved.
PC is loaded with the address of the start of the interrupt-processing routine.
Step 3: MBR, containing the old value of PC, is stored in memory.
Note: In step 2, two actions are implemented as one micro-operation. However, most processor provide multiple types of interrupts, it may take one or more micro-operation to obtain the save_address and the routine_address before they are transferred to the MAR and PC respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fetch cycle

A

This cycle retrieves the instruction from memory and loads it into the processor’s instruction register. The fetch cycle is essential for the processor to know what instruction it needs to execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Decode cycle

A

This cycle decodes the instruction to determine what operation it represents and what operands it requires. The decode cycle is important for the processor to understand what it needs to do with the instruction and what data it needs to retrieve or manipulate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Execute cycle

A

This cycle performs the actual operation specified by the instruction, using the operands specified in the instruction or in other registers. The execute cycle is where the processor performs the actual computation or manipulation of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Store cycle

A

This cycle stores the result of the operation in memory or in a register. The store cycle is essential for the processor to save the result of the computation or manipulation for future use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Advantages of instruction cycle

A

Standardization: The instruction cycle provides a standard way for CPUs to execute instructions, which allows software developers to write programs that can run on multiple CPU architectures. This standardization also makes it easier for hardware designers to build CPUs that can execute a wide range of instructions.

Efficiency: By breaking down the instruction execution into multiple steps, the CPU can execute instructions more efficiently. For example, while the CPU is performing the execute cycle for one instruction, it can simultaneously fetch the next instruction.

Pipelining: The instruction cycle can be pipelined, which means that multiple instructions can be in different stages of execution at the same time. This improves the overall performance of the CPU, as it can process multiple instructions simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Disadvantages of instruction cycle

A

Overhead: The instruction cycle adds overhead to the execution of instructions, as each instruction must go through multiple stages before it can be executed. This overhead can reduce the overall performance of the CPU.

Complexity: The instruction cycle can be complex to implement, especially if the CPU architecture and instruction set are complex. This complexity can make it difficult to design, implement, and debug the CPU.

Limited parallelism: While pipelining can improve the performance of the CPU, it also has limitations. For example, some instructions may depend on the results of previous instructions, which limits the amount of parallelism that can be achieved. This can reduce the effectiveness of pipelining and limit the overall performance of the CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Here are some common issues associated with different instruction cycles:

A

Pipeline hazards: Pipelining is a technique used to overlap the execution of multiple instructions by breaking them into smaller stages. However, pipeline hazards occur when one instruction depends on the completion of a previous instruction, leading to delays and reduced performance.

Branch prediction errors: Branch prediction is a technique used to anticipate which direction a program will take when encountering a conditional branch instruction. However, if the prediction is incorrect, it can result in wasted cycles and decreased performance.

Instruction cache misses: Instruction cache is a fast memory used to store frequently used instructions. Instruction cache misses occur when an instruction is not found in the cache and needs to be retrieved from slower memory, resulting in delays and decreased performance.

Instruction-level parallelism limitations: Instruction-level parallelism is the ability of a processor to execute multiple instructions simultaneously. However, this technique has limitations as not all instructions can be executed in parallel, leading to reduced performance in some cases.

Resource contention: Resource contention occurs when multiple instructions require the use of the same resource, such as a register or a memory location. This can lead to delays and reduced performance if the processor is unable to resolve the contention efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Program Counter (PC)

A

It contains the address of an instruction to be executed next. The PC is updated by the CPU after each instruction is executed so that it always points to the next instruction to be executed. A branch or skip instruction will also modify the content of the PC.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Memory Buffer (or data) register (MBR or MDR)

A

It contains a word of data to be written to memory or the words most recently read. Contents of MBR are directly connected to the data bus.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Instruction Register (IR)

A

It contains the instruction most recently fetched or executed. The fetched instruction is loaded into an IR, where the opcode and operand specifier is analyzed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Memory Address Register (MAR)

A

It contains the address of a location of main memory from where information has to be fetched for information has to be stored. Contents of MAR are directly connected to the address bus. Apart from these registers, we may use other registers which may be invisible to the user, e.g., temporary Buffering registers.

26
Q

Memory Data Register (MDR)

A

Holds the data being accessed or stored in memory.
Used to transfer data between the processor and memory.

27
Q

Memory Data Register (MDR)

A

Holds the data being accessed or stored in memory.
Used to transfer data between the processor and memory.

27
Q
A
27
Q

Here are some common issues associated with different instruction cycles:

A

Pipeline hazards: Pipelining is a technique used to overlap the execution of multiple instructions by breaking them into smaller stages. However, pipeline hazards occur when one instruction depends on the completion of a previous instruction, leading to delays and reduced performance.

Branch prediction errors: Branch prediction is a technique used to anticipate which direction a program will take when encountering a conditional branch instruction. However, if the prediction is incorrect, it can result in wasted cycles and decreased performance.

Instruction cache misses: Instruction cache is a fast memory used to store frequently used instructions. Instruction cache misses occur when an instruction is not found in the cache and needs to be retrieved from slower memory, resulting in delays and decreased performance.

Instruction-level parallelism limitations: Instruction-level parallelism is the ability of a processor to execute multiple instructions simultaneously. However, this technique has limitations as not all instructions can be executed in parallel, leading to reduced performance in some cases.

Resource contention: Resource contention occurs when multiple instructions require the use of the same resource, such as a register or a memory location. This can lead to delays and reduced performance if the processor is unable to resolve the contention efficiently.

27
Q

Accumulator (ACC)

A

Holds the intermediate results of computations.
Used for arithmetic and logical operations.

28
Q

Status Register (SR)

A

Holds status information about the processor and the current instruction.
Used to indicate whether an operation was successful, to set and clear flags, and to store error information.

29
Q

Index Register (IX)

A

Holds an offset value to be added to a memory address.
Used to access data structures or arrays.

30
Q

The program counter fetches the next instruction, which is stored in the instruction register. The instruction is decoded and the memory address to be accessed is stored in the memory address register. The data is then accessed from memory and stored in the memory data register.

A

The accumulator holds the intermediate results of computations, and the status register holds the status information. The index registers and stack pointer are used for accessing data structures and managing the program stack during function calls and returns. Together, these essential registers enable the processor to execute instructions efficiently and accurately.

30
Q

Index Register (IX)

A

Holds an offset value to be added to a memory address.
Used to access data structures or arrays.

30
Q

Accumulator (ACC)

A

Holds the intermediate results of computations.
Used for arithmetic and logical operations.

31
Q

Stack Pointer (SP)

A

Holds the memory address of the last item placed on the stack.
Used for managing the program stack during function calls and returns.

31
Q

Here are some common issues associated with different instruction cycles:

A

Pipeline hazards: Pipelining is a technique used to overlap the execution of multiple instructions by breaking them into smaller stages. However, pipeline hazards occur when one instruction depends on the completion of a previous instruction, leading to delays and reduced performance.

Branch prediction errors: Branch prediction is a technique used to anticipate which direction a program will take when encountering a conditional branch instruction. However, if the prediction is incorrect, it can result in wasted cycles and decreased performance.

Instruction cache misses: Instruction cache is a fast memory used to store frequently used instructions. Instruction cache misses occur when an instruction is not found in the cache and needs to be retrieved from slower memory, resulting in delays and decreased performance.

Instruction-level parallelism limitations: Instruction-level parallelism is the ability of a processor to execute multiple instructions simultaneously. However, this technique has limitations as not all instructions can be executed in parallel, leading to reduced performance in some cases.

Resource contention: Resource contention occurs when multiple instructions require the use of the same resource, such as a register or a memory location. This can lead to delays and reduced performance if the processor is unable to resolve the contention efficiently.

32
Q

Two-address instruction is a format of machine instruction. It has one opcode and two address fields. One address field is common and can be used for either destination or source and other address field for source.

A

In computer architecture and assembly language programming, 2-address and 1-address instructions refer to the number of memory operands or memory locations accessed by the instruction.

33
Q

Number of memory operands: A 2-address instruction involves two memory operands: one source operand and one destination operand. In contrast, a 1-address instruction involves only one memory operand: the operand that is the source or destination of the instruction.

A

Use of registers: 2-address instructions typically require more registers than 1-address instructions. This is because 2-address instructions have both a source and destination operand, which may require additional registers to hold intermediate values or to perform calculations.

Code size: 1-address instructions are generally more compact than 2-address instructions, as they require only one memory operand and fewer registers.

Flexibility: 2-address instructions are more flexible than 1-address instructions, as they allow for more complex calculations and expressions to be performed. This is because 2-address instructions have both a source and destination operand, which can be used to hold intermediate values or to perform calculations.

Execution time: 1-address instructions are generally faster than 2-address instructions, as they require fewer memory accesses and fewer register operations.

34
Q

One-address instructions

A

ne-Address instruction is also a format of machine instruction. It has only two fields. One for opcode and other for operand.
Opcode | Operand
1-address instruction format

35
Q

Difference between two-address instruction and one-address instruction:
TWO-ADDRESS INSTRUCTION

A

three fields

one field for opcode and two fields for address

long instruction length as compared to one-address.

slower accessing location inside processor than memory.

generally needs two memory accesses.

There may be three memory accesses needed for an instruction.

It can’t completely eliminate three memory access.

36
Q

Difference between two-address instruction and one-address instruction:
ONE-ADDRESS INSTRUCTION

A

It has only two fields.

It has one field for opcode and one field for address.

While it has shorter instruction length.

It is faster accessing location inside processor than memory.

It generally needs one memory accesses.

There is a single memory access needed for an instruction.

It eliminates two memory access completely.

37
Q

Computer organization, instruction format zero-address instructions

A

These instructions do not specify any operands or addresses. Instead, they operate on data stored in registers or memory locations implicitly defined by the instruction. For example, a zero-address instruction might simply add the contents of two registers together without specifying the register names.

38
Q

Computer organization, instruction format one-address instructions

A

These instructions specify one operand or address, which typically refers to a memory location or register. The instruction operates on the contents of that operand, and the result may be stored in the same or a different location. For example, a one-address instruction might load the contents of a memory location into a register.
This uses an implied ACCUMULATOR register for data manipulation. One operand is in the accumulator and the other is in the register or memory location. Implied means that the CPU already knows that one operand is in the accumulator so there is no need to specify it.

39
Q

Computer organization, instruction format two-address instructions

A

These instructions specify two operands or addresses, which may be memory locations or registers. The instruction operates on the contents of both operands, and the result may be stored in the same or a different location. For example, a two-address instruction might add the contents of two registers together and store the result in one of the registers.
This is common in commercial computers. Here two addresses can be specified in the instruction. Unlike earlier in one address instruction, the result was stored in the accumulator, here the result can be stored at different locations rather than just accumulators, but require more number of bit to represent address.

40
Q

Computer organization, instruction format three-address instructions

A

These instructions specify three operands or addresses, which may be memory locations or registers. The instruction operates on the contents of all three operands, and the result may be stored in the same or a different location. For example, a three-address instruction might multiply the contents of two registers together and add the contents of a third register, storing the result in a fourth register.
This has three address field to specify a register or a memory location. Program created are much short in size but number of bits per instruction increase. These instructions make creation of program much easier but it does not mean that program will run much faster because now instruction only contain more information but each micro operation (changing content of register, loading address in address bus etc.) will be performed in one cycle only.

41
Q

A computer performs a task based on the instruction provided. Instruction in computers comprises groups called fields. These fields contain different information as for computers everything is in 0 and 1 so each field has different significance based on which a CPU decides what to perform. The most common fields are:

A

Operation field specifies the operation to be performed like addition.

Address field which contains the location of the operand, i.e., register or memory location.

Mode field which specifies how operand is to be founded.

42
Q

Instruction is of variable length depending upon the number of addresses it contains. Generally, CPU organization is of three types based on the number of address fields:

A

Single Accumulator organization
General register organization
Stack organization

43
Q

Zero-address instructions:
Advantages:

A

They are simple and can be executed quickly since they do not require any operand fetching or addressing. They also take up less memory space.

44
Q

Zero-address instructions:
Disadvantages:

A

They can be limited in their functionality and do not allow for much flexibility in terms of addressing modes or operand types.

45
Q

One-address instructions
Advantages:

A

They allow for a wide range of addressing modes, making them more flexible than zero-address instructions. They also require less memory space than two or three-address instructions.

Disadvantages: They can be slower to execute since they require operand fetching and addressing.

46
Q

Two-address instructions
Advantages:

A

They allow for more complex operations and can be more efficient than one-address instructions since they allow for two operands to be processed in a single instruction. They also allow for a wide range of addressing modes.

Disadvantages: They require more memory space than one-address instructions and can be slower to execute since they require operand fetching and addressing.

47
Q

Three-address instructions
Advantages:

A

hey allow for even more complex operations and can be more efficient than two-address instructions since they allow for three operands to be processed in a single instruction. They also allow for a wide range of addressing modes.

Disadvantages: They require even more memory space than two-address instructions and can be slower to execute since they require operand fetching and addressing.

48
Q

Machine Instructions are commands or programs written in machine code of a machine (computer) that it can recognize and execute.

A

A machine instruction consists of several bytes in memory that tells the processor to perform one machine operation.

The processor looks at machine instructions in main memory one after another, and performs one machine operation for each machine instruction.

The collection of machine instructions in main memory is called a machine language program.

49
Q

Machine code or machine language is a set of instructions executed directly by a computer’s central processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is made up of a series of such instructions.

The general format of a machine instruction is

A

[Label:] Mnemonic [Operand, Operand] [; Comments]

Brackets indicate that a field is optional

Label is an identifier that is assigned the address of the first byte of the instruction in which it appears. It must be followed by “:”

Inclusion of spaces is arbitrary, except that at least one space must be inserted; no space would lead to an ambiguity.

Comment field begins with a semicolon “ ; ”
Example:

Here: MOV R5,#25H;load 25H into R5

50
Q

Data transfer instructions– move, load exchange, input, output.

A

MOV: Move byte or word to register or memory .
IN, OUT: Input byte or word from port, output word to port.
LEA: Load effective address
LDS, LES Load pointer using data segment, extra segment .
PUSH, POP: Push word onto stack, pop word off stack.
XCHG: Exchange byte or word.
XLAT: Translate byte using look-up table.

51
Q

Arithmetic instructions – add, subtract, increment, decrement, convert byte/word and compare.

A

ADD, SUB: Add, subtract byte or word
ADC, SBB: Add, subtract byte or word and carry (borrow).
INC, DEC: Increment, decrement byte or word.
NEG: Negate byte or word (two’s complement).
CMP: Compare byte or word (subtract without storing).
MUL, DIV: Multiply, divide byte or word (unsigned).
IMUL, IDIV: Integer multiply, divide byte or word (signed)
CBW, CWD: Convert byte to word, word to double word
AAA, AAS, AAM ,AAD: ASCII adjust for add, sub, mul, div .
DAA, DAS: Decimal adjust for addition, subtraction (BCD numbers)

52
Q

Logic instructions – AND, OR, exclusive OR, shift/rotate and test

A

NOT: Logical NOT of byte or word (one’s complement)
AND: Logical AND of byte or word
OR: Logical OR of byte or word.
XOR: Logical exclusive-OR of byte or word
TEST: Test byte or word (AND without storing).
SHL, SHR: Logical Shift rotate instruction shift left, right byte or word? by 1or CL
SAL, SAR: Arithmetic shift left, right byte or word? by 1 or CL
ROL, ROR: Rotate left, right byte or word? by 1 or CL.
RCL, RCR: Rotate left, right through carry byte or word? by 1 or CL.

53
Q

String manipulation instruction – load, store, move, compare and scan for byte/word

A

MOVS: Move byte or word string
MOVSB, MOVSW: Move byte, word string.
CMPS: Compare byte or word string.
SCAS S: can byte or word string (comparing to A or AX)
LODS, STOS: Load, store byte or word string to AL.

54
Q

Control transfer instructions – conditional, unconditional, call subroutine and return from subroutine.

A

JMP: Unconditional jump .it includes loop transfer and subroutine and interrupt instructions.
JNZ: jump till the counter value decreases to zero. It runs the loop till the value stored in CX becomes zero

55
Q

Loop control instructions

A

LOOP: Loop unconditional, count in CX, short jump to target address.
LOOPE (LOOPZ): Loop if equal (zero), count in CX, short jump to target address.
LOOPNE (LOOPNZ): Loop if not equal (not zero), count in CX, short jump to target address.
JCXZ: Jump if CX equals zero (used to skip code in loop).
Subroutine and Interrupt instructions-
CALL, RET: Call, return from procedure (inside or outside current segment).
INT, INTO: Software interrupt, interrupt if overflow.IRET: Return from interrupt.

56
Q

Processor control instructions

A

Flag manipulation:

STC, CLC, CMC: Set, clear, complement carry flag.
STD, CLD: Set, clear direction flag.STI, CLI: Set, clear interrupt enable flag.
PUSHF, POPF: Push flags onto stack, pop flags off stack.

57
Q

Sample GATE Question

Consider the sequence of machine instructions given below:

MUL R5, R0, R1
DIV R6, R2, R3
ADD R7, R5, R6
SUB R8, R7, R4
In the above sequence, R0 to R8 are general purpose registers. In the instructions shown, the first register stores the result of the operation performed on the second and the third registers. This sequence of instructions is to be executed in a pipelined instruction processor with the following 4 stages: (1) Instruction Fetch and Decode (IF), (2) Operand Fetch (OF), (3) Perform Operation (PO) and (4) Write back the Result (WB). The IF, OF and WB stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD or SUB instruction, 3 clock cycles for MUL instruction and 5 clock cycles for DIV instruction. The pipelined processor uses operand forwarding from the PO stage to the OF stage. The number of clock cycles taken for the execution of the above sequence of instructions is ___

A

13