Assigned Byte 0 Assigned Byte 1 B0 B1: Computer Organization & Assembly Language ASSIGNMENT#2 (FALL 2023)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


ID: _i220770_ NAME: _Junaid Asrar _ SECTION: _F__
Read the Instructions Carefully

❖ 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 0 7 7 0


Assigned Byte 0 Assigned Byte 1
Short for Assigned BYTE B0 B1
Byte in DECIMAL 07 70
Convert byte to HEX B0H, B1H 07 46
Convert byte OCTAL B0Q, B1Q 7 106
Convert byte BINARY B0B, B1B 0111 1000110
Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W)
0770
Convert WORD to HEX (WH) 302
Convert WORD OCTAL (WQ) 1402
Convert byte BINARY (WB) 1100000010
Assigned double WORD in HEXA (DH)

EXAMPLE: Name is HAMZA DAUD

Page 1 of 3
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


❖ If your name starts with MUHAMMAD kindly use your second name
ZERO FIRST SECOND THIRD FOURTH FIFTH SIXTH
CHARACTER CHARACTER CHARACTER CHARACTER CHARACTER CHARACTE CHARACTE
OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR R OF YOUR R OF YOUR
NAME NAME NAME NAME NAME NAME NAME
Short for
C0 C1 C2 C3 C4 C5 C6
CHARACTER
YOURNAME
CHARACTER BY
CHARACTER
J U N A I D 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> .386


using namespace std; .model flat, stdcall
int main() { int a = .stack 4096
4578; int n = 5; .data .code
for (int i = 1; i <= n; ++i) { main Proc
int rightmostBit = a & 1; mov ax,
a >>= 1; 4578 mov
a |= (rightmostBit << 7); ecx, 5 l1:
}
mov dx, ax ; d = a and
int b = a;
return 0; } ax, 1 ; a = a & 1 mov bx,
ax ; b = a mov ax, dx ; a =
d mov dx, bx ; d = b = a
& 1 shr ax, 1 ; a = a >> 1
shl dx, 7 ; d = d << 7
or ax, dx ; a = a |
d loop l1 mov bx, ax main
ENDP END main

Page 2 of 3
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


Explanation:
AX is loaded with 4578, and ECX with 5. Since AX&1 isn’t changing the value of AX, the original value is
preserved in AX before doing AX&1. Since AX>>1 is changing AX, the original value of AX is brought
back, and right shifted 1 time. AX&1 is currently in DX. Since it doesn’t matter whether this value is
overwritten or not, DX is simply left shifted 7 times without its previous value preserved anywhere.
Then the answers of AX>>1 and (AX&1)<<7 are OR-ed and saved in AX. The final answer in AX after the
loop ends is moved into BX

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

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
Zero 0
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 29
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

0 1 2 3 4 5 6 7 8 9 A B C D E F
4000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70
4010 71 72 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 pair Zero 0
of matching bits in two operands and place result in the destination. OR
instruction always clear overflow and carry flags. It modifies Sign, Zero Carry 0
Flags
and Parity flags. Overflow 0
Parity 1
Auxiliary 0

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

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

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
4010 51 52 53 54 55 56 57 58 59 5a 61 62 63 64 65 66
4020 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76

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

AX a5 93
AX 5a 6c
AX 00 00
AX ff ff
AX 00 00

AX 5a 37
Al 3 7

AH 5 b
AL 6 c
Sign 0
Zero 0
Carry 0
Flags
Overflow 0
Parity 1
Auxiliary 0
7. Write a program that finds parity of number given below? HINT: Use XOR and LOOP to find parity

Answer:
.386

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

.model flat, stdcall


.stack 4096

.data
parity dq 0a1b2c3d4e5f67890h ; pe=1

.code
main PROC
mov esi, offset parity
mov ecx, type parity
xor eax, eax
mov al, [esi]
inc esi
dec ecx

l1:
mov ah, [esi]
xor al, ah
inc esi
loop l1

and al, 11111111b


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

TAKEN NOT TAKEN


Jc ✓
Jz ✓
Jo ✓
Js ✓
jp ✓

Sign 1 Calculation
Flags Zero 0 1111 1111 1111 1110
+ 1111 1100 0111 0000

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

Carry 1 ———————————————
1 | 1111 1100 0110 1110 PE=0, ZF=0
Overflow 0 ^ CV=1 ^PL=1 ^ AC=0
Parity 1
OV = CVxorPL = 0
also, adding 2 negative numbers and getting a negative answer, so OV=0.
also, answer = -914 > -32,768, so OV=0

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 1 Calculation
Zero 0 0111 1011 0001 1010
+ 0011 0001 0001 0101
Carry 1
———————————————
Overflow 1 0 | 1010 1100 0010 1111 PE=0, ZF=0
Flags Parity ^ CV=0 ^PL=1 ^ AC=0
0
OV = CVxorPL = 1
also, subtracting a negative number from a positive number (adding 2
positive numbers) and getting a negative answer, so OV=1

since 7b1a < ceeb, CV=1

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 ✓

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

