Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)

ID: ______22I-1291____ NAME: _____Mishal Ali_____________


SECTION: __k__
Read the Instructions Carefully Mishal

 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 Assign Digit 2 Assign Digit 3
1

Short for Assigned Digit A0 A1 A2 A3

Write Assigned Number Digit By Digit 1 2 9 1


Assigned Byte 0 Assigned Byte 1
Short for Assigned BYTE B0 B1
Byte in DECIMAL 12 91
Convert byte to HEX B0H, B1H 0C 5B
Convert byte OCTAL B0Q, B1Q 14 133
Convert byte BINARY B0B, B1B 1100 1011011
Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W) 1291
Convert WORD to HEX (WH)

Convert WORD OCTAL (WQ)

Convert byte BINARY (WB)

Assigned double WORD in HEXA (DH) 78237823H

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

EXAMPLE: Name is HAMZA DAUD


 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
M I S H A L A

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() {
.data
int a = 4578; a dd 4578
int n = 5; n dd 5
for (int i = 1; i <= n; ++i) { rightMostBit d 0
int rightmostBit = a & 1;
a >>= 1; b dd 0
a |= (rightmostBit << 7); .code
} main PROC
int b = a;
return 0; }
mov ecx, n
L1:
mov ax, a
mov rightMostBit, ax
and rightMostBit, 1
sar a, 1
sal rightMostBit, 7
mov ax, rightMostBit
or a, ax
loop L1

mov ax, a
mov b, ax
Move n to ecx to set the counter loop. Then moving ax to rightmostbit copies the value of a in it. Sar
divides a by 2 followed by Sal to mov the rightmostbit to leftmost position by 6bits. Finally the or

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

command replaces the rihgtmostbit with the previous val of riightmostbit variable. After the loop
ends final value of a is copied to b.

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 1
mov al,0AEH Zero 0
and al,246 Carry 0
Flags
Overflow 0
Parity 1
Auxiliary 0
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

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

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

0 1 2 3 4 5 6 7 8 9 A B C D E F
6
4000 1 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70
7 7
4010 1 2 73 74 75 76 77 78 79 7a 41 42 43 44 45 46
4020 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56

4. Update Flags after executing following code


Sign 1
NOTE: OR performs a Boolean(bitwise) OR operation between each
Zero 0
pair of matching bits in two operands and place result in the destination.
OR instruction always clear overflow and carry flags. It modifies Sign, Carry 0
Flags
Zero and Parity flags. Overflow 0

mov al,11100011b Parity 1


OR al,00000100b ; setting 3rd bit Auxiliary 0
Page 4 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

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

.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 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50
5
4010 1 52 53 54 55 56 57 58 59 5a 61 62 63 64 65 66
6
4020 7 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76

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

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

AX 42387 0xa593
Sign 0 AX 23148 0x5a6c
Zero 0 AX 23148 0x5a6c
Carry 0 AX 42387 0xa593
Flags AX 0 0
Overflow 0
Parity 1 AX 23095 0x5a37
Auxiliary 0 Al 55 0x37

AH 91 0x5b
AL 108 0x6c

mov ax,0A593H
XOR ax,-1
XOR ax,0
XOR ax,-1
XOR ax,ax Page 6 of 26
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

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

.data
parity DQ 0A1B2C3D4E5F67890H
result Db 0

Answer:
.code
Main PROC

Mov esi, offset parity


Mov ecx, 64
Mov al,0

Loop1:
Movzx edi, byte ptr [esi]
Xor al, al
Mov al, byte ptr [esi]
Shr edi,8
Dec ecx
Jnz loop1

Test al,al
Jnz loop2
Jmp loop3

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

Loop2: ;odd parity loop


Mov byte ptr[result], 1
Jmp done

Loop3: ;even parity loop


Mov byte ptr [result],0

Done:
INVOKE ExitProcess , 0
Main ENDP
END main

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 taken or not
taken

.code TAKEN NOT TAKEN


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

