Assignment 1 COAL
Assignment 1 COAL
✓ Convert your 4-digit ID to two bytes IDB1 and IDB2 both should be in HEX. First two digits
of your ID will replace IDB1 and Last two will replace IDB2 in the assignment.
✓ Convert your 4-digit ID to two bytes IDB3 and IDB4 both should be in HEX. First and third
digits of your ID will replace IDB3 and second and fourth digit will replace IDB4 in the
assignment.
✓ Convert your 4-digit ID to a WORD in HEX and replace IDW in assignment with your 4-
digit ID in HEX.
✓ Concatenate your ID with your ID to create a 8-digit Double WORD in HEX and replace
IDD in assignment with 8-digit ID.
✓ F 1 F 2 F 3 F 4 in assignment must be replaced with first four character
your FIRST Name where FN1 is first character of your first name, FN2 is second character,
FN3 is third character and FN4 is fourth character.
✓ S 1 S 2 S 3 S 4 in assignment must be replaced with first four character
your Second Name where SN1 is first character of your second name, SN2 is second
character, SN3 is third character and SN4 is fourth character.
Assignment 1
Computer Organization and Assembly Language
Question # 01 Perform each of the following operations on these 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.
1. AFFDh + <IDB2 +6, IDB3 +4, IDB4 +6, IDB1> d
Answer Calculation
Sign
Zero
Flags Carry
Overflow
Aux
Carry
Parity
Answer
Calculation
Sign
Zero
Flags
Carry
Overflow
Aux Carry
Parity
2|Page
Assignment 1
Computer Organization and Assembly Language
Answer Calculation
Sign
Zero
Flags
Carry
Overflow
Aux Carry
Parity
3|Page
Assignment 1
Computer Organization and Assembly Language
4|Page
Assignment 1
Computer Organization and Assembly Language
5|Page
Assignment 1
Computer Organization and Assembly Language
Question # 3:
A 16bit 8086 processor uses segment offset addressing to access memory. Each student must use their
4 digit ID to drive key value for segment registers and memory addressing.
You are given the following Segment Registers derived from your Student ID
Segment Base Address
Code Segment IDB1 IDB2 H
Data Segment IDB3 IDB4 H
Stack Segment IDW H
Extra Segment IDB2 IDB1 H
6|Page
Assignment 1
Computer Organization and Assembly Language
7|Page
Assignment 1
Computer Organization and Assembly Language
Question#5: Memory Management
1. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
DATA
.data
list1 BYTE 4,idb1
list2 BYTE 3 DUP(2, IDb2)
list3 DB 2 DUP(o,1,’ FN1’)
list4 BYTE 2 DUP(‘FIRST NAME’)
list5 BYTE 3 D U P ('AB')
CODE REGISTER
.code
main Proc EDI
mov edi,Offset list1
mov al, List2+2 AL
mov bl, List3+4 BL
mov cl, List4+3
mov dl, List5+3 CL
DL
main ENDP
AH
E D main BH
CH
MEMORY
0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
4010
4020
4030
4040
2. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
8|Page
Assignment 1
Computer Organization and Assembly Language
DATA
.data
word1 DW 1
word2 DW -1
word3 SWORD -1
word4 SWORD +1
word5 DW 'AB'
word6 DW 'ABC'
List1 WORD 01F2BH,01101011001011b, 45
list2 DW IDW,2
list3 WORD 3 DUP(0)
list4 WORD 2 DUP(0AB12H)
list5 DW 2 DUP(IDW)
list6 DW 3 DUP('AB')
CODE REGISTER
.code
main Proc EDI
mov edi,Offset list1
mov al, word1 AL
mov bx, List1+4 BX
mov cx, List2+1
mov dx, List4+2 CX
mov ax, List6+1 DX
mov bx, word6+2
mov cx, word5+2
AX
mov cx, word5+4 BX
Main E DP CX
E D main
DX
MEMORY
0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
4010
4020
4030
4040
9|Page
Assignment 1
Computer Organization and Assembly Language
3. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
DATA
.data
dword1 DD 1
dword2 DD -1
dword3 DWORD -1
dword4 DWORD +1
dword5 DD 'AB'
dword6 DD 'ABCD'
List1 DWORD 012345678H,0011010011101011001011b,65
list4 DWORD 2 DUP(0AB123456H)
CODE REGISTER
.code
main Proc EDI
mov edi,Offset dword1
mov ebx, dword2 EAL
mov ecx, dword5 EBX
mov edx, dword6
mov eax, List1+4 ECX
mov ebx, list4+2 EDX
mov ecx, List1+8
mov ecx, word5+4
EAX
main E DP EBX
E D main ECX
EDX
MEMORY
0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
4010
4020
4030
10 | P a g e
Assignment 1
Computer Organization and Assembly Language
.data
11 | P a g e
Assignment 1
Computer Organization and Assembly Language
5. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
DATA
.data
bval1 BYTE 16
bv2 BYTE -16
wval WORD 0
CODE REGISTER
.code
main Proc BX
movsx bx,al
movsx cx,bv2 CX
movsx eax,bv2 EAX
movsx ebx,bval1
movzx ecx,bv2 EBX
movzx edx,bval1 ECX
main E DP EDX
E D main
MEMORY
0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
6. Consider the following Data declaration? Fill given Memory and register value after the
code execution? Look for errors if any.
DATA
.data
bval1 BYTE 5
bval2 BYTE 7
wval1 WORD 0ABCDH
wval2 word 01234h
CODE REGISTER
12 | P a g e
Assignment 1
Computer Organization and Assembly Language
.code
main Proc EDI
mov ax,@data
mov ds,ax AH
mov al,bval1 BH
mov bl,bval2
xchg al,bl ; CX
mov bval1,bl DH
mov bval2,al
mov cx,wval1
DL
xchg cx,wval2 ESI
mov wval2,cx
main E DP
E D main
MEMORY
0 1 2 3 4 5 6 7 8 9 A B C D E F
4000
7. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
DATA
.data
bary BYTE 0ABh,045O,IDb2,25T,IDb1
wary WORD IDW,3456O,IDb2,IDb1,'cd'
Dary dd IDD,'ABcd','S 1S 2S 3S 4',0AB12CD34h
Qary dq 12345678abcdefh,'AbCd'
CODE
.code
AL
main Proc
mov al,bary BL
mov bl,bary+1 CL
mov cl,bary+2
mov dl,bary+3 DL
AX
mov ax,wary BX
13 | P a g e
Assignment 1
Computer Organization and Assembly Language
mov bx,wary+2 CX
mov cx,wary+6
mov dx,wary+12 DX
EAX
mov eax,dary+4
mov ebx,wary+8 EBX
mov ecx,wary+00CF ECX
mov edx,wary EDX
main E DP
E D main
8. Consider the following Data declaration? Fill given Memory and register value? Look for
errors if any.
DATA
.data
bary BYTE 0ABh,045O,IDb2,25T,IDb1
wary WORD IDW,3456O,IDb2,IDb1,'cd'
Dary dd IDD,'ABcd','S 1S 2S 3S 4',0AB12CD34h
Qary dq 12345678abcdefh,'AbCd'
CODE
.code
ESI
main Proc
mov esi, OFFSET bary EDI
mov edi, OFFSET pary ESI
mov esi, OFFSET wary
mov edi, OFFSET wary+2 EDI
mov esi, OFFSET qary ESI
main E DP
E D main
14 | P a g e
Assignment 1
Computer Organization and Assembly Language
9. Consider the following Data declaration? Fill the registers value? Look for errors if any.
DATA
.data
bval1 DB 034h, IDb1
wval2 DW IDW
dval3 DD IDD
CODE
.code
main Proc ESI
mov esi,OFFSET bval1
mov ax, WORD PTR bval1 AX
mov al, BYTE PTR wval2 AL
mov bx, WORD PTR dval3
mov cx, WORD PTR [dval3+2] BX
CX
main E DP
E D main
10. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
bval1 DB ‘F 1’
wval2 DW 0ABCDH,’F 1’
dval3 DD IDD
qval4 QWORD 01243567812435678H
tval5 tbyte -1
CODE
.code
main Proc AL
mov al, TYPE bval1
mov bl, TYPE wval2 BL
mov cl, TYPE dval3 CL
mov dl, TYPE qval4
mov ah, TYPE tval5 DL
main E DP AH
E D main
11. Consider the following Data declaration? Fill given registers value. Look for errors if any.
15 | P a g e
Assignment 1
Computer Organization and Assembly Language
DATA
.data
bAry BYTE 010H,020h,030H
wAry WORD 5 DUP(o),0 ,0
string1 BYTE 0FFH,0FFH
dAry DWORD 2 DUP(3 DUP(0)),0
string2 BYTE 'ABCDEFGHIJKLM OflQRSTUVWXYZ',0
bAry2 BYTE 1,2,3,
4,5,6
BYte 4,5,6
r dq 2 dup(5),2 dup('abcd')
CODE
.code
main Proc BL
mov bl, LE GTHOF bAry
mov cl, LE GTHOF wAry CL
mov dl, LE GTHOF dAry DL
mov ah, LE GTHOF string2
mov al, LE GTHOF bAry2 AH
mov bl, LE GTHOF r AL
main E DP
E D main BL
12. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
bAry BYTE 010H,020h,030H
wAry WORD 5 DUP(o),0 ,0
string1 BYTE 0FFH,0FFH
dAry DWORD 2 DUP(3 DUfl(0)),0
string2 BYTE 'ABCDEFGHIJKLM OflQRSTUVWXYZ',0
r dq 2 dup(5),2 dup('abcd')
CODE
.code
main Proc BL
mov bl, SIZEOF bAry
mov cl, SIZEOF wAry CL
mov dl, SIZEOF dAry DL
mov ah, SIZEOF string1
mov al, SIZEOF string2 AH
mov bl, SIZEOF r BH
16 | P a g e
Assignment 1
Computer Organization and Assembly Language
main E DP AL
E D main
BL
13. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
valb LABEL DB
valw LABEL WORD
vald LABEL DWORD
valq LABEL QWORD
valt Tbyte 12345678abcdef123456h
CODE
.code
main Proc AL
mov al,valb
mov bx,valw BX
mov ecx,vald ECX
main E DP
E D main
14. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
Ary1 BYTE F 1,2, IDb2
ary2 WORD S 1,05678h, IDW
CODE
.code
main Proc AL
mov ESI, OFFSET Ary1
mov al,[ESI] BL
add ESI,1 CL
mov bl,[ESI]
inc ESI AX
inc BYTE PTR [ESI] BX
mov cl,[ESI]
CX
mov ESI, OFFSET Ary2
mov ax,[ESI]
17 | P a g e
Assignment 1
Computer Organization and Assembly Language
add ESI,2
mov bx,[ESI]
inc ESI
inc ESI
inc WORD PTR [ESI]
mov cx,[ESI]
main E DP
E D main
15. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
Ary1 BYTE F 1,2, IDb2,4
ary2 WORD S 1,05678h, IDW,567o
ary3 DWORD S 2,012345678h, IDD,567o
CODE
.code
main Proc AL
mov ESI,0
mov al,ary1[ESI] BL
mov ESI,1 * TYPE ary2 CL
mov bl,ary1[ESI]
mov ESI,2 * TYPE ary2 AX
mov cl,ary1[ESI] BX
mov ESI,0 CX
mov ax,ary2[ESI] EAX
mov ESI,1 * TYPE ary2
mov bx,ary2[ESI]
EBX
mov ESI,2 * TYPE ary2 ECX
mov cx,ary[ESI]
mov ESI,0
mov eax,ary3[ESI]
mov ESI,1 * TYPE ary3
mov ebx,ary3[ESI]
mov ESI,2 * TYPE ary3
mov ecx,ary3[ESI]
main E DP
E D main
18 | P a g e
Assignment 1
Computer Organization and Assembly Language
16. Consider the following Data declaration? Fill given registers value. Look for errors if any.
DATA
.data
ary2 WORD S 1,05678h, IDW,567o
CODE
.code
main Proc AX
mov ESI,0
mov ax,ary[ESI * TYPE ary2] BX
I C ESI CX
mov BX,ary[ESI * TYPE ary2]
I C ESI
mov CX,ary[ESI * TYPE ary2]
I C ESI
main E DP
E D main
19 | P a g e
Assignment 1
Computer Organization and Assembly Language
Question no 17: Convert the following C++ code into Assembly language
#include <iostream>
int main() {
int a = 9, b = 15;
int max;
if (a > b)
max = a;
else
max = b;
Best of Luck
20 | P a g e