ASSIGNMENT 2 (Flags)
ASSIGNMENT 2 (Flags)
1. Write equivalent C code for the assembly code given below? Update final value of registers in HEX
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________ CX
AX
2. Update Flags after executing following code?
NOTE: AND performs a Boolean(bitwise) AND operation between each pair of matching bits in two
operands and place result in the destination. AND instruction always clear overflow and carry flags. It
modifies Sign, Zero and Parity flags.
Sign
Zero
Carry
Flags
Overflow
Parity
Auxiliary
Page 1 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Page 2 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Page 3 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
6. Update register after each line of code and update Flags after executing XOR AL,AH
AX
AX
Sign
AX
Zero AX
Carry AX
Flags
Overflow
Parity AX
Auxiliary Al
AH
AL
7. Write a program that finds parity of number given below? HINT: Use XOR and LOOP to find parity
Page 4 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
INSTRUCTIONS: (Question 7-11) Perform each of the following operations on word size 2’s
complement numbers and update the answer and value of flags after performing the arithmetic.
Perform all the steps in the “calculation” box, only filling the answer will not get any credit.
8. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
Sign Calculation
Zero
Flags Carry
Overflow
Parity
9. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
Sign Calculation
Zero
Flags Carry
Overflow
Parity
Page 5 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
10. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary
11. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary
Page 6 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
12. Update flags after CMP instruction? Also state which of the following jumps will taken or not taken
RENAME JUMPS: JE= JZ , JNZ= JNE
Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary
13. Update value of ax and cx registers after every iteration. Update any changes to the done to flag
1 2 3 4 5 6
CX
AX
Sign Calculation
Zero
Carry
Flags At last iteration Zero and parity flag is set
Overflow
Parity
Auxiliary
Page 7 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
• For two unsigned operands Zero and Carry Flag indicate the following relationship
• For two signed operands Zero and Carry Flag indicate the following relationship
Page 8 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Auxiliary
Auxiliary
Auxiliary
Page 9 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
INSTRUCTIONS: (Question 14-15) Dry run the program for each iteration with following
consideration
Example ID 3812
First digit of Your ID1 3
Second digit of Your ID2 8
Third digit of Your ID3 1
Fourth digit of Your ID4 2
15. Dry run program gives below update table for each iteration count total number of iterations took by the
program
Page 10 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
COUNT SWAP
66 id1 45 id2 40 id3 -25 id4 -10 11
Page 11 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Page 12 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
16. Dry run program gives below update table for each iteration count total number of iterations took by the
program
Page 13 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
COUNT SWAP
66 id1 45 id2 40 id3 -25 id4 -10 11
Page 14 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Page 15 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Page 16 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
STACK AT END OF
FILL STACK PROGRAM
00C6 00C6
00C8 00C8
00CA 00CA
00CC 00CC
00CE 00CE
00E0 00E0
00E2 00E2
00E4 00E4
00E6 00E6
00E8 00E8
00EA 00EA
00EC 00EC
00FE 00FE
00F0 00F0
00F2 00F2
00F4 00F4
00F6 00F6
00F8 00F8
00FA 00FA
00FC 00FC
00FE 00FE
Page 17 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
19. Dry run the assembly code given below and update flag register after executing POPF
Sign Calculation
Zero
Flags Carry
Overflow
Parity
STACK AT END OF
FILL STACK PROGRAM
00F0 00F0
00F2 00F2
00F4 00F4
00F6 00F6
00F8 00F8
00FA 00FA
00FC 00FC
00FE 00FE
Page 18 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
STACK AT END OF
FILL STACK PROGRAM
00F0 00F0
00F2 00F2
00F4 00F4
00F6 00F6
00F8 00F8
00FA 00FA
00FC 00FC
00FE 00FE
STACK AT END OF
FILL STACK PROGRAM
00F0 00F0
00F2 00F2
00F4 00F4
00F6 00F6
00F8 00F8
00FA 00FA
00FC 00FC
00FE 00FE
Page 19 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
STACK AT END OF
FILL STACK PROGRAM
00C6 00C6
00C8 00C8
00CA 00CA
00CC 00CC
00CE 00CE
00E0 00E0
00E2 00E2
00E4 00E4
00E6 00E6
00E8 00E8
00EA 00EA
00EC 00EC
00FE 00FE
00F0 00F0
00F2 00F2
00F4 00F4
00F6 00F6
00F8 00F8
00FA 00FA
00FC 00FC
00FE 00FE
Page 20 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
24. Convert the program given in Question#15 to a procedure where it receives array offset and array size
through STACK. It also creates a local variable for swap?
Page 21 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
INSTRUCTIONS: (Question 23-27) Consider a simple hypothetical machine that includes a single data
register, called an accumulator (AC), 16-bits long instructions and data. Memory is organized using 16-bit
words. The instruction format provides 4 bits for the opcode and 4096 (4K) words of memory can be
directly addressed.
Following Figure is showing the relevant portions of memory:
400 2900 PC 400
401 0901 AC
402 5005 IR
403 4006 MAR
404 6902 MBR
405 9500 I/OAR
406 5006 I/OMR
407 2902
…... I/O Devices
500 3901 …
…. 005 867E
900 80EF 006 7AEE
901 90FF 007 FFFF
902 FFFF ….
PC = Program counter
IR = Instruction register
MAR = Memory address register
MBR = Memory buffer register
I/O AR = Input/output address register
I/O BR = Input/output buffer register
Instruction Format:
16-bit instructions
Bits 0-3 is Operation Code (Op Code)
Bits 4-15 is Address
After execution of arithmetic operations, set the values of the flags as well after the execution step.
Page 22 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Instruction Execute
Page 23 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Instruction Execute
Page 24 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Instruction Execute
Page 25 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)
Instruction Execute
Page 26 of 26