Amna - Assembly Codes
Amna - Assembly Codes
Language (CS-212)
Name: Amna Ashfaq
Roll no:221370016
Section: A
“Assignment-1”
Question 1:(1)
Program:
[org 0x100]
AF: The SHL instruction shifts the bits in the AX register to the left by 4 positions. This
operation result in a carry-out that's why AF is set to 1.
PF: parity flag is one because of even bit, that's why PF is set to 1
SF: sign flag is 0 because the most significant bit (MSB) of the final value is
0. This indicates a non-negative number that's why it is 0.
Question 1:(2)
Program:
[org 0x100]
shr ax, 8
int 0x21
num: dd 70000
Justification:(part 2)
AF: The SHR instruction shifts the bits in the AX register to the right This operation result in a
carry-out that's why AF is set to 1.
PF: parity flag is one because of even bit, that's why PF is set to 1
CF: Carry flag is not set because carry is not generated CF flag is set to 0
OF: No overflow occurs so over flow flag is set to 0
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it is 0.
Question 1:(3)
Program:
[org 0x100]
mov ax,[num]
sal ax, 3
int 0x21
num: dd 70000
Justification:(part 3)
PF: parity flag is one because of even bit, that's why PF is set to 1
SF: sign flag is 1 because the most significant bit (MSB) of the final value is 1 This indicates a
negative number that's why it is 1.
Question 1:(4)
Program:
[org 0x100]
mov ax,[num]
sar ax, 5
int 0x21
num: dd 70000
Screen Short of code Working :
Justification :(part 4)
AF: The SAR instruction shifts the bits in the AX register to the left this operation result in a
carry-out that's why AF is set to 1.
PF: parity flag is one because of even bit, that's why PF is set to 1
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it is 0.
Question 1:(5)
Program:
[org 0x100]
mov ax,[num]
ror ax, 4
int 0x21
num: dd 70000
Screen Short of code Working :
Justification:(part 5)
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it’s 0.
QUESTION 1:(6)
Program:
[org 0x100]
rol ax, 3
mov ax, 0x4c00
int 0x21
num: dd 70000
Justification:(part 6)
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it’s 0.
Question 1:(7)
Program:
[org 0x100]
mov ax,[num]
mov cx, 1
rcl ax, 3
int 0x21
num: dd 70000
Justification:
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it’s 0.
Question 1:(8)
Program:
[org 0x100]
mov cx, 1
rcr ax, 4
int 0x21
num: dd 70000
JUSTIFICATION:(part 8)
SF: sign flag is 0 because the most significant bit (MSB) of the final value is 0. This indicates a
non-negative number that's why it’s 0.
1. mov ax, [number] Loads the 16-bit value from the memory location number into the ax register.
3. and ax, 0xFFFB Performs a bitwise AND operation between the ax (010111) and the value 0xFFFB. The
0xFFFB mask has all bits set to 1 except the two least significant bits which are 0. So this operation will
clears the two least significant bits of ax.
4. mov [result], ax Stores the value of ax into the memory location result.
5. mov ax, 0x4c00: Loads the value 0x4c00 (decimal 19456) into the ax register.
Flag Values:
SF: Sign Flag Set to 0 because the most significant bit (MSB) of the result is 0, indicating a positive value.
AF: Auxiliary Carry Flag The and instruction performs a bitwise AND operation, only checking if
corresponding bits in both operands are 1. it doesn't influence the lower 4 bits so AF is set to zero
PF: Parity Flag Set to 1 because the parity of the result (even number of 1 bits) is even.
Screen Short of Question 4 code Working:
Justification:
1.The code sets the two least significant bits of the value stored in number to 1 using the or instruction.
2. No arithmetic operations are performed, so the Overflow Flag (OF) and Carry Flag (CF) remain
unaffected.
3. The Auxiliary Carry Flag (AF) is specifically associated with carries during decimal-adjusted binary
(BCD) arithmetic
4. The final value in ax is not zero (cleared ZF), and its MSB is 0.
Flag Values:
SF: Sign Flag Set to 0 because the most significant bit (MSB) of the final ax value is 0, indicating a positive
value.
AF: Auxiliary Carry Flag is specifically designed to track carries during decimal-adjusted binary arithmetic
operations since there is no such operation performed it is zero
PF: Parity Flag Cleared to 0 because the parity of the final ax value odd number of 1 bit.
1. mov ax, [number] Loads the first 16 bits (lower half) of the 32-bit value stored at memory location into
the ax register. ax now holds 0x6999.
2.mov dx, [number+2] Loads the next 16 bits (upper half) of the value at number into the dx register. dx
now holds 0x0001
3. shl ax, 6: Shifts the bits in ax (0x6999) 6 positions to the left and 6 zeros are added to the right. ax now
becomes 0x16000. shl dx, 6 Shifts the bits in dx (0x0001) 6 positions to the left
4. mov [result], ax Stores the shifted value in ax into the memory location result.
5. mov [result+2], dx Stores the shifted value in dx into the next 2 bytes of memory after result.
Flag Values :
ZF: Cleared to 0 because the final values in ax and dx are not zero.
SF: Set to 0 because the most significant bits of the final ax and dx values are 0, indicating positive
values.
PF: Set to 0 because the parity (number of 1 bits) of the final ax value is odd