0% found this document useful (0 votes)
5 views11 pages

Nowshin (MLab-2)

This lab report details an experiment on flags and flow control instructions in assembly language using the 8086 microprocessor. It analyzes the effects of various instructions on the Carry Flag (CF), Overflow Flag (OF), Zero Flag (ZF), and Sign Flag (SF) through step-by-step execution of code. The final flag statuses are summarized, indicating the outcomes of the operations performed.

Uploaded by

Noshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Nowshin (MLab-2)

This lab report details an experiment on flags and flow control instructions in assembly language using the 8086 microprocessor. It analyzes the effects of various instructions on the Carry Flag (CF), Overflow Flag (OF), Zero Flag (ZF), and Sign Flag (SF) through step-by-step execution of code. The final flag statuses are summarized, indicating the outcomes of the operations performed.

Uploaded by

Noshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Bangladesh University of Professionals

Lab Report

Course Name : Microprocessors, Microcontrollers and Assembly Language


Laboratory
Course Code : CSE-3106
Department : Computer Science & Technology
Faculty : Faculty of Science & Technology

Submitted by,
Student Name : Nowshin Sayara
Student ID : 2252421004
Section :B
Group :6
Year : 3rd
Semester : 1st
Session : 2021-22
Experiment No: 02
Experiment Title: Flags & Flow Control Instructions

Objectives
• To understand the flags of 8086
• To familiarize with flow control instructions
• To write and execute a simple assembly language

Program Question/Lab Task:

1. Given the code below, determine the final status of the Carry Flag (CF) and Overflow
Flag (OF):
MOV AL, 0FFh
ADD AL, 1
ADD AL, 127

Explain how each instruction affects the flag registers, and describe the status of CF and
OF after each step.

Code:
MOV AL, 0FFh
ADD AL, 1
ADD AL, 127

Step-by-Step Analysis

1. MOV AL, 0FFh


This instruction moves the hexadecimal value `FF` (255 in decimal) into the AL register. The
binary representation of `0FFh` is `1111 1111`.
The `MOV` instruction only loads data into a register without performing an arithmetic
operation. Therefore, neither CF nor OF is affected by this instruction.
CF and OF Status:
- CF: Unchanged (retains the previous status).
- OF: Unchanged (retains the previous status).
2. ADD AL, 1
- This instruction adds `1` to the current value in AL (`0FFh` or `1111 1111` in binary). The
result of `0FFh + 1` is `1 0000 0000` in binary, which is `0x100` in hexadecimal.
8-Bit Result: In an 8-bit register like AL, the result `1 0000 0000` wraps around, so AL
contains only the lowest 8 bits: `0000 0000` (0 in decimal).
Effect on Flags:
Carry Flag (CF): The addition of `1` to `0xFF` causes a carry out of the most significant bit,
setting the CF to `1`.
Overflow Flag (OF): Here addition of a negative number and a positive number is performed. If
two signs are different, the overflow flag will always be zero.
- CF and OF Status After This Step:
- CF: `1` (since there was a carry out).
- OF: `0`
3. ADD AL, 127

Now, `127` (or `0111 1111` in binary) is added to AL, which currently holds `0` (or `0000
0000` in binary).
Result in AL: `0000 0000 + 0111 1111 = 0111 1111` (127 in decimal), which is within the
range for an 8-bit signed integer.
Effect on Flags:
- Carry Flag (CF): There is no carry out from this addition, so the CF is reset to `0`.
- Overflow Flag (OF): Here both numbers 0111 1111 and 0000 0000 are positive where result
is also positive. So, OF = 0.
- CF and OF Status After This Step:
- CF:`0` (no carry out from this addition).
- OF `0` (no overflow in the signed 8-bit range).

Final Flag Status


- Carry Flag (CF): `0`
- Overflow Flag (OF): `0`

Summary
After executing all the instructions:
- The Carry Flag (CF) is cleared (`0`).
- The Overflow Flag(OF) is cleared (`0`).

2. Analyze the following code and determine the statuses of the Zero Flag (ZF) and Sign
Flag (SF) after each instruction:
MOV AL, 10
SUB AL, 5
SUB AL, 5
SUB AL, 1
Track the status of ZF and SF after each SUB instruction and explain how they indicate
whether the result is zero, positive, or negative.
Code:
MOV AL, 10
SUB AL, 5
SUB AL, 5
SUB AL, 1

Step-by-Step Analysis

1. `MOV AL, 10`

This instruction moves the decimal value `10` (which is `0Ah` in hexadecimal or `0000 1010` in
binary) into the AL register.
- Effect on Flags: `MOV` only loads a value into a register, so it does not affect the flags.
ZF and SF Status:
- ZF: Unchanged (retains the previous status).
- SF: Unchanged (retains the previous status).

2. SUB AL, 5

This instruction subtracts `5` (or `0000 0101` in binary) from the current value in AL (`10` or
`0000 1010` in binary).
0000 1010 (10 in AL)
- 0000 0101 (5)
= 0000 0101 (5 in decimal)
After this operation, AL contains `5` (or `0000 0101` in binary).
Effect on Flags:
Zero Flag (ZF): Since the result is not zero, ZF is cleared (`0`).
Sign Flag (SF): The most significant bit (MSB) of the result (`0000 0101`) is `0`, indicating a
positive result, so SF is cleared (`0`).
ZF and SF Status After This Step:
- ZF:`0` (result is non-zero).
- SF: `0` (result is positive).
3. SUB AL, 5

