Computer Architecture11

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

KINGDOM OF SAUDI ARABIA | JAZAN UNIVERSITY

COLLEGE OF COMPUTER SCIENCE & INFORMATION TECHNOLOGY


ANSWER ASSIGNMENT- II - 2022 – 2023

1. Write an assembly language program to print the following output

Output:
Displaying 10 stars **********

.model small
.stack 100h
.data
msg db 10, '**********'
.code

start:
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, msg
int 21h

mov ah, 4Ch


int 21h
end start

Ather Way

.MODEL SMALL

.STACK 100H

.DATA

msg db "Displaying 10 stars: $"

.CODE

main proc

mov ax, @data

mov ds, ax

mov ah, 9
lea dx, msg

int 21h

mov cx, 10

mov ah, 2

mov dl, '*'

int 21h

mov ah, 4ch

int 21h

main endp

END main

2. Write an assembly language program to print factorial of a number.

Output:

Factorial 3 is: 6

.MODEL SMALL
.STACK 100h
.DATA
msg db 10,13, "Factorial 3 is: $"
num db 3
res dw 1
.CODE
.STARTUP
mov ax, @DATA
mov ds, ax

mov cx, num ; Initialize counter


mov bx, 1 ; Initialize result

fact:
mul bx ; Multiply result by counter
mov bx,ax ; Store result in bx
dec cx ; Decrement counter
cmp cx, 0 ; Compare counter
jnz fact ; If counter not 0 jump to fact

mov res, bx ; Store result in res

; Print the result


mov dx, offset msg
mov ah, 9
int 21h

mov dx, offset res


mov ah, 9
int 21h

.EXIT
END

Ather Way

program to print factorial of a number;


enter the number;
MOV AH, 01h
INT 21h
MOV CL, AL

factorial calculation;
MOV BX, 1
MOV AX, 1
L1: MUL CL
MOV DX, 0
ADD BX, AX
DEC CL
JNZ L1

printing factorial;
MOV AH, 02h
MOV DL, BX
INT 21h
MOV AH, 4Ch
INT 21h

You might also like