Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Assignment 2

Uploaded by

arwheelsofficial
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment 2

Uploaded by

arwheelsofficial
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2024)

ID: NAME: SECTION:


Read the Instructions Carefully.
Deadline:1,11,2024,time:11pm

 Understanding of the questions is also a part of this assignment.


 You are required to solve the assignment on this document and submit it on GCR (SoftCopy)
 You have to use your Roll No and consider it as decimal for the unique declaration purpose.
 Exclude the characters and the first two digits from your Roll number.
FOR EXAMPLE: If your number is 22i-7823, use 7823, where A0 assign the first digit of it.
Assign Digit 0 Assign Digit 1 Assign Digit 2 Assign Digit 3
Short for Assigned Digit A0 A1 A2 A3
Write Assigned Number Digit By Digit 7 8 2 3
Assigned Byte 0 Assigned Byte 1
Short for Assigned BYTE B0 B1
Byte in DECIMAL 78 23
Convert byte to HEX B0H, B1H

Convert byte OCTAL B0Q, B1Q

Convert byte BINARY B0B, B1B

Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W) 7823
Convert WORD to HEX (WH)

Convert WORD OCTAL (WQ)

Convert byte BINARY (WB)

Assigned double WORD in HEXA (DH) 78237823H


EXAMPLE: Name is ali hasan
 If your name starts with MUHAMMAD kindly use your second name

ZERO FIRST SECOND THIRD FOURTH FIFTH SIXTH


CHARACTER CHARACTER CHARACTER CHARACTER CHARACTER CHARACTER CHARACTER
OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR
NAME NAME NAME NAME NAME NAME NAME
Short for
C0 C1 C2 C3 C4 C5 C6
CHARACTER
YOUR NAME
CHARACTER BY
CHARACTER
A L I H A S A

Page 1 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2024)

1. Write equivalent Assembly instructions for the C++ code given below and also explain C++ code in
given space?

C++ Code Assembly Code


#include <iostream>
using namespace std;
int main() {
int a = 4578;
int n = 5;
for (int i = 1; i <= n; ++i) {
int rightmostBit = a & 1;
a >>= 1;
a |= (rightmostBit << 7);
}
int b = a;
return 0; }
Explanation:

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
mov al,0AEH Zero
and al,246
Carry
Flags
Overflow
Parity
Auxiliary
3. Update memory after executing code given below

CODE
.data
ary db 26 dup(?)
arysize= $-ary
ary_copy db arysize dup(0)
endmem db 1
.code

Page 2 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2024)

main PROC
mov esi,OFFSET ary
mov edi,OFFSET ary_copy
mov ax,000FFh
mov ecx,arysize
and al,061h
mov bl,al
and bl,0CFH ;masking
L1:
mov [esi],al
mov [edi],bl
inc esi
inc edi
inc al
inc bl
LOOP L1
INVOKE ExitProcess,0
main ENDP
END main

MEMORY

0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
4010
4020

4. Update Flags after executing following code


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

CODE
.data
ary db 26 dup(?)
arysize= $-ary
ary_copy db arysize dup(0)
endmem db 1

Page 3 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

.code
mov esi,OFFSET ary
mov edi,OFFSET ary_copy
mov ax,0041h
mov ecx,arysize
mov bl,al
OR bl,00100000b
L1:
mov [esi],al
mov [edi],bl
inc esi
inc edi
inc al
inc bl
LOOP L1

MEMORY

0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
4010
4020

6. Update register after each line of code and update Flags after executing the following code

mov ax,0A593H AX
XOR ax,-1 Sign AX
XOR ax,0 Zero AX
XOR ax,-1 AX
XOR ax,ax Carry AX
Flags
Overflow
mov ax, 05A37H
XOR al,0 Parity AX
Al
XOR ah,1 Auxiliary
XOR al,ah AH
AL

7. Write a program that finds parity of number given below? HINT: Use XOR and LOOP to find parity

.data
parity DQ 0A1B2C3D4E5F67890H

Page 4 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

Answer:

INSTRUCTIONS: (Question 8-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 be taken or
not taken

.code TAKEN NOT TAKEN


mov ax,0FFFEh
add ax,0FC70h Jc
jc l1 Jz
L1: jz L2
L2: jo L3 Jo
L3: js L4 Js
L4: jp L5
L5: jp

Sign Calculation
Zero
Flags Carry
Overflow
Parity

Page 5 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

9. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not
taken

.code TAKEN NOT TAKEN


mov ax,07B1Ah
sub ax,0CEEBh Jc
jc l1 Jz
L1: jz L2
L2: jo L3 Jo
L3: js L4
L4: jp L5
Js
jp
Sign Calculation
Zero
Flags Carry
Overflow
Parity

10. Update flags after arithmetic instruction? Also state which of the following jumps will be taken or not taken

.code TAKEN NOT TAKEN


mov cx,0FBCDh
add cx,0E4AAh Jnc
jnc l1 Jnz
L1: jnz L2
L2: jo L3 Jo
L3: js L4 Js
L4: jnp L5
jnp
Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary

Page 6 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

11. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken

mov bx,0FABDh
TAKEN NOT TAKEN
add bx,0684Ah
jc l1 Jc
L1: jz L2 Jz
L2: jno L3
L3: jns L4 Jno
L4: jp L5 Jns
L5: mov ah,04ch jp

Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary

12. Update value of ax and cx registers after every iteration. Update any changes to the done to flag

mov ecx,5
1 2 3 4 5 6
mov ax,1
L1: CX
inc ax
AX
dec ecx
jcxz end_loop
jmp L1
end_loop:

Sign Calculation
Zero
Carry
Flags
Overflow
Parity
Auxiliary

Page 7 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

13. Fill flag after every CMP instruction

NOT Sign Calculation


TAKEN TAKEN Zero
Ja
Carry
Jg Flags
Overflow
Parity
Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
Jnl Carry
Jnle Flags
Overflow
JL Parity
Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
JNG Carry
JNGE Flags
Overflow
JGE Parity
Auxiliary

NOT Sign Calculation


TAKEN TAKEN Zero
JG Carry
Flags
JNL Overflow
JLE Parity
Auxiliary

NOT Sign Calculation


TAKEN TAKEN
Zero
JL Flags
Carry
JNG
Overflow
JGE

Page 8 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

14. Write a program that Left shifts characters of your name three times. Treat it as an array and write final result in
Hex

nameSTRING db ‘C0’, ‘C1’, ‘C2’, ‘C3’, ‘C4’, ‘C5’, ‘C6’, ‘C7’, ‘C8’, ‘C9’
; C0 is first character of your name
; C9 is tenth character of your name

Page 9 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

15. Dry run program gives below update table for each iteration count total number of iterations took by
the program

CODE
.data
Multiplicand db 78 ; Consider Assigned Number Digit
; A0 which is 4 bit
Multiplier db 23 ; Consider Assigned Number Digit A3
; A0 which is 4 bit
Result db 0

.code

mov ax,0
mov cl,4
mov al,multiplicand
mov bl,multiplier
checkbit:
shr bl,1
jnc skip
add result,al

skip:
shl al,1
loop checkbit

al bl
CF multiplicand Multiplier CF result

Page 10 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

16. Perform unsigned binary multiplication using following given flow chart?
NOTE: Your computer width is 8-bit, Multiplicand is (B0B)2 of the assigned number and Multiplier is (B1B)2 of the
assigned number

C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)


Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add

Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add

Shift

C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)

Page 11 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift

C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)


Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift

17. Perform Multiplication using Booth’s algorithm?


NOTE: Your computer width is 10-bit, Multiplicand is B1H assigned number, Multiplier is 0A5H

Q
A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
-1

Page 12 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2024)

Add 10
Shif
t

Add 9
Shif
t

Add 8
Shif
t

Add 7
Shif
t

Add 6
Shif
t

Add 5
Shif
t

Add 4
Shif
t

Add 3
Shif
t
Add 2
Shif
t

Add 1
Shif
t

Page 13 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2024)

Page 14 of 14

You might also like