Sign 1 Calculation
Zero 0 1111 1011 1100 1101
+ 1110 0100 1010 1010
Carry 1
———————————————
Overflow 0 1 | 1110 0000 0111 0111 PE=1, ZF=0
Flags ^ CV=1 ^PL=1 ^ AC=1
Parity 1
Auxiliary 1 OV = CVxorPL = 0
also, adding 2 negative numbers and getting a negative answer, so
OV=0.
also answer = -8073 > -32,768, so OV=0
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 0 Calculation
Zero 0 1111 1010 1011 1101
1 + 0110 1000 0100 1010
Carry
———————————————
Flags Overflow 0
1 | 0110 0011 0000 0111 PE=0, ZF=0
Parity 0 ^ CV=1 ^PL=0 ^ AC=1
Auxiliary 1
answer = 25,351 < 32,767, so OV=0

12. 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 5 4 3 2 1 0
AX 1 2 3 4 5 6

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

Sign 0 Calculation
Zero 1 The final calculation is ECX being
0 decremented to 0
Carry
Flags 0
Overflow
Parity 1
Auxiliary 0

13. Fill flag after every CMP instruction

Sign 1 Calculation
NOT
Zero 0 0111 1111
TAKEN TAKEN + 1000 0000
Carry 1
Ja ✓ ——————————
Jg Overflow 1
✓ 0 | 1111 1111 PE=1, ZF=0
Parity 1 ^CV=0 ^PL=1 ^AC=0
0
Flags Auxiliary
OV=CVxorPL=1
also, answer=255 > 128, so OV=1

since smaller number (127) -


bigger number (128 {2’s
complement of -128=128}), so
CV=1

NOT
Sign 1 Calculation
TAKEN TAKEN
0
✓ Zero
Jnl 1111 1111 1111 1111
0 + 0000 0000 0000 0000
Jnle ✓ Carry
———————————————
JL ✓ Overflow 0 0 | 1111 1111 1111 1111
Parity 1 ^ CV=0 ^PL=1 ^ AC=0

Flags Auxiliary 0
PE=1, ZF=0

since negative number + negative


number (0 is just 0) = negative
number, OV=0

since bigger number (2’s


complement of -1=65,535) -

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

smaller number (2’s complement


of 0=0), so CV=0

NOT
Sign 0 Calculation
TAKEN TAKEN
0
✓Zero
JNG 0000 0000 0010 0000
1 + 0000 0000 0010 0011
JNGE ✓Carry ———————————————
JGE ✓ Overflow 0
0 | 0000 0000 0100 0011
Parity 0 ^ CV=0 ^PL=0 ^ AC=0
Auxiliary 0
Flags PE=0, ZF=0

OV=CVxorPL=0
also, answer=67 < 32767, so OV=0

since smaller number (32) - bigger


number (2’s complement of -35 =
65501), so CV=1

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

NOT
Sign 0 Calculation
TAKEN TAKEN
JG Zero 1 0000 0000 0000 0000

0 + 0000 0000 0000 0000
JNL ✓ Carry
———————————————
JLE Overflow 0
✓ 0 | 0000 0000 0000 0000
Parity 1 ^ CV=0 ^PL=0 ^ AC=0
Flags Auxiliary 0
PE=1, ZF=1

NOT
OV=CVxorPL=0
TAKEN TAKEN
also, 0 < 32,767 and 0>-32768, so
JL ✓ OV=0
JNG ✓
JGE ✓ Sign 0 Calculation
Zero 1 same as above
Flags 0
Carry
Overflow 0

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

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,0,045h,8,040h,9,-025h,9,-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
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

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

COUNT SWAP
66 0 45 8 40 9 -25 9 -10 11 0 0

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

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

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

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

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

66 45 8 40 9 0 -25 9 -10 11 6 1
(carrying
from above)

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

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

66 45 8 40 9 0 9 -10 11 -25 9 0
(after last
switch, swap
resets to 0 if
it was 1
before)

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

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

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

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

66 45 40 9 8 0 9 -10 11 -25 14 1
(carrying
from above)

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

66 45 40 9 8 9 0 -10 11 -25 16 1
(carrying
from above)

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

66 45 40 9 8 9 0 11 -10 -25 18 0
(after last
switch, swap
resets to 0 if

Page 13 of 29
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)
it was 1
before)

66 45 40 9 8 9 0 11 -10 -25 19 0

66 45 40 9 8 9 0 11 -10 -25 20 0

66 45 40 9 8 9 0 11 -10 -25 21 0

66 45 40 9 8 9 0 11 -10 -25 22 0

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

66 45 40 9 9 8 0 11 -10 -25 24 1
(carrying
from above)

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

66 45 40 9 9 8 11 0 -10 -25 26 1
(carrying
from above)

66 45 40 9 9 8 11 0 -10 -25 27 0
(after last
switch, swap
resets to 0 if
it was 1
before)

66 45 40 9 9 8 11 0 -10 -25 28 0

66 45 40 9 9 8 11 0 -10 -25 29 0

66 45 40 9 9 8 11 0 -10 -25 30 0

66 45 40 9 9 8 11 0 -10 -25 31 0

66 45 40 9 9 8 11 0 -10 -25 32 0

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

66 45 40 9 9 11 8 0 -10 -25 34 1
(carrying
from above)

66 45 40 9 9 11 8 0 -10 -25 35 1
(carrying
from above)

66 45 40 9 9 11 8 0 -10 -25 36 0
(after last
switch, swap
resets to 0 if
it was 1
before)

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

66 45 40 9 9 11 8 0 -10 -25 37 0

66 45 40 9 9 11 8 0 -10 -25 38 0

66 45 40 9 9 11 8 0 -10 -25 39 0

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

