100% found this document useful (1 vote)
545 views26 pages

ASSIGNMENT 2 (Flags)

This document appears to be an assignment for a computer organization and assembly language course. It includes 13 questions asking students to: 1) Write equivalent C code for assembly code; 2) Update flags for AND and OR operations; 3) Update memory after code execution; 4) Write a program to find parity of a number; 5) Perform arithmetic operations on 2's complement numbers and update flags and jumps; 6) Update registers and flags for CMP; and 7) Update registers over loop iterations and flags. Students are asked to show their work and explain updates to registers, memory, flags and jumps.
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
100% found this document useful (1 vote)
545 views26 pages

ASSIGNMENT 2 (Flags)

This document appears to be an assignment for a computer organization and assembly language course. It includes 13 questions asking students to: 1) Write equivalent C code for assembly code; 2) Update flags for AND and OR operations; 3) Update memory after code execution; 4) Write a program to find parity of a number; 5) Perform arithmetic operations on 2's complement numbers and update flags and jumps; 6) Update registers and flags for CMP; and 7) Update registers over loop iterations and flags. Students are asked to show their work and explain updates to registers, memory, flags and jumps.
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/ 26

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2021)

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)

3. Update memory after executing code given below

Page 2 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)

4. Update Flags after executing following code


NOTE: OR performs a Boolean(bitwise) OR operation between each pair of matching bits in two operands and
place result in the destination. OR instruction always clear overflow and carry flags. It modifies Sign, Zero and
Parity flags. Sign
Zero
Carry
Flags
Overflow
Parity
Auxiliary
5. Update memory after executing code given below

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

TAKEN NOT TAKEN


Jc
Jz
Jo
Js
jp

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

TAKEN NOT TAKEN


Jc
Jz
Jo
Js
jp

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

TAKEN NOT TAKEN


Jnc
Jnz
Jo
Js
jnp

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

TAKEN NOT TAKEN


Jc
Jz
Jno
Jns
jp

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

TAKEN NOT TAKEN


Jz
Je
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)

14. Fill flag after every CMP instruction

NOT Sign Calculation


TAKEN TAKEN Zero
Ja
Carry
Jg Flags For unsigned:
Overflow Destination < Source
For Signed:
Parity Destination>Source

Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
Jnl Carry For unsigned:
Jnle Flags Destination > Source
Overflow For Signed:
JL Parity Destination < Source

Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
JNG Carry
JNGE Flags For unsigned:
Overflow Destination < Source
For Signed:
JGE Parity Destination>Source

Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
JG Carry
Flags Destination = Source
JNL Overflow
JLE Parity
Auxiliary

NOT Sign Calculation


TAKEN TAKEN
Zero
JL Flags
Carry Destination = Source
JNG
Overflow
JGE

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)

17. Modify the program in QUESTION#14 for following data declaration.

Page 16 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)

18. Fill and clear stack using following code

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

20. Update stack after running assembly code given below

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)

21. Update stack after running assembly code given below

STACK AT END OF
FILL STACK PROGRAM

00F0 00F0

00F2 00F2

00F4 00F4

00F6 00F6

00F8 00F8

00FA 00FA

00FC 00FC

00FE 00FE

22. Update stack after running assembly code given below

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)

23. Update stack after running assembly code given below

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

Operation Codes (Op Code)


0000 Add to AC from memory AC = AC + [Address]
0010 Load AC from memory AC = [Address]
0011 Store AC to memory [Address] = AC
0100 Load AC from I/O AC = [Device_Address]
0101 Load I/O from AC [Device Address] = AC
0110 Subtract memory from AC AC = AC – [Address]
1001 Jump to the address PC = Address

Perform two steps individually for each instruction:


Instruction Fetch
Instruction Execute

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)

25. Instruction Fetch


400 2900 PC 400
401 0901 AC
402 5005 IR 2900
403 4006 MAR 400
404 6902 MBR 2900
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 ….

Flags Overflow Sign Zero Carry


Values

Instruction Execute

400 2900 PC 401


401 0901 AC 80EF
402 5005 IR 2900
403 4006 MAR 900
404 6902 MBR 80EF
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 ….

Flags Overflow Sign Zero Carry


Values

Page 23 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)

26. Instruction Fetch

400 2900 PC 401


401 0901 AC 80EF
402 5005 IR 0901
403 4006 MAR 401
404 6902 MBR 0901
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 ….

Flags Overflow Sign Zero Carry


Values

Instruction Execute

400 2900 PC 402


401 0901 AC 11EE
402 5005 IR 0901
403 4006 MAR 901
404 6902 MBR 90FF
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 ….

Flags Overflow Sign Zero Carry


Values

Page 24 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)

27. Instruction Fetch

400 2900 PC 402


401 0901 AC 11EE
402 5005 IR 5005
403 4006 MAR 402
404 6902 MBR 5005
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 ….

Flags Overflow Sign Zero Carry


Values

Instruction Execute

400 2900 PC 403


401 0901 AC 11EE
402 5005 IR 5005
403 4006 MAR
404 6902 MBR
405 9500 I/OAR 005
406 5006 I/OMR 11EE
407 2902
…... I/O Devices
500 3901 …
…. 005 11EE
900 80EF 006 7AEE
901 90FF 007 FFFF
902 FFFF ….

Flags Overflow Sign Zero Carry


Values

Page 25 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2021)

28. Instruction Fetch

400 2900 PC 403


401 0901 AC 11EE
402 5005 IR 4006
403 4006 MAR 403
404 6902 MBR 4006
405 9500 I/OAR
406 5006 I/OMR
407 2902
…... I/O Devices
500 3901 …
…. 005 11EE
900 80EF 006 7AEE
901 90FF 007 FFFF
902 FFFF ….

Flags Overflow Sign Zero Carry


Values

Instruction Execute

400 2900 PC 404


401 0901 AC 7AEE
402 5005 IR 4006
403 4006 MAR
404 6902 MBR
405 9500 I/OAR 006
406 5006 I/OMR 7AEE
407 2902
…... I/O Devices
500 3901 …
…. 005 11EE
900 80EF 006 7AEE
901 90FF 007 FFFF
902 FFFF ….

Flags Overflow Sign Zero Carry


Values

Page 26 of 26

You might also like