Nowshin (MLab-2)
Nowshin (MLab-2)
Lab Report
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
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
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).
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
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)
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).
This instruction subtracts `255` (or `1111 1111` in binary) from the current value in AL, which is
`128` (or `1000 0000` in binary).
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`