66 45 40 9 11 9 8 0 -10 -25 42 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 43 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 44 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 45 0
(after last
switch, swap
resets to 0 if
it was 1
before)

66 45 40 9 11 9 8 0 -10 -25 46 0
66 45 40 9 11 9 8 0 -10 -25 47 0
66 45 40 9 11 9 8 0 -10 -25 48 0
66 45 40 11 9 9 8 0 -10 -25 49 1
66 45 40 11 9 9 8 0 -10 -25 50 1
66 45 40 11 9 9 8 0 -10 -25 51 1
66 45 40 11 9 9 8 0 -10 -25 52 1
66 45 40 11 9 9 8 0 -10 -25 53 1
66 45 40 11 9 9 8 0 -10 -25 54 0

66 45 40 11 9 9 8 0 -10 -25 55 0
66 45 40 11 9 9 8 0 -10 -25 56 0
66 45 40 11 9 9 8 0 -10 -25 57 0
66 45 40 11 9 9 8 0 -10 -25 58 0
66 45 40 11 9 9 8 0 -10 -25 59 0
66 45 40 11 9 9 8 0 -10 -25 60 0
66 45 40 11 9 9 8 0 -10 -25 61 0
66 45 40 11 9 9 8 0 -10 -25 62 0
66 45 40 11 9 9 8 0 -10 -25 63 0

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

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
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
… …

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

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:
.386
.model flat, stdcall
.stack 4096

.data
mData dd 1378cef6h
separate1 db 0
mFLAGS dw 20899
separate2 db 0
permPosition db 14, 15, 29, 3, 20, 4, 0, 6, 23, 5, 25, 7, 10, 11, 8, 28, 1, 24, 21, 9, 30, 16, 2, 18, 22, 17, 31, 26,
13, 12, 27, 19

.code
main Proc

mov ax, mFLAGS


shl ax, 2

jnc step2

mov ax, mFLAGS


and ax, 0000000000001111b
mov cl, al

mov ebx, 0
mov edx, mDATA
shld edx, ebx, cl
or edx, ebx
mov mDATA, edx

step2:

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

mov ax, mFLAGS


shl ax, 3

jnc step3

and ax, 0000000000011111b


mov cl, al

mov ebx, mDATA


mov edx, 0
shrd ebx, edx, cl
or ebx, edx
mov mDATA, ebx

step3:

mov ax, mFLAGS


shl ax, 6

jnc step4

movzx ebx, mFLAGS


shl ebx, 16
or bx, ax
xor mDATA, ebx

step4:

mov ax, mFLAGS


shr ax, 1

jnc endCode

mov ecx, 32
mov esi, 3
xor eax, eax
xor ebx, ebx
xor edx, edx

l1:
push eax
test ax, 0FFh
jz doNotDecrementESI
mov bl, 8
div bl

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

test ah, ah
jnz doNotDecrementESI

dec esi

doNotDecrementESI:
pop eax

mov bl, byte ptr [mData + esi] ; byte0,1,2...


push eax
movzx eax, byte ptr [permPosition + eax] ; index from permArray
push ebx
mov bl, 8
div bl ; index/8 = byte (al). index%8 = bit (ah)
movzx edx, al
neg edx
add edx, 3
pop ebx
mov edi, edx
mov bh, byte ptr [mDATA + edx]
mov dh, 10000000b
push ecx
mov cl, ah
shr dh, cl ; shift 1 in 10000000b to index
pop ecx
pop eax
mov dl, 10000000b
push ecx
mov cl, al
ror dl, cl ; shift 1 in 10000000b to bit
pop ecx

test bl, dl

jp replacing0
jnp replacing1

replacing0:
test bh, dh
jp replacing0with0
jnp replacing0with1

replacing1:
test bh, dh
jp replacing1with0
jnp replacing1with1

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

replacing0with1:
replacing1with0:
xor byte ptr [mData + edi], dh

replacing0with0:
replacing1with1:

inc eax
loop l1

endCode:

main ENDP
END main

Page 20 of 29
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 0 ; Consider Assigned Number Digit
; A0
Multiplier db 9 ; 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 1 0 0 0 0
(carr ying from above)

0 0 0 0 0 0 0 1 0 0 0 0 0 0
(carr ying from above)

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?
Note: Considering it as a 16 bit architecture

CODE
; NOTE ;ADC is add through carry

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

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

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

.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

ECX DX CF AX [result] CF BX [result+2] CF [mulp] CF [mulp+2]

10 02d5 0 0 0 0 - 0 0 0706 0 0

f 016a 1 0706 0706 0 0 0 0 0e0c 0 0

e 00b5 0 0706 0706 0 0 0 0 1c18 0 0

d 005a 1 1c18 231e 0 0 0 0 3830 0 0

c 002d 0 1c18 231e 0 0 0 0 7060 0 0

b 0016 1 7060 937e 0 0 0 0 e0c0 0 0

a 000b 0 7060 937e 0 0 0 0 c180 1 0001

9 0005 1 c180 54fe 1 0001 0002 0 8300 1 0003

8 0002 1 8300 d7fe 0 0003 0005 0 0600 1 0007

7 0001 0 8300 d7fe 0 0003 0005 0 0c00 0 000e

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

6 0 1 0c00 e3fe 0 000e 0013 0 1800 0 001c

