0% found this document useful (0 votes)
48 views5 pages

Coal Assignment 3 Name: Faizan Tariq Roll No: 22F-3858 Section: 3D

Task 1 checks if the input number 1221 is a palindrome by reversing the number and comparing it to the original. Task 2 calculates the factorial of 6 by multiplying it by descending numbers. Task 3 converts the decimal number 15 to binary by dividing it by 2 and storing the remainders.

Uploaded by

f223858
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)
48 views5 pages

Coal Assignment 3 Name: Faizan Tariq Roll No: 22F-3858 Section: 3D

Task 1 checks if the input number 1221 is a palindrome by reversing the number and comparing it to the original. Task 2 calculates the factorial of 6 by multiplying it by descending numbers. Task 3 converts the decimal number 15 to binary by dividing it by 2 and storing the remainders.

Uploaded by

f223858
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/ 5

COAL

Assignment 3
Name : Faizan Tariq
Roll No: 22F-3858
Section: 3D

TASK 1:
CODE:
org 0x100
; to check if number is palidrome or not
num dw 1221 ; Replace with your input number (16-bit)

mov ax,[num] ; Load the original number into AX


mov bx, ax
xor cx, cx ; Clear CX for the reversed number
;loop to reverse the number and store in cx
reverse_loop:
xor dx, dx ; Clear DX for the division
mov si, 10 ; SI is the divisor
div si ; Divide AX by 10, result in AX, remainder in DX
imul cx, 10 ; Multiply CX by 10
add cx, dx ; Add the digit to CX
cmp ax, 0 ; Check if AX is zero means end of original number
jnz reverse_loop

mov ax, [num]


cmp ax, cx
jz palindrome
mov ax ,2H ; for not palindrome set ax to 2
jmp exit
palindrome:
mov ax, 1H ; for palindrome set ax to 1
exit:
mov ax, 0x4c00
int 21h

OUTPUT:

TASK 2:
[org 0x0100]
jmp start
num : dw 6
fact: dw 0

start: mov ax,[num]


mov bx,0

loop1: cmp ax,1


jle fact0

mov dx,ax
sub dx,1
mov cx,dx
multiply: shr cx,1
jnc skipaddition
add bx,ax

skipaddition:
cmp cx,0
jz next
shl ax,1
jmp multiply
next: sub dx,1
mov ax,dx
cmp ax,1
jle fact0

mov ax,bx

mov bx,0
mov cx,dx
jmp multiply
fact0: cmp bx,0
jnz movebx
mov word [fact],1
jmp end

movebx: mov [fact],bx


end: mov ax,0x4c00
int 21h

OUTPUT:

TASK 3:
Code:
[org 0x100]

jmp start
decimal_num dw 15
binaryArray db 0, 0, 0, 0, 0, 0, 0, 0

start:
mov cx,2 ; for divide by 2
mov ax, [decimal_num] ; Move the decimal number into the AX register
mov bx,binaryArray+7

; Loop will terminate when decimal number is zero


loop1:
; Divide the AX register by 2 and store the remainder in the Dl register
xor dx, dx
div cx ;cx = 2
mov [bx],dl
dec bx ; to store at prev index then before
cmp ax,0
jnz loop1

exit:
mov ax,[binaryArray]
mov ax, 0x4c00
int 21h

OUTPUT:

TASK 4:
org 100h

jmp start
num4 : dw 60,55,-55,60,-60,58,-58,-58,25,15,34,87,90,12,65
swap : db 0

start:
mov bx, 0
mov byte[swap], 0
loop1:
mov ax, [num4 +bx]
mov dx,[num4+bx+2]
cmp dx,ax
jge noswap
mov [num4+bx+2] ,ax
mov [num4+bx],dx
mov byte[swap],1
noswap: add bx,2
cmp bx, 28
jne loop1
cmp byte[swap],1
je start
mov ax,num4
mov ax, 0x4c00
int 21h

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy