0% found this document useful (0 votes)
70 views13 pages

Name:-Prateek Sinha Reg no.:-18BCB0081 Lab Assignment-1: Answers

The document contains a student's name and registration number followed by 4 lab assignments involving assembly language programming concepts: 1. Performing arithmetic operations like addition, subtraction and multiplication of 8-bit numbers. 2. Writing a program to calculate the factorial of a given number using a loop. 3. Copying an array in reverse order and searching for a character in a string. 4. Getting the current system time.

Uploaded by

kumarkl
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)
70 views13 pages

Name:-Prateek Sinha Reg no.:-18BCB0081 Lab Assignment-1: Answers

The document contains a student's name and registration number followed by 4 lab assignments involving assembly language programming concepts: 1. Performing arithmetic operations like addition, subtraction and multiplication of 8-bit numbers. 2. Writing a program to calculate the factorial of a given number using a loop. 3. Copying an array in reverse order and searching for a character in a string. 4. Getting the current system time.

Uploaded by

kumarkl
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/ 13

Name:- Prateek Sinha

Reg no.:-18BCB0081
Lab Assignment-1

Answers:
1. Variables, Arrays and Constants in Arithmetic
Operations (1 and 3)
ALP program to perform the 8 bit add, sub and
multiplication:
Addition:

Answer:000B
Subtraction:
Answer:07FF

Multiplication:
Answer:001E

Write an ALP to perform the following expression, a2+2ab+b2; If the result is even, DL =
EEh, else DH = 00h

Code:
assume cs:code,ds:data
data segment
data1 db 01h
data2 db 01h
data ends
code segment
start:
mov ax,data
mov ds,ax
mov al,data1
mov bl,data2
add al,bl
mov bh,al
mulbh
mov bl,2
div bl
cmp ah,0
je evennumber
mov dh,00h
mov ah,4ch
int 21h
evennumber:
mov dl,238
mov ah,4ch
int 21h
code ends
end start

Output:

2. Loop flow control


Write an ALP to find the factorial of a given number

DATA SEGMENT
A DB 5
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AH,00
MOV AL,A
L1: DEC A
MUL A
MOV CL,A
CMP CL,01
JNZ L1
MOV AH,4CH
INT 21H
CODE ENDS
END START

OUTPUT:
-G CS: 001B
AX=0078 BX=0000 CX=0001 DX=0000 SP=0000 BP=0000 SI=0000
DI=0000
DS=0BA8 ES=0B98 SS=0BA8 CS=0BA9 IP=001B NV UP EI PL ZR NA
PE NC
0BA9:001B B44C MOV AH,4C

Write an ALP program to copy an array in a reverse order

DATA SEGMENT
STR1 DB 01H,02H,05H,03H,04H
STR2 DB 5 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, STR1
LEA DI, STR2+4
MOV CX, 05H
BACK: CLD
MOV AL, [SI]
MOV [DI], AL
INC SI
DEC DI
DEC CX
JNZ BACK
INT 3
CODE ENDS
END STAR
Output:
-G
AX=0B04 BX=0000 CX=0000 DX=0000 SP=0000 BP=0000 SI=0005 DI=0004
DS=0B97 ES=0B87 SS=0B97 CS=0B98 IP=001A NV UP EI PL ZR NA PE NC
0B98:001A CC INT 3
-D 0B97:0000
0B97:0000 01 02 05 03 04 04 03 05-02 01 00 00 00 00 00 00 ................
0B97:0010 B8 97 0B 8E D8 8D 36 00-00 8D 3E 09 00 B9 05 00 ......6...>.....
0B97:0020 FC 8A 04 88 05 46 4F 49-75 F6 CC 2A E4 50 B8 FD .....FOIu..*.P..
0B97:0030 05 50 FF 36 24 21 E8 77-63 83 C4 06 FF 36 24 21 .P.6$!.wc....6$!
0B97:0040 B8 0A 00 50 E8 47 5E 83-C4 04 5E 8B E5 5D C3 90 ...P.G^...^..]..
0B97:0050 55 8B EC 81 EC 84 00 C4-5E 04 26 80 7F 0A 00 74 U.......^.&....t
0B97:0060 3E 8B 46 08 8B 56 0A 89-46 FC 89 56 FE C4 5E FC >.F..V..F..V..^.
0B97:0070 26 8A 47 0C 2A E4 40 50-8B C3 05 0C 00 52 50 E8 &.G.*.@P.....RP.

3. String Operations
Write a program to search a character in string
Code:
data segment
string1 db 'akarsh'
key db 'd'
data ends
code segment
assume cs:code,ds:data
here:
LEA si,string1
mov ax,data
mov ds,ax
mov cx,06h
mov ah,key
l1: mov al,[si]
cmpah,al
jz found
incsi
loop l1
mov dl,'n'
mov ah,02h
int 21h
mov ah,4ch
int 21h
found:
mov dl,'y'
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end here

Write an ALP program to reverse a string


Code:
.model small
.stack 100h
.data
String1 db ' akarsh',0
Length1 dw $-String1-1
.code
Main proc
MOV AX, @data
MOV DS, AX
MOV SI, offset String1
MOV CX, Length1
ADD SI, CX
Back: MOV DL, [SI]
MOV AH, 02H
INT 21H
DEC SI
LOOP Back
MOV AH, 4CH
INT 21H
Main endp
End Main

4. Inbuilt Libraries

Write a program to get the system time.


Code:
MODEL SMALL
.DATA
.CODE
START: MOV AX,@DATA
MOV DS,AX
;Hour Part
HOUR:
MOV AH,2CH ; To get System Time
INT 21H
MOV AL,CH ; Hour is in CH
AAM
MOV BX,AX
CALL DISP
MOV DL,':'
MOV AH,02H ; To Print : in DOS
INT 21H
;Minutes Part
MINUTES:
MOV AH,2CH ; To get System Time
INT 21H
MOV AL,CL ; Minutes is in CL
AAM
MOV BX,AX
CALL DISP
MOV DL,':' ; To Print : in DOS
MOV AH,02H
INT 21H
;Seconds Part
Seconds:
MOV AH,2CH ; To get System Time
INT 21H
MOV AL,DH ; Seconds is in DH
AAM
MOV BX,AX
CALL DISP
;To terminate the Program
MOV AH,4CH ; To Terminate the Program
INT 21H
;Display Part
DISP PROC
MOV DL,BH ; Since the values are in BX, BH Part
ADD DL,30H ; ASCII Adjustment
MOV AH,02H ; To Print in DOS
INT 21H
MOV DL,BL ; BL Part
ADD DL,30H ; ASCII Adjustment
MOV AH,02H ; To Print in DOS
INT 21H
RET
DISP ENDP ; End Disp Procedure
END START ; End of MAIN

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