5 0 0 0c00 e3fe 0 000e 0013 0 3000 0 0038

4 0 0 0c00 e3fe 0 000e 0013 0 6000 0 0070

3 0 0 0c00 e3fe 0 000e 0013 0 c000 0 00e0

2 0 0 0c00 e3fe 0 000e 0013 0 8000 1 01c1

1 0 0 0c00 e3fe 0 000e 0013 0 0 1 0383


multiplicand = 03830000
multiplier = 05aa
result = 0013e3fe
18. Modify and Rewrite the code given above for following data declaration?
.data
multiplicand DQ 78237823h ;value of Assigned doubleword in hexa
multiplier DW 383h ;Assigned word in hexa
result DQ 0 ;result of the multiplication
Answer:

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

.code
main PROC
mov eax,0
mov ecx,16
mov dx, multiplier

checkbit:
shr dx,1
jnc noadd

mov eax, dword ptr[multiplicand]


add dword ptr[result], eax
mov ebx, dword ptr[multiplicand+4]
adc dword ptr[result+4],ebx
noadd:
shl dword ptr[multiplicand],1
rcl dword ptr[multiplicand+4],1
Loop checkbit
main ENDP
END main

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

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


0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 Add

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

0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 Shift

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

20. Perform Multiplication using Booth’s algorithm?


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

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

AX Q Q-1 M Count

11 1001 1101 00 1010 0101 0 00 0110 0011 Subtract 10

11 1100 1110 10 0101 0010 1 00 0110 0011 Shift

00 0011 0001 ^ ^ 00 0110 0011 Add 9

00 0001 1000 11 0010 1001 0 00 0110 0011 Shift

11 1011 0101 ^ ^ 00 0110 0011 Subtract 8

11 1101 1010 11 1001 0100 1 00 0110 0011 Shift

00 0011 1101 ^ ^ 00 0110 0011 Add 7

00 0001 1110 11 1100 1010 0 00 0110 0011 Shift

00 0110 0011 - 6

00 0000 1111 01 1110 0101 0 00 0110 0011 Shift

11 1010 1100 ^ ^ 00 0110 0011 Subtract 5

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

11 1101 0110 00 1111 0010 1 00 0110 0011 Shift

00 0011 1001 ^ ^ 00 0110 0011 Add 4

00 0001 1100 10 0111 1001 0 00 0110 0011 Shift

11 1011 1001 ^ ^ 00 0110 0011 Subtract 3

11 1101 1100 11 0011 1100 1 00 0110 0011 Shift

00 0011 1111 ^ ^ 00 0110 0011 Add 2

00 0001 1111 11 1001 1110 0 00 0110 0011 Shift

00 0110 0011 - 1

00 0000 1111 11 1100 1111 0 00 0110 0011 Shift

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

21. Perform Unsigned binary division?


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

Answer:

AX Q M Count

0000 0000 0110 0011 0000 0011

0000 0000 1100 0110 ^ 8 SHL

1111 1101 ^ ^ A-M

0000 0000 1100 0110 ^ Qo=0, A+M

0000 0001 1000 1100 ^ 7 SHL

1111 1110 ^ ^ A-M

0000 0001 1000 1100 ^ Qo=0, A+M

0000 0011 0001 1000 ^ 6 SHL

0000 0000 ^ ^ A-M

^ 0001 1001 ^ Qo=1

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

0000 0000 0011 0010 ^ 5 SHL

1111 1101 ^ ^ A-M

0000 0000 0011 0010 ^ Qo=0, A+M

0000 0000 0110 0100 ^ 4 SHL

1111 1101 ^ ^ A-M

0000 0000 0110 0100 ^ Qo=0, A+M

0000 0001 1100 1000 ^ 3 SHL

1111 1110 ^ ^ A-M

0000 0001 1100 1000 ^ Qo=0, A+M

0000 0011 1001 0000 ^ 2 SHL

0000 0000 ^ ^ A-M

^ 1001 0000 ^ Qo=0, A+M

0000 0000 0010 0001 ^ 1 SHL

1111 1101 ^ ^ A-M

0000 0000 0010 0001 ^ Qo=0, A+M

Page 29 of 29
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


ID: _i220770_ NAME: _Junaid Asrar _ SECTION: _F__
Read the Instructions Carefully

❖ 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 0 7 7 0


Assigned Byte 0 Assigned Byte 1
Short for Assigned BYTE B0 B1
Byte in DECIMAL 07 70
Convert byte to HEX B0H, B1H 07 46
Convert byte OCTAL B0Q, B1Q 7 106
Convert byte BINARY B0B, B1B 0111 1000110
Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W)
0770
Convert WORD to HEX (WH) 302
Convert WORD OCTAL (WQ) 1402
Convert byte BINARY (WB) 1100000010
Assigned double WORD in HEXA (DH)

EXAMPLE: Name is HAMZA DAUD

Page 1 of 3
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


❖ If your name starts with MUHAMMAD kindly use your second name
ZERO FIRST SECOND THIRD FOURTH FIFTH SIXTH
CHARACTER CHARACTER CHARACTER CHARACTER CHARACTER CHARACTE CHARACTE
OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR R OF YOUR R OF YOUR
NAME NAME NAME NAME NAME NAME NAME
Short for
C0 C1 C2 C3 C4 C5 C6
CHARACTER
YOURNAME
CHARACTER BY
CHARACTER
J U N A I D 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> .386


