Q1
org 100h
mov ah, 09h
mov dx, offset msg
int 21h ; Call the DOS interrupt
ret
msg db 'Hello world$'
Q2 8 bit add
org 100h
mov AL,255
mov BL,60
mov cl,00h
add AL,BL
jnc jump
inc cl
jump:
hlt
Q3 8 bit sub
org 100h
mov AL, 50h
mov BL, 40h
mov CL, 00h
sub AL, BL
jnc jump
inc CL
jump:
hlt
Q4 8 bit Mul
org 100h
mov [num1],20h
mov [num2],2h
mov al,[num1]
mov bl,[num2]
mov cl,00h
mul bl
jnc jump:
inc cl
jump:
hlt
num1 db 0
num2 db 0
Q5 8bit Div
org 100h
mov [dividend], 5h
mov [divisor], 2h
mov al, [dividend]
mov bl, [divisor]
mov ah, 00h
div bl
mov [quotient], al
mov [remainder], ah
hlt
dividend DB 0
divisor DB 0
quotient DB 0
remainder DB 0
Q6.1
org 100h ; Set code origin at offset 100h for a COM program
; Load the character to print ('A')
mov dl, 'A'
; Call DOS interrupt to print the character
mov ah, 02h ; Function 02h: Output a character
int 21h ; Call DOS interrupt
; Terminate the program
mov ah, 4Ch ; Function 4Ch: Terminate program
int 21h ; Call DOS interrupt
ret ; Return (though in a COM file this is often unnecessary, INT 21h/4Ch ends the program)
Q6.2
org 100h ; Set code origin at offset 100h for a COM program
mov al, 'a' ; Hardcoded lower-case letter 'h'
sub al, 20h ; Convert to upper-case by subtracting 20h
mov dl, al ; Move the converted letter to DL for output
mov ah, 02h ; DOS interrupt to print the character
int 21h ; Call DOS to print the upper-case letter
Q7
org 100h ; Set code origin at offset 100h for a COM program
start:
; Get a single character input from the user (digit)
mov ah, 01h ; Function 01h: Input a single character
int 21h ; Call DOS interrupt to get the character
mov dl, al ; Move the input character to DL for output
; Print the input character
mov ah, 02h ; Function 02h: Output a character
int 21h ; Call DOS interrupt to print the character
; Terminate the program
mov ah, 4Ch ; Function 4Ch: Terminate program
int 21h ; Exit to DOS
Q8
org 100h
start:
; Display the number
mov ah, 09h ; DOS interrupt to display a string
lea dx, [num] ; Load the address of the number into DX
int 21h ; Call DOS interrupt
; Return from program
ret ; Return control to DOS
num db '25$' ; Data section for number to display
Q9
org 100h
.code
; Input first number
mov ah, 01h ; DOS interrupt 21h, function 01h (input single character)
int 21h ; Read a single character from the user
sub al, 30h ; Convert ASCII to numeric value by subtracting 30h
mov bl, al ; Store first number in BL register
; Input second number
mov ah, 01h ; DOS interrupt 21h, function 01h (input single character)
int 21h ; Read second character from the user
sub al, 30h ; Convert ASCII to numeric value by subtracting 30h
; Compare the two numbers
cmp bl, al ; Compare first number (BL) with second number (AL)
je equal ; If they are equal, jump to 'equal' label
; If not equal
mov dx, offset not_equal_msg ; Load message for 'not equal' case
jmp display_msg ; Jump to message display
equal:
mov dx, offset equal_msg ; Load message for 'equal' case
display_msg:
mov ah, 09h ; DOS interrupt 21h, function 09h (display string)
int 21h ; Display the message
; Terminate the program
mov ah, 4ch ; DOS interrupt 21h, function 4ch (terminate program)
int 21h
; Data section for messages
.data
equal_msg db 'The numbers are equal.', 0Dh, 0Ah, '$'
not_equal_msg db 'The numbers are not equal.', 0Dh, 0Ah, '$'
Q10.1
org 100h
.code
mov cx, 10 ; Set loop counter to 10 (for numbers 0 to 9)
mov ah, 2 ; DOS interrupt function 2 (print character)
mov dl, 30h ; ASCII value of '0'
L1:
int 21h ; Display the character in DL
inc dl ; Increment DL to get the next number character
loop L1 ; Repeat the loop until CX reaches 0
mov ah, 4ch ; Terminate program
int 21h
Q10.2
org 100h
.code
mov cx, 26 ; Set the loop counter for 26 letters
mov ah, 2 ; DOS interrupt for displaying characters
mov dl, 122 ; ASCII value for 'z'
L1:
int 21h ; Display the character in DL
dec dl ; Decrement DL to get the previous character
loop L1 ; Loop until CX reaches 0
mov ah, 4ch ; Terminate the program
int 21h
Q11.a
org 100h ; Specify the code segment for EMU8086
start:
mov ah, 0Eh ; BIOS teletype function to print character
mov al, 'A' ; Load character 'A' into AL
int 10h ; Call BIOS interrupt to print the character
int 20h ; Terminate program
Q11.b
org 100h ; Specify the code segment for EMU8086
start:
mov al, 'A' ; Load upper-case letter 'A' into AL
or al, 20h ; Set bit 5 to convert to lower-case
mov ah, 0Eh ; BIOS teletype function to print character
int 10h ; Call BIOS interrupt to print the character
int 20h ; Terminate program
Q12.1
Program:
org 100h
.data
a db 0,1,2,3,4,5,6,7,8,9
.code
mov cx,10
mov si,0
loop1:
mov al,a[si]
mov dl,al
add dl,48
mov ah,2h
int 21h
INC si
loop loop1
Hlt
Q12.2
org 100h
.data
a db 1, 9, 7, 6 ; Define array of bytes
.code
start:
mov ax, @data ; Initialize data segment
mov ds, ax
mov cx, 4 ; Set counter to the number of elements in the array (4)
mov si, 0 ; Initialize SI (array index) to 0
mov bh, a[si] ; Move the first element into BH as the initial largest number
loop1:
inc si ; Move to the next element
cmp si, cx ; Check if we have iterated through the array
je done ; If yes, exit the loop
cmp bh, a[si] ; Compare the current largest with the next element
jge loop1 ; If BH is greater or equal, continue to the next element
mov bh, a[si] ; Otherwise, update BH to the new largest number
jmp loop1 ; Repeat the process
done:
; Convert BH to ASCII and display the result
add bh, 30h ; Convert number to ASCII by adding 30h
mov dl, bh ; Move the largest number (in ASCII) to DL for display
mov ah, 02h ; DOS interrupt to display a character
int 21h ; Call DOS interrupt
mov ah, 4Ch ; DOS interrupt to terminate program
int 21h ; Exit program
Q13
ORG 100h ; Start code at offset 100h for a .COM file
DATA_SEGMENT:
numbers DB 5, 9, 1, 6, 2 ; List of numbers to be sorted
count DB 5 ; Number of elements in the list
CODE_SEGMENT:
MOV CL, count ; Load the count of elements into CL
DEC CL ; CL = count - 1, as we’ll loop (count - 1) times
outer_loop:
MOV SI, 0 ; SI will point to the start of the list
MOV BL, CL ; BL will control the inner loop
inner_loop:
MOV AL, numbers[SI] ; Load current element into AL
MOV DL, numbers[SI + 1]; Load next element into DL
CMP AL, DL ; Compare current and next elements
JBE no_swap ; If AL <= DL, no swap needed
; Swap the elements
MOV numbers[SI], DL ; Move next element to current position
MOV numbers[SI + 1], AL; Move current element to next position
no_swap:
INC SI ; Move to the next pair
DEC BL ; Decrement inner loop counter
JNZ inner_loop ; Repeat inner loop until BL = 0
DEC CL ; Decrement outer loop counter
JNZ outer_loop ; Repeat outer loop until CL = 0
; Display sorted numbers
MOV SI, 0 ; Reset SI to the start of the list
MOV CL, count ; Load count of elements to print into CL
print_loop:
MOV AL, numbers[SI] ; Load the current number into AL
ADD AL, '0' ; Convert number to ASCII by adding '0'
MOV DL, AL ; Move ASCII value into DL for printing
MOV AH, 02h ; DOS print character function
INT 21h ; Print the character in DL
INC SI ; Move to the next element
DEC CL ; Decrement print counter
JNZ print_loop ; Loop until all numbers are printed
; Exit program
MOV AX, 4C00h ; Terminate program
INT 21h