0% found this document useful (0 votes)
10 views14 pages

Mic15 16 17 18

The document contains assembly code for various practical exercises that demonstrate basic arithmetic operations and bit manipulation. It includes examples of checking if a number is positive or negative, counting bits, and performing addition, subtraction, multiplication, and division using macros. Each section is structured with a main procedure and specific procedures for each operation, along with messages for output.

Uploaded by

shruticpatil07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views14 pages

Mic15 16 17 18

The document contains assembly code for various practical exercises that demonstrate basic arithmetic operations and bit manipulation. It includes examples of checking if a number is positive or negative, counting bits, and performing addition, subtraction, multiplication, and division using macros. Each section is structured with a main procedure and specific procedures for each operation, along with messages for output.

Uploaded by

shruticpatil07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Exp 15

1] .model small

.stack 100h

.data

msg_pos db 'The number is Positive.$'

msg_neg db 'The number is Negative.$'

.code

main:

mov ax, @data

mov ds, ax

mov al, -8 ; Load a number to check (you can change this)

; Rotate MSB into Carry Flag

rol al, 1 ; MSB -> CF, AL is rotated left by 1 bit

; Now CF = original MSB

jc is_negative ; If CF = 1 (i.e., original MSB = 1), it's negative

is_positive:

lea dx, msg_pos

mov ah, 09h

int 21h

jmp exit

is_negative:

lea dx, msg_neg


mov ah, 09h

int 21h

exit:

mov ah, 4ch

int 21h

end main

OUTPUT
2]

.model small

.stack 100h

.data

msg_pos db 'The number is Positive.$'

msg_neg db 'The number is Negative.$'

.code

main:

mov ax, @data ; Initialize data segment

mov ds, ax

mov al, -5 ; Load a number to test (you can change this value)

; Check sign of AL

test al, al ; Sets flags based on AL (including Sign flag)

jns is_positive ; Jump if Sign Flag = 0 (i.e., number is positive)

is_negative:

lea dx, msg_neg

mov ah, 09h

int 21h

jmp exit

is_positive:

lea dx, msg_pos

mov ah, 09h

int 21h
exit:

mov ah, 4ch

int 21h

end main

OUTPUT
Exp 16

1]

.model small
.stack 100h
.data
ones_msg db 'Number of 1s: $'
zeros_msg db 'Number of 0s: $'
.code
main:
mov ax, @data
mov ds, ax

mov al, 0F3h ; Example number (11110011b), change as needed


mov bl, 8 ; Counter for 8 bits
mov ch, 0 ; Count of 1's
mov cl, 0 ; Count of 0's

check_bit:
ror al, 1 ; Rotate right, LSB -> CF
jc count_one ; If CF=1, it's a '1'

inc cl ; Count 0s
jmp next_bit

count_one:
inc ch ; Count 1s

next_bit:
dec bl
jnz check_bit

; Print number of 1s
lea dx, ones_msg
mov ah, 09h
int 21h

mov dl, ch ; Move 1s count to DL


add dl, 30h ; Convert to ASCII
mov ah, 02h
int 21h

; Print number of 0s
lea dx, zeros_msg
mov ah, 09h
int 21h
mov dl, cl ; Move 0s count to DL
add dl, 30h ; Convert to ASCII
mov ah, 02h ;Start of text
int 21h

; Exit
mov ah, 4ch
int 21h
end main
OUTPUT
Practical 17

.model small
.stack 100h
.data
num1 db 10
num2 db 5

msg_add db 'Addition: $'


msg_sub db 'Subtraction: $'
msg_mul db 'Multiplication: $'
msg_div db 'Division: $'

.code
main:
mov ax, @data
mov ds, ax

lea dx, msg_add


mov ah, 09h
int 21h

call addition
call print_result

lea dx, msg_sub


mov ah, 09h
int 21h

call subtraction
call print_result

lea dx, msg_mul


mov ah, 09h
int 21h

call multiplication
call print_result

lea dx, msg_div


mov ah, 09h
int 21h

call division
call print_result
mov ah, 4ch
int 21h

addition proc
mov al, num1
add al, num2
mov bl, al
ret
addition endp

subtraction proc
mov al, num1
sub al, num2
mov bl, al
ret
subtraction endp

multiplication proc
mov al, num1
mov bl, num2
mul bl
mov bl, al
ret
multiplication endp

division proc
mov al, num1
mov ah, 0
mov bl, num2
div bl
mov bl, al
ret
division endp

print_result proc
mov dl, bl
add dl, 30h
mov ah, 02h
int 21h
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
int 21h
ret
print_result endp
end main
Output

2]
3]

4]
Practical 18

.model small
.stack 100h
.data
num1 db 12
num2 db 4

msg_add db 'Addition: $'


msg_sub db 'Subtraction: $'
msg_mul db 'Multiplication: $'
msg_div db 'Division: $'
.code

ADD_MACRO MACRO a, b
mov al, a
add al, b
mov bl, al
ENDM

SUB_MACRO MACRO a, b
mov al, a
sub al, b
mov bl, al
ENDM

MUL_MACRO MACRO a, b
mov al, a
mov bl, b
mul bl
mov bl, al
ENDM

DIV_MACRO MACRO a, b
mov al, a
mov ah, 0
mov bl, b
div bl
mov bl, al
ENDM

PRINT_RESULT MACRO
mov dl, bl
add dl, 30h
mov ah, 02h
int 21h
mov dl, 10
int 21h
mov dl, 13
int 21h
ENDM

main:
mov ax, @data
mov ds, ax

lea dx, msg_add


mov ah, 09h
int 21h
ADD_MACRO num1, num2
PRINT_RESULT

lea dx, msg_sub


mov ah, 09h
int 21h
SUB_MACRO num1, num2
PRINT_RESULT

lea dx, msg_mul


mov ah, 09h
int 21h
MUL_MACRO num1, num2
PRINT_RESULT

lea dx, msg_div


mov ah, 09h
int 21h
DIV_MACRO num1, num2
PRINT_RESULT

mov ah, 4ch


int 21h
end main
OUTPUT

1]

2]
3]

4]

You might also like