using namespace std; .model flat, stdcall
int main() { int a = .stack 4096
4578; int n = 5; .data .code
for (int i = 1; i <= n; ++i) { main Proc
int rightmostBit = a & 1; mov ax,
a >>= 1; 4578 mov
a |= (rightmostBit << 7); ecx, 5 l1:
}
mov dx, ax ; d = a and
int b = a;
return 0; } ax, 1 ; a = a & 1 mov bx,
ax ; b = a mov ax, dx ; a =
d mov dx, bx ; d = b = a
& 1 shr ax, 1 ; a = a >> 1
shl dx, 7 ; d = d << 7
or ax, dx ; a = a |
d loop l1 mov bx, ax main
ENDP END main

Page 2 of 3
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE

ASSIGNMENT#2 (FALL 2023)


Explanation:
AX is loaded with 4578, and ECX with 5. Since AX&1 isn’t changing the value of AX, the original value is
preserved in AX before doing AX&1. Since AX>>1 is changing AX, the original value of AX is brought
back, and right shifted 1 time. AX&1 is currently in DX. Since it doesn’t matter whether this value is
overwritten or not, DX is simply left shifted 7 times without its previous value preserved anywhere.
Then the answers of AX>>1 and (AX&1)<<7 are OR-ed and saved in AX. The final answer in AX after the
loop ends is moved into BX

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

ID: _i220899_ NAME: _Ayesha Ejaz_ SECTION: _F__


Read the Instructions Carefully

❖ 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 0 8 9 9
Assigned Byte 0 Assigned Byte 1
Short for Assigned BYTE B0 B1
Byte in DECIMAL 08 99
Convert byte to HEX B0H, B1H 8 63
Convert byte OCTAL B0Q, B1Q 10 143
Convert byte BINARY B0B, B1B 1000 1100011
Assigned WORD
Short for Assigned WORD W
WORD in DECIMAL(W) 0899
Convert WORD to HEX (WH) 383
Convert WORD OCTAL (WQ) 1603
Convert byte BINARY (WB) 1110000011
Assigned double WORD in HEXA (DH) 78237823H
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 CHARACTE CHARACTE
OF YOUR OF YOUR OF YOUR OF YOUR OF YOUR R OF YOUR R OF YOUR
NAME NAME NAME NAME NAME NAME NAME

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

Short for
C0 C1 C2 C3 C4 C5 C6
CHARACTER
YOUR NAME
CHARACTER
BY A Y E S H A E
CHARACTER

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> .386


using namespace std; .model flat, stdcall
int main() {
int a = 4578;
.stack 4096
int n = 5; .data
for (int i = 1; i <= n; ++i) { .code
int rightmostBit = a & 1; main Proc
a >>= 1; mov ax, 4578
a |= (rightmostBit << 7); mov ecx, 5
}
int b = a; l1:
return 0; } mov dx, ax ; d = a
and ax, 1 ; a = a & 1
mov bx, ax ; b = a
mov ax, dx ; a = d
mov dx, bx ; d = b = a & 1
shr ax, 1 ; a = a >> 1
shl dx, 7 ; d = d << 7
or ax, dx ; a = a | d
loop l1
mov bx, ax
main ENDP
END main
Explanation:
AX is loaded with 4578, and ECX with 5. Since AX&1 isn’t changing the value of AX, the original value is
preserved in AX before doing AX&1. Since AX>>1 is changing AX, the original value of AX is brought back,
and right shifted 1 time. AX&1 is currently in DX. Since it doesn’t matter whether this value is
overwritten or not, DX is simply left shifted 7 times without its previous value preserved anywhere. Then
the answers of AX>>1 and (AX&1)<<7 are OR-ed and saved in AX. The final answer in AX after the loop
ends is moved into BX

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

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
Zero 0
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 29
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)

0 1 2 3 4 5 6 7 8 9 A B C D E F
4000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70
4010 71 72 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 pair Zero 0
of matching bits in two operands and place result in the destination. OR
instruction always clear overflow and carry flags. It modifies Sign, Zero Carry 0
Flags
and Parity flags. Overflow 0
Parity 1
Auxiliary 0

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

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

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
4010 51 52 53 54 55 56 57 58 59 5a 61 62 63 64 65 66
4020 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76

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

AX a5 93
AX 5a 6c
AX 00 00
AX ff ff
AX 00 00

AX 5a 37
Al 3 7

AH 5 b
AL 6 c
Sign 0
Zero 0
Carry 0
Flags
Overflow 0
Parity 1
Auxiliary 0
7. Write a program that finds parity of number given below? HINT: Use XOR and LOOP to find parity

Answer:
.386

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

.model flat, stdcall


.stack 4096

.data
parity dq 0a1b2c3d4e5f67890h ; pe=1

.code
main PROC
mov esi, offset parity
mov ecx, type parity
xor eax, eax
mov al, [esi]
inc esi
dec ecx

l1:
mov ah, [esi]
xor al, ah
inc esi
loop l1

and al, 11111111b


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

TAKEN NOT TAKEN


Jc ✓
Jz ✓
Jo ✓
Js ✓
jp ✓

Sign 1 Calculation
Flags Zero 0 1111 1111 1111 1110
+ 1111 1100 0111 0000

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

