COA
EXP1 : Implementation of various 8 bit ALU operations (ADD, SUB, MUL, DIV, AND, OR, XOR, NOT)
through assembly language programming for 8086 using MASM and Debug.
code :
.MODEL SMALL
.STACK 100H
.DATA
num1 DB 4 ; First operand
num2 DB 2 ; Second operand
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
; ----------- ADD -----------
MOV AL, num1
ADD AL, num2
; ----------- SUB -----------
MOV AL, num1
SUB AL, num2
; ----------- MUL -----------
MOV AL, num1
MOV AH,0
MOV BL, num2
MUL BL ; AX = AX * BX
; Store result (for word-size MUL, result in AX)
; ----------- DIV -----------
MOV AL, num1
MOV BL, num2
XOR DX, DX ; Clear DX before division
DIV BL ; AX = AX / BX, remainder in DX
; ----------- AND -----------
MOV AL, num1
AND AL, num2
; ----------- OR -----------
MOV AL, num1
OR AL, num2
; ----------- XOR -----------
MOV AL, num1
XOR AL, num2
; ----------- NOT -----------
MOV AL, num1
NOT AL
; Exit program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
EXP2 : To apply 8086 instruction set knowledge for evaluating and displaying the status of condition flags using
flag manipulation instructions.
code :
.model small
.data
msg db 0dh, 0ah, "----------- OF DF IF TF SF ZF -- AF -- PF -- CF $"
new1 db 0dh, 0ah, "$"
flag dw ?
.code
start:
mov ax,@data
mov DS,ax
mov dx,offset msg
mov ah,09h
int 21h
mov dx,offset new1
mov ah,09h
int 21h
cli
stc
std
pushf
pop BX
mov flag,bx
mov cx,16
mov bx,8000h
loops:
mov ax,flag
and ax,bx
jz zero
mov dl,31h
mov ah,02h
int 21h
jmp space
zero:
mov dl,30h
mov ah,02h
int 21h
space:
mov dl,' '
mov ah,02h
int 21h
mov ah,02h
int 21h
ror bx,1
loop loops
mov ah,4ch
int 21h
end start
EXP3 : Implementation of number conversion (HEX to BCD, ASCII to BCD) using MASM
code :
; hex_to_decimal.asm
.MODEL SMALL
.STACK 100h
.DATA
hexNum DB 4Ch ; 3Ch = 60 decimal
msg1 DB 'HEX to Decimal result: $' ; String msg
newline DB 0Dh, 0Ah, '$'
.CODE
MAIN PROC
; Initialize data segment
MOV AX, @DATA
MOV DS, AX
; Display message
LEA DX, msg1 ; Load effective address msg1 in DX
MOV AH, 09h ; DOS string display function
INT 21h
; Print newline
LEA DX, newline ; Display newline using some DOS INT 21h
MOV AH, 09h
INT 21h
; Convert hexNum to decimal
MOV AL, hexNum ; AL = 3Ch (60)
XOR AH, AH ; Clear AH
MOV BL, 10 ; Divisor is 10 (for decimal conversion)
DIV BL ; AX / BL -> AL = quotient (tens), AH = remainder (units)
; Save remainder (units) in BH
MOV BH, AH ; BH = units digit
MOV AH, 0 ; Clear AH (not necessary but good practice)
; Print tens digit
ADD AL, '0' ; Convert to ASCII
MOV DL, AL
MOV AH, 02h
MOV AH, 02h
INT 21h
; Print units digit
MOV AL, BH ; Load units digit from BH
ADD AL, '0' ; Convert to ASCII
MOV DL, AL
MOV AH, 02h
INT 21h
; Exit program
MOV AH, 4Ch
INT 21h
MAIN ENDP
END MAIN
EXP4: Implementation of two 8-bit BCD additions with accepting input from keyboard and displaying output
on monitor using INT 21H interrupts.
code :
.model small
.stack 100h
.data
msg1 db 'Enter first BCD number (00-99): $'
msg2 db 0Dh, 0Ah, 'Enter second BCD number (00-99): $'
msg3 db 0Dh, 0Ah, 'Sum is: $'
res db 3 dup('$') ; two digits + '$'
.code
main:
mov ax, @data
mov ds, ax
; First number
lea dx, msg1
call print
call read_bcd
mov bh, al ; store first BCD in BH
; Second number
lea dx, msg2
call print
call read_bcd
add al, bh ; add two BCD numbers
daa ; Decimal Adjust AL
call bcd_to_ascii
; Show result
lea dx, msg3
call print
lea dx, res
call print
; Exit
mov ah, 4Ch
int 21h
; ------- Subroutines -------
; Print string at DS:DX
print:
mov ah, 09h
int 21h
ret
; Read 2 ASCII digits and convert to packed BCD in AL
; Read 2 ASCII digits and convert to packed BCD in AL
read_bcd:
; Read 1st digit
mov ah, 01h
int 21h
sub al, '0'
mov cl,4
shl al, cl
mov bl, al ; upper nibble
; Read 2nd digit
mov ah, 01h
int 21h
sub al, '0'
or bl, al ; combine into packed BCD
mov al, bl
ret
; Convert packed BCD in AL to 2 ASCII digits stored in res[]
bcd_to_ascii:
mov ah, al
and ah, 0F0h
mov cl,4
shr ah, cl
add ah, '0'
mov res, ah
mov ah, al
and ah, 0Fh
add ah, '0'
mov res+1, ah
mov byte ptr res+2, '$'
ret
end main
Exp5 : Block Transfer & Block exchange
code :
Block transfer :
.model small
.data
x db 01h,02h, 03h, 04h, 05h
. code
start:
mov ax, @data
mov ds, ax
mov cx, 05h
lea si, x+04
lea si, x+04
lea di, x+04+03
up: mov bl, [si]
mov [di], bl
dec si
dec di
dec cx
jnz up
mov ah,4ch
int 21h
end start
Block Exchange :
.MODEL SMALL
.DATA
block1 DB 01h, 02h, 03h, 04h, 05h
block2 DB 11h, 12h, 13h, 14h, 15h
. CODE
START:
MOV AX, @DATA
MOV DS, AX
MOV CX, 05h
; Number of bytes to exchange
LEA SI, block1
; Source block 1
LEA DI, block2
; Source block 2
EXCHANGE_LOOP:
MOV AL, [SI]
; Load byte from block1
MOV BL, [DI]
; Load byte from block2
MOV [SI], BL
; Store block2's byte into block1
MOV [DI], AL
; Store block1's byte into block2
INC SI
INC DI
DEC CX
JNZ EXCHANGE_LOOP
MOV AH, 4Ch
INT 21h
END START
EXP6: To implement an 8086 assembly language program that checks whether a predefined string is a
palindrome by applying string manipulation and comparison techniques
code :
.model small
.stack 100h
.data
str db "liril"
len equ $-str
rstr db 20 dup(0)
msg1 db 10,13, "It is a palindrome $"
msg2 db 10,13, "It is not a palindrome $"
.code
start:
mov ax, @data
mov ds, ax
mov es, ax
; Copy string into reverse buffer
mov si, offset str
mov di, offset rstr
add di, len - 1
mov cx, len
back:
mov al, [si]
mov [di], al
inc si
dec di
loop back
; Compare original and reversed strings
mov si, offset str
mov di, offset rstr
mov cx, len
cld
repe cmpsb
jne not_palindrome ; Jump if strings are not equal
; If palindrome
lea dx, msg1
lea dx, msg1
jmp print_msg
not_palindrome:
lea dx, msg2
print_msg:
mov ah, 09h
int 21h
mov ah, 4Ch
int 21h
end start
EXP7: Analyze the functions of INT 10H video interrupts for cursor manipulation, such as hiding
and reshaping the cursor.
code :
.model small
.stack 100h
.data
menu db 13,10, 'case1. increase cursor (block)', 13,10
db 'case2. decrease cursor (underline)', 13,10
db 'case3. move right', 13,10
db 'case4. move left', 13,10
db 'case5. move up',13,10
db 'case6. move down', 13,10
db 'case7. disable cursor', 13,10
db 'Press key 1-7, any other key to exit...', 13, 10, '$'
.code
main:
mov ax, @data
mov ds, ax
; Display menu
mov ah, 09h
lea dx, menu
int 21h
main_loop:
; Wait for key press
mov ah, 01h
int 21h
mov bl, al
; Store key in BL
; Check cases
cmp bl, '1'
je increase_cursor
cmp bl, '2'
je decrease_cursor
cmp bl, '3'
je move_right
cmp bl, '4'
je move_left
cmp bl, '5'
je move_up
cmp bl, '6'
je move_down
cmp bl, '7'
cmp bl, '7'
je hide_cursor
jmp exit_program
increase_cursor:
mov ah, 01h
mov ch, 00h ; Start line (top)
mov cl, 07h ; End line (bottom) block
int 10h
jmp main_loop
decrease_cursor:
mov ah, 01h
mov ch, 06h ; Underline
mov cl, 07h
int 10h
jmp main_loop
move_right:
mov ah, 03h
mov bh, 0
int 10h ; Get current position
inc dl ; Move right
mov ah, 02h
int 10h
jmp main_loop
move_left:
mov ah, 03h
mov bh, 0
int 10h
dec dl
mov ah, 02h
int 10h
jmp main_loop
move_up:
mov ah, 03h
mov bh, 0
int 10h
dec dh
mov ah, 02h
int 10h
jmp main_loop
move_down:
mov ah, 03h
mov bh, 0
int 10h
inc dh
mov ah, 02h
int 10h
jmp main_loop
hide_cursor:
mov ah, 01h
mov ch, 26h ; Invalid shape (hide)
mov cl, 07h
int 10h
jmp main_loop
exit_program:
mov ah, 4Ch
int 21h
end main
EXP8: Analyze how 8086 instructions and system interrupts work together to create interactive password checking application.
Code:
.model small
.DATA
prompt DB 'Enter password: $'
correctPwd DB 'secret$', 0
userPwdStruct LABEL BYTE
DB 20 ; max input length
DB 0 ; actual input length (filled by DOS)
userPwdBuffer DB 20 DUP(0) ; space for user input
successMsg DB 13,10, 'Access Granted$'
failMsg DB 13,10, 'Access Denied$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
; Display prompt
LEA DX, prompt
MOV AH, 09H
INT 21H
; Read user input using DOS buffered input (AH=0Ah)
LEA DX, userPwdStruct
MOV AH, 0AH
INT 21H
; Point SI to input buffer (starts at userPwdBuffer)
LEA SI, userPwdBuffer
LEA SI, userPwdBuffer
LEA DI, correctPwd
CALL CompareStrings
CMP AL, 0
JE CORRECT
; If not equal
LEA DX, failMsg
MOV AH, 09H
INT 21H
JMP EXIT
CORRECT:
; If equal
LEA DX, successMsg
MOV AH, 09H
INT 21H
EXIT:
MOV AH, 4CH
INT 21H
MAIN ENDP
;-----------------------------------------
; CompareStrings: compares strings at SI and DI
; Returns AL = 0 if match, AL = 1 if not
;-----------------------------------------
CompareStrings PROC
PUSH CX
MOV CX, 20 ; max characters to compare
NextChar:
LODSB ; Load byte from SI into AL
CMP AL, '$'
JE EndOfCompare
CMP AL, [DI]
JNE NotMatch
INC DI
LOOP NextChar
EndOfCompare:
CMP BYTE PTR [DI], '$'
JNE NotMatch
; match
MOV AL, 0
POP CX
RET
NotMatch:
MOV AL, 1
POP CX
RET
CompareStrings ENDP
END MAIN
EXP9: Implement Booth’s Multiplication Algorithm
code :
DATA SEGMENT
Q DB 8H
M DB 5H
RESULT DW ?
DB 100 DUP(00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AX, 0000H
MOV BX, 0000H
MOV AL, Q
MOV BL, M
MOV CL, 8
CLC
BACK: MOV DX, 00H
MOV DX, AX
RCL DX, 01
AND DX, 03H
CMP DX, 01H
JE Q01
CMP DX, 02H
JE Q10
NEXT: SAR AX, 01
LOOP BACK
JMP EXIT
Q10: SUB AH, BL
JMP NEXT
Q01: ADD AH, BL
JMP NEXT
EXIT: MOV RESULT, AX
INT 3H
CODE ENDS
END START