Sign 1 Calculation
Zero 0 FFFE
+1FC70
Carry 1
FC6E
Flags Overflow 0 CF = 1, jumps to L1
0 ZF=0, move to L2
Parity OF=0, move to L3
SF=1, jump to L4
PF=0, move to L5

Page 8 of 26
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 1 0
jc l1 Jz 0 1
L1: jz L2
L2: jo L3 Jo 1 0
L3: js L4 Js 1 0
L4: jp L5
L5: jp 0 1
Sign 1 Calculation
Zero 0 7B1A
- CEEB
Carry 1
AC2F
Flags Overflow 1 CF = 1, jump to L1
0 ZF=0, move to L2
Parity OF=1, jump to L3
SF=1, jump to L4
PF=0, move to L5

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

.code TAKEN NOT TAKEN


mov cx,0FBCDh
add cx,0E4AAh Jnc 0 1
jnc l1 Jnz 1 0
L1: jnz L2
L2: jo L3 Jo 0 1
L3: js L4 Js 1 0
L4: jnp L5
L5: mov ah,04ch jnp 0 1
Sign 1 Calculation
Zero 0 FBCD
+E4AA
Carry 1
E077
Overflow 0
Flags 1111 1011 1100 1101 +1110 0100 1010 1010 = 1110 0000 0111 0111
Parity 1
SF=1
Auxiliar 1 CF=1
y PF=1
AF=1

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

Page 10 of 26
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 1 0
jc l1
L1: jz L2
Jz 0 1
L2: jno L3 Jno 1 0
L3: jns L4 Jns 0 1
L4: jp L5
L5: mov ah,04ch
jp 0 1

Sign 0 Calculation
Zero 0 "mov ax,OFABDh" command moves 1111 1010 1011 1101 to ax
"add ax,0684Ah"command adds 0110 1000 0100 1010 to ax
Carry 1
Giving answer 1110 0000 0111 0111 with, CF=1 and AF=1
Flags Overflow 0
Parity 0
Auxiliar 1
y

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 5 4 3 2 1 0
inc ax AX 1 2 3 4 5 6
dec ecx
jcxz end_loop
jmp L1
end_loop:

Flags Sign 0 Calculation

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

Zero 1 At every iteration the counter value of ecx


decreases by one till it reaches zero,
Carry 0
simultaneously the value of ax increases
Overflow 0 by one .
Parity 1
Auxiliary 0

13. Fill flag after every CMP instruction

NOT Sign 1 Calculation


TAKEN TAKEN Zero 0 Al register has +127
J Carry 1
When compared with
-128 result is -255
a 0 1 Flags
Overflow 1
Jg 1 0 Ja doesn’t work for
Parity 1
negative values.
Auxiliary 0

NOT Sign 1 Calculation


TAKE TAKE Zero 0 Dx has a value of -1
When compared with
N N Carry 0
0,
Jnl Flags 0
0 1 Overflow Jl is taken as -1<0
Jnl 1 Hence it jumps
Parity
e 0 1
Auxiliary 0
JL 1 0

Sign 0 Calculation
Zero 0 Bx is +32
And is compared
Carry 1
with -35
Flags Overflow 0 Jge is taken as
0 32>=-35
Parity Hence it jumps to
Auxiliar 1 L5
NOT y
TAKEN TAKEN
JNG 0 1
JNG
E 0 1 Page 12 of 26
JGE 1 0
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

N Sign 0 Calculation
O Zero 1 Cx is zero and
compared with
T Carry 0
zero
T Overflow 0 Jg is false hence
A T Flags
1 itskips
Parity
K A Jnl also skipped as
Auxiliar 0 its not less
E K
y Jge takes it as 0>=0
N E hence it jumps to
N L2
Sign 0 Calculation
J
0 1 Cx is taken as 0 and
Zero 1
J 1 0 compared to 0
Flags Carry J 1 Jl is skipped NOT
as its
0
0 TAKEN
not less TAKEN
Overflow 0 JL Jng0is also skipped
1
Jge takes it as 0>=0
JNG Hence
1 it jumps 0 to L2
Parity 1 0JGE 0 1

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