Carry 1 ———————————————
1 | 1111 1100 0110 1110 PE=0, ZF=0
Overflow 0 ^ CV=1 ^PL=1 ^ AC=0
Parity 1
OV = CVxorPL = 0
also, adding 2 negative numbers and getting a negative answer, so OV=0.
also, answer = -914 > -32,768, so OV=0

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 1 Calculation
Zero 0 0111 1011 0001 1010
+ 0011 0001 0001 0101
Carry 1
———————————————
Overflow 1 0 | 1010 1100 0010 1111 PE=0, ZF=0
Flags Parity ^ CV=0 ^PL=1 ^ AC=0
0
OV = CVxorPL = 1
also, subtracting a negative number from a positive number (adding 2
positive numbers) and getting a negative answer, so OV=1

since 7b1a < ceeb, CV=1

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 ✓

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

Sign 1 Calculation
Zero 0 1111 1011 1100 1101
+ 1110 0100 1010 1010
Carry 1
———————————————
Overflow 0 1 | 1110 0000 0111 0111 PE=1, ZF=0
Flags ^ CV=1 ^PL=1 ^ AC=1
Parity 1
Auxiliary 1 OV = CVxorPL = 0
also, adding 2 negative numbers and getting a negative answer, so
OV=0.
also answer = -8073 > -32,768, so OV=0
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 0 Calculation
Zero 0 1111 1010 1011 1101
1 + 0110 1000 0100 1010
Carry
———————————————
Flags Overflow 0
1 | 0110 0011 0000 0111 PE=0, ZF=0
Parity 0 ^ CV=1 ^PL=0 ^ AC=1
Auxiliary 1
answer = 25,351 < 32,767, so OV=0

12. 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 5 4 3 2 1 0
AX 1 2 3 4 5 6

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

Sign 0 Calculation
Zero 1 The final calculation is ECX being
0 decremented to 0
Carry
Flags 0
Overflow
Parity 1
Auxiliary 0

13. Fill flag after every CMP instruction

Sign 1 Calculation
NOT
Zero 0 0111 1111
TAKEN TAKEN + 1000 0000
Carry 1
Ja ✓ ——————————
Jg Overflow 1
✓ 0 | 1111 1111 PE=1, ZF=0
Parity 1 ^CV=0 ^PL=1 ^AC=0
0
Flags Auxiliary
OV=CVxorPL=1
also, answer=255 > 128, so OV=1

since smaller number (127) -


bigger number (128 {2’s
complement of -128=128}), so
CV=1

NOT
Sign 1 Calculation
TAKEN TAKEN
0
✓ Zero
Jnl 1111 1111 1111 1111
0 + 0000 0000 0000 0000
Jnle ✓ Carry
———————————————
JL ✓ Overflow 0 0 | 1111 1111 1111 1111
Parity 1 ^ CV=0 ^PL=1 ^ AC=0

Flags Auxiliary 0
PE=1, ZF=0

since negative number + negative


number (0 is just 0) = negative
number, OV=0

since bigger number (2’s


complement of -1=65,535) -

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

smaller number (2’s complement


of 0=0), so CV=0

NOT
Sign 0 Calculation
TAKEN TAKEN
0
✓Zero
JNG 0000 0000 0010 0000
1 + 0000 0000 0010 0011
JNGE ✓Carry ———————————————
JGE ✓ Overflow 0
0 | 0000 0000 0100 0011
Parity 0 ^ CV=0 ^PL=0 ^ AC=0
Auxiliary 0
Flags PE=0, ZF=0

OV=CVxorPL=0
also, answer=67 < 32767, so OV=0

since smaller number (32) - bigger


number (2’s complement of -35 =
65501), so CV=1

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

NOT
Sign 0 Calculation
TAKEN TAKEN
JG Zero 1 0000 0000 0000 0000

0 + 0000 0000 0000 0000
JNL ✓ Carry
———————————————
JLE Overflow 0
✓ 0 | 0000 0000 0000 0000
Parity 1 ^ CV=0 ^PL=0 ^ AC=0
Flags Auxiliary 0
PE=1, ZF=1

NOT
OV=CVxorPL=0
TAKEN TAKEN
also, 0 < 32,767 and 0>-32768, so
JL ✓ OV=0
JNG ✓
JGE ✓ Sign 0 Calculation
Zero 1 same as above
Flags 0
Carry
Overflow 0

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

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,0,045h,8,040h,9,-025h,9,-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
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

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

COUNT SWAP
66 0 45 8 40 9 -25 9 -10 11 0 0

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

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

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

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

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

66 45 8 40 9 0 -25 9 -10 11 6 1
(carrying
from above)

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

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

66 45 8 40 9 0 9 -10 11 -25 9 0
(after last
switch, swap
resets to 0 if
it was 1
before)

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

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

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

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

66 45 40 9 8 0 9 -10 11 -25 14 1
(carrying
from above)

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

66 45 40 9 8 9 0 -10 11 -25 16 1
(carrying
from above)

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

66 45 40 9 8 9 0 11 -10 -25 18 0
(after last
switch, swap
resets to 0 if

Page 13 of 29
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ASSIGNMENT#2 (FALL 2023)
it was 1
before)

66 45 40 9 8 9 0 11 -10 -25 19 0

66 45 40 9 8 9 0 11 -10 -25 20 0

66 45 40 9 8 9 0 11 -10 -25 21 0

66 45 40 9 8 9 0 11 -10 -25 22 0

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

