COAL Assignment#1 Solution
COAL Assignment#1 Solution
Question 2
org 0x100
mov ax, 5
add bx ax
add bx, ax
add bx, ax
add bx, ax
add bx, ax
mov bx, ax
mov ax, 0x4c00
int 0x21
Or
org 0x100
mov ax, 7
mov cx, ax
sqr:
add bx, ax
loop sqr
mov ax, bx
mov ax, 0x4c00
int 0x21
Question 3
It takes a segment offset pair. Appends a zero at the end of the segment address then adds the 20 bit segment
and the 16 bit offset. As an example, to generate 20 bit address from the pair A68F:F054
A 6 8 F 0
F 0 5 4
B 5 9 4 4
Question 4
Carry Flag: Sets when 17 bit number is generated from the addition of two 16 bit numbers, or 9 bit
number is generated from the addition of two 8 bit numbers.
Set:
mov ax, 0xFFFF
add ax, 1
Or
mov al, 0xFF
add al, 1
Clear:
mov ax, 1
add ax, 2
Zero Flag: Sets when the result of any arithmetic operation is zero
Set:
mov ax, 7
sub ax, 7
Clear:
mov ax, 7
add ax, 7
Overflow Flag: Sets when sign (LSb (b for bit)) bit is changed
Set:
mov al, 50
add al, 32
Clear:
mov al, 9
add al, 1
Question 5
100 : 2A
101 : E3
102 : 01
103 : B8
Question 6
Big Endian: MSB is stored at lower address
Little Endian: MSB is stored at higher address
8086 uses Little Endian
Question 7
i)
First: 0AB0:0000 = 0AB00
Last: 0AB0:FFFF =
ii)
First: 0F5F:0000 = 0F5F0
Last: 0F5F:FFFF = 1F5EF
iii)
First: 1002:000 = 10020
Last: 1002:FFFF = 2001F
iv)
First: 0101:0000 = 01010
Last: 0101:FFFF = 1100F
v)
First: E010:0000 = E0100
Last: E010:FFFF = F00FF
Question 8
i)
ZF: 0
CF: 0
SF: 1
OF: 0
ii)
ZF: 0
CF: 0
SF: 0
OF: 0
iii)
ZF: 1
CF: 1
SF: 0
OF: 0
Question 9
i) (216) / (10242) = 0.624MB
ii) (232) / (10242) = 4096MB
iii) (264) / (10242) = 1.759218x1013MB
Question 10
Parity flag will not be able to detect the error, it works by checking the number of ones and giving a parity
answer based on that. Even numbers are still even when 2 is added or subtracted, same goes for odd
numbers. Since the even-odd nature of the number of ones in the register did not change, the parity flag
won’t be able to detect this error.
Question 11
To extend the memory limit beyond the 2^16 limit imposed by 16-bit registers. Using segmentation it
could have more memory while still having 16-bit registers for addressing.
Question 12
None are invalid
a. 0x00F0
b. 0xFF00
c. 0x010A
e. 0x00FF
f. 0x0101
Question 13
org 0x100
;data section
arr db 0,0,0,0,0 ;array for storing fibonacci in consecutive locations
;code section
mov al,0 ;fist fib no
mov ah,1 ;second fib no
mov dl,0 ;dl register for calculation of next fibonacci no
mov cx,0 ;count for loop
mov [arr+0],al
mov [arr+1],ah
mov bx,2 ;first two locations of array initialized so set offset (bx) to 2
l1:
add dl,al ;add al and ah to fib for next fibonacci number
add dl,ah
mov al,ah ;update al to dl
mov ah,dl ;update ah to dl
mov [arr+bx],ah ;move fibonacci number to array
mov dl,0 ;clear dl register for new calculation
add bx,1 ;increment offset for next location
add cx,1 ;increment count for loop condition
cmp cx,3 ;compare to check if 3 iterations complete
jnz l1 ;exit if zero flag set (cx-3)
mov ax,0x4c00
int 0x21
Question 14
org 0x100
;data section
arr db 7,9,4,2,6 ;array for storing integers in consecutive locations
l1:
add al,[arr+bx] ;add each element of array to al
add bx,1 ;increment offset
add cx,1 ;increment count for loop termination
cmp cx,5 ;check if 5 iterations have completed
jnz l1 ;exit loop it zero flag set (cx-5)
mov ax,0x4c00
int 0x21
Question 15
org 0x100
;data section
num db 7
result db 0
;code section
mov ax,0 ;for storing positive integer
mov cx,0 ;for loop count
mov ax,[num] ;move integer to register for addition
l1:
add [result],ax ;add integer to result variable
add cx,1 ;increment loop count
cmp cx,5 ;check if 5 iterations have completed (cx-5)
jnz l1 ;exit loop if zero flag set
mov ax,0x4c00
int 0x21