CODE
.data
data dw 66h,AO,045h,A1,040h,A2,-025h,A3,-010h,011h
swap db 0

.code
main PROC
start:
mov swap,0 ;Reset swap flag to no swap
mov ebx,0 ;initialize array index to zero

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

loop1:
mov ax,[ebx+data] ;load number to ax
cmp ax,[ebx+data+2] ;compare with next number
jge noswap ;no swap if already inorder

mov dx,[ebx+data+2] ;load second element in dx


mov [ebx+data+2],ax ;store first number in second
mov[ebx+data],dx ;store second number in first
mov swap,1 ;flag that a swap has been done
noswap:
add bx,2 ;advance bx to next index
cmp bx,18 ;are we at last index
jne loop1 ;if not than compare next 2

cmp swap,1 ;check if swap has been done


je start ;if yes than make another pass

INVOKE ExitProcess,0
main ENDP
END main

COUNT SWAP
66 1 45 2 40 9 -25 1 -10 11 0 0

66 1 45 2 40 9 -25 1 -10 11 2 0

66 45 1 2 40 9 -25 1 -10 11 4 1

66 45 2 1 40 9 -25 1 -10 11 6 1

66 45 2 40 1 9 -25 1 -10 11 8 1

66 45 2 40 9 1 -25 1 -10 11 10 1

66 45 2 40 9 1 -25 1 -10 11 12 0

66 45 2 40 9 1 1 -25 -10 11 14 1

66 45 2 40 9 1 1 -10 -25 11 16 1

66 45 2 40 9 1 1 -10 11 -25 18 1

66 45 2 40 9 1 1 -10 11 -25 2 0

66 45 2 40 9 1 1 -10 11 -25 4 0

66 45 40 2 9 1 1 -10 11 -25 6 1

66 45 40 9 2 1 1 -10 11 -25 8 1

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

66 45 40 9 2 1 1 -10 11 -25 10 0

66 45 40 9 2 1 1 -10 11 -25 11 0

66 45 40 9 2 1 1 -10 11 -25 12 0

66 45 40 9 2 1 1 11 -10 -25 14 0

66 45 40 9 2 1 1 11 -10 -25 16 1

66 45 40 9 2 1 1 11 -10 -25 18 0

66 45 40 9 2 1 1 11 -10 -25 2 0

66 45 40 9 2 1 1 11 -10 -25 4 0

66 45 40 9 2 1 1 11 -10 -25 6 0

66 45 40 9 2 1 1 11 -10 -25 8 0

66 45 40 9 2 1 1 11 -10 -25 10 0

66 45 40 9 2 1 1 11 -10 -25 12 0

66 45 40 9 2 1 11 1 -10 -25 14 1

66 45 40 9 2 1 11 1 -10 -25 16 0

66 45 40 9 2 1 11 1 -10 -25 18 0

66 45 40 9 2 1 11 1 -10 -25 2 0

66 45 40 9 2 1 11 1 -10 -25 4 0

66 45 40 9 2 1 11 1 -10 -25 6 0

66 45 40 9 2 1 11 1 -10 -25 8 0

66 45 40 9 2 1 11 1 -10 -25 10 0

66 45 40 9 2 11 1 1 -10 -25 12 1

66 45 40 9 2 11 1 1 -10 -25 14 0

66 45 40 9 2 11 1 1 -10 -25 16 0

66 45 40 9 2 11 1 1 -10 -25 18 0

66 45 40 9 2 11 1 1 --10 -25 2 0

66 45 40 9 2 11 1 1 -10 -25 4 0

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

66 45 40 9 2 11 1 1 -10 -25 6 0
66 45 40 9 2 11 1 1 -10 -25 8 0

66 45 40 9 11 2 1 1 -10 -25 10 1

66 45 40 9 11 2 1 1 -10 -25 12 0

66 45 40 9 11 2 1 1 -10 -25 14 0