66 45 40 9 9 8 0 11 -10 -25 24 1
(carrying
from above)

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

66 45 40 9 9 8 11 0 -10 -25 26 1
(carrying
from above)

66 45 40 9 9 8 11 0 -10 -25 27 0
(after last
switch, swap
resets to 0 if
it was 1
before)

66 45 40 9 9 8 11 0 -10 -25 28 0

66 45 40 9 9 8 11 0 -10 -25 29 0

66 45 40 9 9 8 11 0 -10 -25 30 0

66 45 40 9 9 8 11 0 -10 -25 31 0

66 45 40 9 9 8 11 0 -10 -25 32 0

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

66 45 40 9 9 11 8 0 -10 -25 34 1
(carrying
from above)

66 45 40 9 9 11 8 0 -10 -25 35 1
(carrying
from above)

66 45 40 9 9 11 8 0 -10 -25 36 0
(after last
switch, swap
resets to 0 if
it was 1
before)

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

66 45 40 9 9 11 8 0 -10 -25 37 0

66 45 40 9 9 11 8 0 -10 -25 38 0

66 45 40 9 9 11 8 0 -10 -25 39 0

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

66 45 40 9 11 9 8 0 -10 -25 42 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 43 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 44 1
(carrying
from above)

66 45 40 9 11 9 8 0 -10 -25 45 0
(after last
switch, swap
resets to 0 if
it was 1
before)

66 45 40 9 11 9 8 0 -10 -25 46 0
66 45 40 9 11 9 8 0 -10 -25 47 0
66 45 40 9 11 9 8 0 -10 -25 48 0
66 45 40 11 9 9 8 0 -10 -25 49 1
66 45 40 11 9 9 8 0 -10 -25 50 1
66 45 40 11 9 9 8 0 -10 -25 51 1
66 45 40 11 9 9 8 0 -10 -25 52 1
66 45 40 11 9 9 8 0 -10 -25 53 1
66 45 40 11 9 9 8 0 -10 -25 54 0

66 45 40 11 9 9 8 0 -10 -25 55 0
66 45 40 11 9 9 8 0 -10 -25 56 0
66 45 40 11 9 9 8 0 -10 -25 57 0
66 45 40 11 9 9 8 0 -10 -25 58 0
66 45 40 11 9 9 8 0 -10 -25 59 0
66 45 40 11 9 9 8 0 -10 -25 60 0
66 45 40 11 9 9 8 0 -10 -25 61 0
66 45 40 11 9 9 8 0 -10 -25 62 0
66 45 40 11 9 9 8 0 -10 -25 63 0

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

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
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
… …

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

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:
.386
.model flat, stdcall
.stack 4096

.data
mData dd 1378cef6h
separate1 db 0
mFLAGS dw 20899
separate2 db 0
permPosition db 14, 15, 29, 3, 20, 4, 0, 6, 23, 5, 25, 7, 10, 11, 8, 28, 1, 24, 21, 9, 30, 16, 2, 18, 22, 17, 31, 26,
13, 12, 27, 19

.code
main Proc

mov ax, mFLAGS


shl ax, 2

jnc step2

mov ax, mFLAGS


and ax, 0000000000001111b
mov cl, al

mov ebx, 0
mov edx, mDATA
shld edx, ebx, cl
or edx, ebx
mov mDATA, edx

step2:

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

mov ax, mFLAGS


shl ax, 3

jnc step3

and ax, 0000000000011111b


mov cl, al

mov ebx, mDATA


mov edx, 0
shrd ebx, edx, cl
or ebx, edx
mov mDATA, ebx

step3:

mov ax, mFLAGS


shl ax, 6

jnc step4

movzx ebx, mFLAGS


shl ebx, 16
or bx, ax
xor mDATA, ebx

step4:

mov ax, mFLAGS


shr ax, 1

jnc endCode

mov ecx, 32
mov esi, 3
xor eax, eax
xor ebx, ebx
xor edx, edx

l1:
push eax
test ax, 0FFh
jz doNotDecrementESI
mov bl, 8
div bl

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

test ah, ah
jnz doNotDecrementESI

dec esi

doNotDecrementESI:
pop eax

mov bl, byte ptr [mData + esi] ; byte0,1,2...


push eax
movzx eax, byte ptr [permPosition + eax] ; index from permArray
push ebx
mov bl, 8
div bl ; index/8 = byte (al). index%8 = bit (ah)
movzx edx, al
neg edx
add edx, 3
pop ebx
mov edi, edx
mov bh, byte ptr [mDATA + edx]
mov dh, 10000000b
push ecx
mov cl, ah
shr dh, cl ; shift 1 in 10000000b to index
pop ecx
pop eax
mov dl, 10000000b
push ecx
mov cl, al
ror dl, cl ; shift 1 in 10000000b to bit
pop ecx

test bl, dl

jp replacing0
jnp replacing1

replacing0:
test bh, dh
jp replacing0with0
jnp replacing0with1

replacing1:
test bh, dh
jp replacing1with0
jnp replacing1with1

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

replacing0with1:
replacing1with0:
xor byte ptr [mData + edi], dh

replacing0with0:
replacing1with1:

inc eax
loop l1

endCode:

main ENDP
END main

Page 20 of 29
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 0 ; Consider Assigned Number Digit
; A0
Multiplier db 9 ; 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 1 0 0 0 0
(carr ying from above)

