Assignment 2
Assignment 2
Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W) 7823
Convert WORD to HEX (WH)
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?
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
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
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
10. Update flags after arithmetic instruction? Also state which of the following jumps will be taken or not taken
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)
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
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
Page 11 of 14
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)
Add
Shift
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAND)
Add
Shift
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