Now, `5` (or `0000 0101` in binary) is subtracted from AL, which currently holds `5` (or `0000
0101` in binary).
0000 0101 (5 in AL)
- 0000 0101 (5)
= 0000 0000 (0 in decimal)

After this operation, AL contains `0` (or `0000 0000` in binary).


Effect on Flags:
Zero Flag (ZF): Since the result is zero, ZF is set to `1`.
Sign Flag (SF):The MSB of the result (`0000 0000`) is `0`, indicating a non-negative result, so
SF is cleared (`0`).
ZF and SF Status After This Step:
- ZF: `1` (result is zero).
- SF: `0` (result is non-negative).
4. SUB AL, 1

Finally, `1` (or `0000 0001` in binary) is subtracted from AL, which currently holds `0` (or `0000
0000` in binary).
0000 0000 (0 in AL)
- 0000 0001 (1)
= 1111 1111 (-1 in decimal for an 8-bit signed integer)
After this operation, AL contains `-1` (or `1111 1111` in two’s complement notation, which
represents -1 in decimal for an 8-bit signed integer).
Effect on Flags:
Zero Flag (ZF): Since the result is not zero, ZF is cleared (`0`).
Sign Flag (SF): The MSB of the result (`1111 1111`) is `1`, indicating a negative result, so SF is
set to `1`.
ZF and SF Status After This Step:
ZF: `0` (ZF indicates if the result is zero: `1` when zero, `0` otherwise).
SF:`1` (SF indicates the sign of the result :`1` when negative, `0` when positive).

3. Given the following instructions, predict the final values of CF, ZF, SF, and OF:
MOV AL, 128
SUB AL, 255
ADD AL, 64
ADC AL, 63 ; Perform addition with carry
Describe the status of each flag after each instruction and provide the final values of CF,
ZF, SF, and OF.
Code:
MOV AL, 128
SUB AL, 255
ADD AL, 64
ADC AL, 63
Step-by-Step Analysis
1.MOV AL, 128
This instruction moves the decimal value `128` into the AL register. In 8-bit binary, `128` is
represented as `1000 0000`.
The `MOV` instruction does not perform an arithmetic operation, so it does not affect any of the
flags.
CF, ZF, SF, and OF Status:
- CF: Unchanged (retains the previous status).
- ZF: Unchanged (retains the previous status).
- SF: Unchanged (retains the previous status).
- OF: Unchanged (retains the previous status).

2. SUB AL, 255

This instruction subtracts `255` (or `1111 1111` in binary) from the current value in AL, which is
`128` (or `1000 0000` in binary).

1000 0000 (128 in AL)


- 1111 1111 (255)
= 1000 0001
After this operation, AL contains `1000 0001 which is -127 in decimal in 2’s complement
binary.
Again, taking 2’s complement of 1111 1111 , we get 0000 0001 . Adding it with 1000 000 we
get 1000 0001.
Effect on Flags:
Carry Flag (CF): Since there was a borrow , CF is set to `1`.
- Zero Flag (ZF): Since the result is non-zero, ZF is cleared (`0`).
- Sign Flag (SF): The MSB of the result (`1000 0001`) is `1`, indicating a negative result, so
SF is set to `1`.
- Overflow Flag (OF): Since the addition operation between a negative number and a positive
number always gives OF = 0, OF is set to `0` here.
CF, ZF, SF, and OF Status After This Step:
- CF: `1` (indicating a borrow).
- ZF:`0` (result is non-zero).
- SF: `1` (result is negative).
- OF: `0`

3. ADD AL, 64

Now, `64` (or `0100 0000` in binary) is added to AL, which currently holds `1000 0001` (or `-
127` in decimal).
1000 0001 (-127 in AL)
+ 0100 0000 (64)
= 1100 0001 (-63 in two’s complement binary)
After this operation, AL contains `1100 0001`, which is `-63` in decimal.
Effect on Flags:
Carry Flag (CF): There was no carry out of the most significant bit, so CF remains `0`.
Zero Flag (ZF): Since the result is non-zero, ZF remains `0`.
Sign Flag (SF): The MSB of the result (`1100 0001`) is `1`, indicating a negative result, so SF
remains `1`.
Overflow Flag (OF): This addition did not result in a signed overflow, so OF is cleared to `0`.
CF, ZF, SF, and OF Status After This Step:
CF: `0` (no carry).
ZF: `0` (result is non-zero).
SF: `1` (result is negative).
OF: `0` (no signed overflow).
4.ADC AL, 63 (Addition with Carry)

The `ADC` (Add with Carry) instruction adds `63` (or `0011 1111` in binary) to AL, which
currently holds `1100 0001` (`-63`), and also includes the carry flag in the addition.
1100 0001 (-63 in AL)
+ 0011 1111 (63)
+ 0 (current CF value, which is 0)
= 1111 1111 (-1 in two’s complement binary)
After this operation, AL contains `1111 1111`, which is `-1` in decimal.
Effect on Flags:
Carry Flag (CF): No carry out occurs, so CF remains `0`.
Zero Flag (ZF): Since the result is non-zero, ZF remains `0`.
Sign Flag (SF): The MSB of the result (`1111 1111`) is `1`, indicating a negative result, so SF
remains `1`.
Overflow Flag (OF): The addition did not result in a signed overflow, so OF remains `0`.
CF, ZF, SF, and OF Status After This Step:
CF: `1`
ZF: `1`
SF: `0`
OF: `0`
Final Flag Status Summary
After executing all instructions, the final values of the flags are:
Carry Flag (CF):`1`
Zero Flag (ZF): `1`
Sign Flag (SF): `0`
Overflow Flag (OF): `0`

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy