(c) Explain the following in the context of 8086 Microprocessor with the help of an example or a diagram: (i) Use of code segment and stack segment registers for computing the respective 20-bit addresses. (ii) Any 4 flags of the flag register of 8086 micro-processor (iii) Any four shift instructions of 8086 micro-processo Read the following passage carefully.

, , No Comments

 (i) Use of Code Segment and Stack Segment Registers:


In the 8086 microprocessor, the Code Segment (CS) and Stack Segment (SS) registers are used to compute the 20-bit physical addresses for code and stack operations. The CS register holds the starting address of the code segment, and the SS register holds the starting address of the stack segment. Together with the Instruction Pointer (IP) register, they form a 20-bit address in the form of CS:IP for code execution.


Example:

```assembly

section .data

    msg db 'Hello, World!', 0


section .text

    global _start


_start:

    mov ah, 09h          ; DOS function to print string

    mov dx, msg          ; Address of the string

    int 21h              ; DOS interrupt


    ; Other instructions...


    int 20h              ; DOS interrupt to terminate program

```


In this example, the CS register points to the code segment, and the IP register points to the current instruction within the code segment.


(ii) Flags of the Flag Register:


The 8086 microprocessor has various flags in the flag register (FLAGS), and four important ones are:

1. Zero Flag (ZF): Set if the result of an operation is zero.

2. arry Flag (CF): Set if there is a carry-out or borrow into the high-order bit.

3. Sign Flag (SF): Set if the result is negative.

4. Overflow Flag (OF): Set if there is signed arithmetic overflow.


Example:

```assembly

section .text

    global _start


_start:

    mov ax, 32767       ; Maximum positive value for a 16-bit signed integer

    add ax, 1           ; This will set the Overflow Flag (OF) since it overflows

```


(iii) Shift Instructions:


The 8086 microprocessor has several shift instructions, including:

1. SHL/ SAL (Shift Left): Shifts bits to the left.

2. SHR (Shift Right): Shifts bits to the right, filling with zeros.

3. SAR (Arithmetic Shift Right): Shifts bits to the right, preserving the sign bit.

4. ROL/ ROR (Rotate Left/ Right): Similar to shifts but bits that are shifted out are brought back in.


Example:

```assembly

section .text

    global _start


_start:

    mov ax, 0100h       ; Binary: 0000 0001 0000 0000

    shl ax, 1           ; Shift left by 1 bit, result: 0000 0010 0000 0000

    shr ax, 2           ; Shift right by 2 bits, result: 0000 0000 0100 0000

```


These shift instructions are used for bitwise operations and are crucial in manipulating data in registers.

0 टिप्पणियाँ:

Post a Comment