66 45 40 9 11 2 1 1 -10 -25 16 0

66 45 40 9 11 2 1 1 -10 -25 18 0

66 45 40 9 11 2 1 1 -10 -25 2 0
66 45 40 9 11 2 1 1 -10 -25 4 0
66 45 40 9 11 20 1 1 -10 -25 6 0
66 45 40 11 9 2 1 1 -10 -25 8 1
66 45 40 11 9 2 1 1 -10 -25 10 0
66 45 40 11 9 2 1 1 -10 -25 12 0
66 45 40 11 9 2 1 1 -10 -25 14 0
66 45 40 11 9 2 1 1 -10 -25 16 0

66 45 40 11 9 2 1 1 -10 -25 18 0
15. You are working on the development of an encryption process for a secure communication protocol for a
highly sensitive application. As part of the encryption process, the system needs to perform a series of
bitwise operations on the provided data. Your task is to design and implement an assembly program that
can do these series of transformations on a 32-bit integer number mDATA.
Suppose an 16-bit number mFLAGS, you have to transform the data by applying the series of following 4-
bitwise operations on mDATA according to the specific bit value in mFLAGS as defined in the operation
description provided below:

Operatio Bit Position Operation Description


n# in mFLAGS
(MSB to
LSB)
1 2 (2nd MSB) Bitwise LEFT Rotation:
Perform the left bitwise rotation if the bit is ON. The rotations must be
performed X times. The number X must be extracted from the mFLAGS using
its last 4 bits (LSB). Ensure that the rotation is circular, meaning bits shifted out
from one end are rotated back to the other end.

Note: Not allowed to use any predefined rotate instruction like (ROL,ROR etc.)

2 3 Bitwise RIGHT Rotation:


Perform the right bitwise rotation if the bit is ON. The rotations must be
performed X times. The number X must be extracted from the mFLAGS using

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

its first 5 bits. Ensure that the rotation is circular, meaning bits shifted out from
one end are rotated back to the other end.

Note: Not allowed to use any predefined rotate instruction like (ROL,ROR etc.)

3 6 Bitwise Key Mixing:


In key mixing operation, you must update the mDATA by performing XOR
operation with the a key value. A 32-bit key value must be generated by using
mFLAGS in such a way that mFLAGS is concatenated with mFLAGS.
i.e., if mFLAG is 1010110110101101 the key must be
10101101101011011010110110101101.

The key mixing will only be performed if the bit is ON.


4 LSB Bitwise Permutation:

If this bit is ON, perform bitwise permutation operation on a mDATA using a


predefined permutation table. The permutation table specifies the new positions
of the bits. For example:
Permutation Table:
Bit Position Permutated Position
0 16
1 07
2 09
… …
31 15

You must provide your permutation table in a char array in the data section.

For Example:
the above permutation table can be represented in char array as “160709 … 15”,
where the bit positions are in ascending order,
i.e., 16 is the new position for bit 0,
and 07 is the new position for bit 1,
and so on.

Note: You have to generate 16-bit number mFLAGS using your Roll Number excluding the character and the
first digit. For example if the number is 22i-9986 the mFLAGS must be 29986.
Answer:

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

16. 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
Multiplier db 23 ; Consider Assigned Number Digit A3
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

0 0 0 0 0 0 1 0 0 0 0 0 0 0

0 0 0 0 0 0 0 1 0 0 0 0 0 0

0 0 0 0 0 0 0 0 1 0 0 0 0 0

0 0 0 0 0 0 0 0 0 1 0 0 0 0

17. Consider the following code and fill given registers and memory accordingly after each step?

CODE
; NOTE ;ADC is add through carry

ADC ax, bx ;AX+BX+CF(carry flag)


.data
multiplicand dd WH ;Hexa of assigned word
multiplier dw 005AAH
result dd 0

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

.code

mov ax,0
mov ecx,16 ;initialize bit count to 16
mov dx, multiplier ;initialize bit mask
checkbit:
shr dx,1
jnc noadd ;skip addition if no carry