0 0 0 0 0 0 0 1 0 0 0 0 0 0
(carr ying from above)

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?
Note: Considering it as a 16 bit architecture

CODE
; NOTE ;ADC is add through carry

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

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

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

.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

ECX DX CF AX [result] CF BX [result+2] CF [mulp] CF [mulp+2]

10 02d5 0 0 0 0 - 0 0 0706 0 0

f 016a 1 0706 0706 0 0 0 0 0e0c 0 0

e 00b5 0 0706 0706 0 0 0 0 1c18 0 0

d 005a 1 1c18 231e 0 0 0 0 3830 0 0

c 002d 0 1c18 231e 0 0 0 0 7060 0 0

b 0016 1 7060 937e 0 0 0 0 e0c0 0 0

a 000b 0 7060 937e 0 0 0 0 c180 1 0001

9 0005 1 c180 54fe 1 0001 0002 0 8300 1 0003

8 0002 1 8300 d7fe 0 0003 0005 0 0600 1 0007

7 0001 0 8300 d7fe 0 0003 0005 0 0c00 0 000e

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

6 0 1 0c00 e3fe 0 000e 0013 0 1800 0 001c

5 0 0 0c00 e3fe 0 000e 0013 0 3000 0 0038

4 0 0 0c00 e3fe 0 000e 0013 0 6000 0 0070

3 0 0 0c00 e3fe 0 000e 0013 0 c000 0 00e0

2 0 0 0c00 e3fe 0 000e 0013 0 8000 1 01c1

1 0 0 0c00 e3fe 0 000e 0013 0 0 1 0383


multiplicand = 03830000
multiplier = 05aa
result = 0013e3fe
18. Modify and Rewrite the code given above for following data declaration?
.data
multiplicand DQ 78237823h ;value of Assigned doubleword in hexa
multiplier DW 383h ;Assigned word in hexa
result DQ 0 ;result of the multiplication
Answer:

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

.code
main PROC
mov eax,0
mov ecx,16
mov dx, multiplier

checkbit:
shr dx,1
jnc noadd

mov eax, dword ptr[multiplicand]


add dword ptr[result], eax
mov ebx, dword ptr[multiplicand+4]
adc dword ptr[result+4],ebx
noadd:
shl dword ptr[multiplicand],1
rcl dword ptr[multiplicand+4],1
Loop checkbit
main ENDP
END main

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

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


0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 Add

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

0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 Shift

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


0 0 0 0 1 0 0 0 Add

0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 Shift

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

20. Perform Multiplication using Booth’s algorithm?


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

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

AX Q Q-1 M Count

11 1001 1101 00 1010 0101 0 00 0110 0011 Subtract 10

11 1100 1110 10 0101 0010 1 00 0110 0011 Shift

00 0011 0001 ^ ^ 00 0110 0011 Add 9

00 0001 1000 11 0010 1001 0 00 0110 0011 Shift

11 1011 0101 ^ ^ 00 0110 0011 Subtract 8

11 1101 1010 11 1001 0100 1 00 0110 0011 Shift

00 0011 1101 ^ ^ 00 0110 0011 Add 7

00 0001 1110 11 1100 1010 0 00 0110 0011 Shift

00 0110 0011 - 6

00 0000 1111 01 1110 0101 0 00 0110 0011 Shift

11 1010 1100 ^ ^ 00 0110 0011 Subtract 5

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

11 1101 0110 00 1111 0010 1 00 0110 0011 Shift

00 0011 1001 ^ ^ 00 0110 0011 Add 4

00 0001 1100 10 0111 1001 0 00 0110 0011 Shift

11 1011 1001 ^ ^ 00 0110 0011 Subtract 3

11 1101 1100 11 0011 1100 1 00 0110 0011 Shift

00 0011 1111 ^ ^ 00 0110 0011 Add 2

00 0001 1111 11 1001 1110 0 00 0110 0011 Shift

00 0110 0011 - 1

00 0000 1111 11 1100 1111 0 00 0110 0011 Shift

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

21. Perform Unsigned binary division?


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

Answer:

AX Q M Count

0000 0000 0110 0011 0000 0011

0000 0000 1100 0110 ^ 8 SHL

1111 1101 ^ ^ A-M

0000 0000 1100 0110 ^ Qo=0, A+M

0000 0001 1000 1100 ^ 7 SHL

1111 1110 ^ ^ A-M

0000 0001 1000 1100 ^ Qo=0, A+M

0000 0011 0001 1000 ^ 6 SHL

0000 0000 ^ ^ A-M

^ 0001 1001 ^ Qo=1

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

0000 0000 0011 0010 ^ 5 SHL

1111 1101 ^ ^ A-M

0000 0000 0011 0010 ^ Qo=0, A+M

0000 0000 0110 0100 ^ 4 SHL

1111 1101 ^ ^ A-M

0000 0000 0110 0100 ^ Qo=0, A+M

0000 0001 1100 1000 ^ 3 SHL

1111 1110 ^ ^ A-M

0000 0001 1100 1000 ^ Qo=0, A+M

0000 0011 1001 0000 ^ 2 SHL

0000 0000 ^ ^ A-M

^ 1001 0000 ^ Qo=0, A+M

0000 0000 0010 0001 ^ 1 SHL

1111 1101 ^ ^ A-M

0000 0000 0010 0001 ^ Qo=0, A+M

Page 29 of 29

You might also like