100% found this document useful (1 vote)
29 views10 pages

Assembly Programs for Basic Operations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
29 views10 pages

Assembly Programs for Basic Operations

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

Name:Alishba Nadeem

Roll no:Bsai-168

Subject: COAL

Submitted to: Ms. Amna Rauf

Code-01: Write a program to find if the number is Even or Odd? (JE)


include [Link]
.model small
.code
main proc
mov ah,1 ;input the number to be checked
int 21h
mov bl,2 ; divisor/source moved to bl
div bl
cmp ah,0 ; remainder goes to AH, check it
JE even ; remainder zero is
even
JNE odd ; remainder zero is
odd
even:
print "Even"
jmp exit
odd:
print "Odd"
exit:
main endp
end main

Code-05: Write a program to multiply two positive numbers


bya‘repeated addition’ method. For example, to multiply 5ⅹ3, the
programevaluates the product by adding 5 three times, or 5 + 5 + 5.

; multi-segment executable file template.

data segment
; add your data here!
pkey db "press any key...$"
ends

stack segment
dw 128 dup(0)
ends

code segment
start:
mov bl,5
mov cx,3
mov al,0
label1:
add al,bl
LOOP label1

mov bh,10
div bh

mov ah,2
mov dl,al
add dl,30h
int 21h

mov ah,2
mov dl,bl
add dl,30h
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
ends

end start
[Link] two inputs from user and display the largest one.
; multi-segment executable file template.

include [Link]

data segment

; add your data here!

pkey db "press any key...$"

ends

stack segment

dw 128 dup(0)

ends

code segment

start:

mov ah,1

int 21h

mov bl,al

mov ah,1

int 21h
cmp bl,al

JG Greatest

print "Second input is greater"

JMP exit

Greatest:

print "The number 1 is greater"

exit:

mov ax, 4c00h ; exit to operating system.

int 21h

ends

end start ; set entry point and stop the assembler.

[Link] two inputs from user lets say x and y and implement the given
c++ code
.model small

.stack 100h

.data

msg1 db 'Enter x (0 to 4): $'

msg2 db 'Enter y (0 to 9): $'

resultMsg db 'Result: $'

zeroMsg db '0$'

x db ? ; Variable to hold the first input (x)

y db ? ; Variable to hold the second input (y)

.code
main proc

; Initialize the data segment

mov ax, @data

mov ds, ax

; Prompt user for x

lea dx, msg1

mov ah, 09h

int 21h

; Read x

mov ah, 01h

int 21h

sub al, '0' ; Convert from ASCII to integer

mov x, al ; Store x

; Prompt user for y

lea dx, msg2

mov ah, 09h

int 21h

; Read y

mov ah, 01h

int 21h

sub al, '0' ; Convert from ASCII to integer

mov y, al ; Store y

; Check if (x <= 4) && (y <= 9)

mov al, x
cmp al, 4

jg elseBranch ; Jump to else if x > 4

mov al, y

cmp al, 9

jg elseBranch ; Jump to else if y > 9

; Enter the for loop, condition met (x <= 4) && (y <= 9)

mov cx, x ; Load the loop counter with x

forLoop:

mov al, x ; Move x to AL to print

add al, '0' ; Convert back to ASCII

mov dl, al ; Move the character to DL for printing

mov ah, 02h ; Function to display character

int 21h ; Call DOS interrupt

loop forLoop ; Decrement CX and repeat if CX != 0

jmp endProgram ; Jump to end of the program

elseBranch:

; Print "0"

lea dx, zeroMsg

mov ah, 09h

int 21h ; Print "0"

endProgram:

; Exit the program

mov ax, 4C00h

int 21h
main endp

end main

Write an Assembly program to print all the Odd numbers from1 to


100usingloops and Compare instructions.
include '[Link]'

org 100h
mov al, 1

mov cx, ,50

mov bl, 2

iterate:

call PRINT_NUM

call PRINT_CHAR

db ' ', 0

mov ah, al

mov dl, 10

div dl

cmp ah, 0

jne no_newline

call PRINT_CHAR

db 0Dh, 0Ah, 0

no_newline:

add al, bl

loop iterate

DEFINE_PRINT_STRING

DEFINE_PRINT_NUM

DEFINE_PRINT_NUM_UNS

DEFINE_PRINT_CHAR

ret

You might also like