mov ax, word ptr[multiplicand] ;mov LSW of


multiplicand to ax
add word ptr[result],ax ;add LSW of multiplicand to
result
mov bx, word ptr[multiplicand+2] ;mov MSW of multiplicand to
bx
adc word ptr[result+2],bx ;add MSW of multiplicand to
result
noadd:
shl word ptr[multiplicand],1 ;shift LSW multiplicand to left
rcl word ptr[multiplicand+2],1 ;rotate MSW of multiplicand to
left
Loop checkbit

bx ax
C C
Multiplicand+2 Multiplicand
F F
0A 0C
0
1B 3D
dx
C
multiplier Result+2 Result
F
00 0
55 0
bx ax
C C
Multiplicand+2 Multiplicand
F F
0A1 086
1
B A

dx
C
multiplier Result+2 Result
F
00
0
2A 0
bx ax
C C
Multiplicand+2 Multiplicand
F F
0A 00
0
1B D4

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

dx
C
multiplier Result+2 Result
F
00
0
15 0
bx ax
C C
Multiplicand+2 Multiplicand
F F
0A 01
1 1B A8

dx
C
multiplier Result+2 Result
F
00
00
0A 0
bx ax
C C
Multiplicand+2 Multiplicand
F F
0A1 03
0 B 50
dx
C
multiplier Result+2 Result
F
00 0
0
05
bx ax
C C
Multiplicand+2 Multiplicand
F F

dx
C
multiplier Result+2 Result
F

bx ax
C C
Multiplicand+2 Multiplicand
F F

dx
C
multiplier Result+2 Result
F

bx ax
C C
Multiplicand+2 Multiplicand
F F

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

dx
C
multiplier Result+2 Result
F

18. Modify and Rewrite the code given above for following data declaration?
.data
multiplicand DQ DH ;value of Assigned doubleword in hexa
multiplier DW WH ;Assigned word in hexa
result DQ 0 ;result of the multiplication

Answer:

.code
Main PROC

Movzx ecx, multiplier


Mov ebx,0
Loop1:
Mov ebx, multiplicand
Add dword ptr [result], ebx
Loop loop1

Main ENDP
END main

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

19. 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 (MULTIPLICAN

0 0 00001000 00110001

0
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0
0000010 0011000
0 0 0 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0
0011000
0 0 00000010 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN
0
0000000 0011000
0 0 1 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN
0011000 0000000 0011000
0 1 1 1

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

0001100 1000000 0011000


0 0 0 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0000110 0100000 0011000


0 0 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0000011 0010000 0011000


0 0 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0000001 0001000 0011000


1 0 1
C A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICAN

0000000 1000100 0011000


1 0 1
20. Perform Multiplication using Booth’s algorithm?
NOTE: Your computer width is 10-bit, Multiplicand is 2’s complement of B1H assigned number (Means
it’s a signed and negative number), Multiplier is 0A5H

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

Q-
A (ACCUMULATOR) Q (MULTIPLIER) M (MULTIPLICA
1
001010010 111100111
0000110001 1 1
100101001
0000011000 0 1

100101001 111100111
1111100111 0 1
110010100 111100111
1111110011 1 0 1

111100111
0000100100 1100101001 1
011001010 111100111
0000010010 0 1 1

011001010 111100111
1111100001 0 1
101100101 111100111
1111110000 0 0 1

111100111
1
010110010 111100111
1111111000 1 0 1

010110010
0000101001 1 1111001111
101011001 111100111
0000010100 0 1 1

101011001 111100111
1111100011 0 1
110101100 111100111
1111110001 1 0 1

111100111
0000100010 110101001 1
011010110 111100111
0000010001 0 1 1
011010110 111100111
1111100000 0 1
001101011 111100111
111111000 0 0 1

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

000110101 111100111
1111111000 1 0 1

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

21. Perform Unsigned binary division?


NOTE: Your computer width is 8-bit, where dividend B1H of assigned number, Divisor is 003H

Answer:

Page 26 of 26

You might also like