0% found this document useful (0 votes)
21 views

SSMP Lab Rec Final

Uploaded by

nishanathpathatt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

SSMP Lab Rec Final

Uploaded by

nishanathpathatt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

DISPLAY A STRING ENDING WITH $

PROGRAM

ASSUME CS:CODE,DS:DATA

DATA SEGMENT
msg1 DB "Hello GEC SKPM$"
DATA ENDS

CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX

MOV AH,09H
MOV DX,OFFSET msg1
INT 21H

MOV AH,4CH ; exit to DOS


INT 21H

CODE ENDS

END START

OUTPUT

C:\FIRST

Hello GEC SKPM


READ AND DISPLAY STRING
PROGRAM

ASSUME CS:CODE,DS:DATA
DATA SEGMENT
msg1 DB 'Enter your string: $'
msg2 DB 'The string is : $' OUTPUT
str1 DB 50 DUP (?) ========

DATA ENDS Enter your string : Hello world


CODE SEGMENT
START: The string is : Hello world
MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET msg1
CALL displaystr
MOV DI,OFFSET str1
CALL readstr
MOV DX,OFFSET msg2
CALL displaystr
MOV DX,OFFSET str1
CALL displaystr
MOV AH,4CH
INT 21H
displaystr proc near
PUSH AX
MOV AH,09H
INT 21H
POP AX
RET
displaystr endp

readstr PROC NEAR


PUSH AX
PUSH DI
readstr_back1:
MOV AH,01H
INT 21H
MOV [DI],AL
INC DI
CMP AL,0DH
JNE readstr_back1
DEC DI
MOV AL,'$'
MOV [DI],AL
POP DI
POP AX
RET
readstr ENDP
CODE ENDS
END START
REVERSING STRING
PROGRAM

ASSUME CS:CODE, DS:DATA

DATA SEGMENT
msg1 DB 'ENTER YOUR STRING : $'
msg2 DB 'THE REVERSED STRING IS: $'
str1 DB 50 DUP(?)
DATA ENDS

CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET msg1
CALL displaystr
MOV DI, OFFSET str1
CALL readstr
CALL reverse_str
MOV DX, OFFSET msg2
CALL displaystr
MOV DX, OFFSET str1
CALL displaystr
MOV AH, 4CH
INT 21H

displaystr PROC NEAR


PUSH AX
MOV AH, 09H
INT 21H
POP AX
RET
displaystr ENDP

readstr PROC NEAR


PUSH AX
PUSH DI

readstr_back1:
MOV AH, 01H
INT 21H
MOV [DI], AL
INC DI
CMP AL, 0DH ; Check for Enter key (Carriage Return)
JNE readstr_back1
DEC DI
MOV AL, '$'
MOV [DI], AL ; End the string with '$'

POP DI
POP AX
RET
readstr ENDP

reverse_str PROC NEAR


PUSH SI
PUSH BX

MOV SI, OFFSET str1


MOV CX, 0

length:
CMP BYTE PTR [SI + CX], '$' ; Find the end of the string
JE start_reverse
INC CX
JMP length

start_reverse:
DEC CX
MOV DI, OFFSET str1
MOV BX, CX ; Set BX to the end of the string (length - 1)

reverse_loop:
CMP DI, BX ; Check if pointers have crossed
JAE done_reverse

MOV AL, [DI] ; Swap characters at DI and BX


MOV DL, [BX]
MOV [DI], DL
MOV [BX], AL

INC DI ; Move DI forward


DEC BX ; Move BX backward
JMP reverse_loop

done_reverse:
POP BX
POP SI
RET
reverse_str ENDP

CODE ENDS
END START

OUTPUT
========

ENTER YOUR STRING : HELLO


THE REVERSED STRING IS: OLLEH
SUM OF N GIVEN NUMBERS
PROGRAM

ASSUME CS:CODE, DS:DATA

DATA SEGMENT
msg1 db 'Enter the limit : $'
msg2 db 'Enter the numbers : $'
msg3 db 'THE SUM IS: $'
newline db 10, 13, '$'
limit DW ?
num_list DW 50 DUP(?)
sum DW 0
DATA ENDS

CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX

; Display prompt to enter the limit


MOV DX, OFFSET msg1
CALL printmsg
CALL readnum ; Read the limit
MOV limit, AX

; Display prompt to enter the numbers


MOV DX, OFFSET msg2
CALL printmsg
MOV DI, OFFSET num_list
MOV CX, limit

back1:
CALL readnum
MOV [DI], AX ; Store numbers to the array num_list
ADD DI, 2
LOOP back1

; Calculate the sum


MOV SI, OFFSET num_list
MOV CX, limit

back2:
MOV AX, [SI]
ADD sum, AX ; Accumulate sum
ADD SI, 2
LOOP back2

; Print newline
CALL printnewline

; Display the result message


MOV DX, OFFSET msg3
CALL printmsg

; Display the sum


MOV AX, sum
CALL displaynum

; Exit to DOS
MOV AH, 4CH
INT 21H

; Procedure to display a message pointed by DX register


printmsg PROC near
PUSH AX
MOV AH, 09H
INT 21H
POP AX
RET
printmsg ENDP

; Procedure to display newline


printnewline PROC NEAR
PUSH DX
MOV DX, OFFSET newline
CALL printmsg
POP DX
RET
printnewline ENDP

; displaynum procedure displays AX in decimal


displaynum PROC near
PUSH AX
PUSH BX
PUSH CX
PUSH DX ; Save registers
MOV CX, 0 ; count <-- 0
MOV BX, 10

displaynum_back1:
MOV DX, 0
DIV BX ; digit = num % 10
PUSH DX ; num = num / 10, push digit
INC CX ; count = count + 1
CMP AX, 0 ; if num > 0, go back to displaynum_back1
JNE displaynum_back1

displaynum_back2:
POP DX ; pop digit
ADD DL, 30H ; convert to ASCII
MOV AH, 02H ; display
INT 21H
LOOP displaynum_back2
POP DX ; Restore registers
POP CX
POP BX
POP AX
RET
displaynum ENDP

; readnum procedure reads a decimal number from the keyboard


; and returns it through AX
readnum PROC near
PUSH BX
PUSH CX ; Save registers
MOV BX, 0 ; NUM <-- 0
MOV CX, 10

readnum_back1:
MOV AH, 01H ; read a single character
INT 21H
CMP AL, '0'
JB readnum_last
CMP AL, '9'
JA readnum_last
SUB AL, 30H ; convert to digit
PUSH AX
MOV AX, BX
MUL CX
MOV BX, AX ; NUM <-- NUM x 10
POP AX
MOV AH, 0
ADD BX, AX ; NUM <-- NUM + digit
JMP readnum_back1

readnum_last:
MOV AX, BX
POP CX ; Restore registers
POP BX
RET
readnum ENDP

CODE ENDS
END START

OUTPUT
========

Enter the limit : 3


Enter the numbers :12 34 56
THE SUM IS: 102
SEARCH A GIVEN NUMBER
PROGRAM

ASSUME CS:CODE, DS:DATA

DATA SEGMENT
msg1 db 'Enter the limit : $'
msg2 db 'Enter the numbers : $'
msg3 db 'Enter the number to search : $'
msg4 db 'Number found $'
msg5 db 'Number Not Found $'
newline db 10, 13, '$'
limit DW ?
num_list DW 50 DUP(?)
target DW ?
DATA ENDS

CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX ; Set DS to the data segment

; Display prompt to enter the limit


MOV DX, OFFSET msg1
CALL printmsg
CALL readnum
MOV limit, AX

; Display prompt to enter numbers


MOV DX, OFFSET msg2
CALL printmsg
MOV DI, OFFSET num_list
MOV CX, limit

back1:
CALL readnum
MOV [DI], AX ; Store the number in num_list
ADD DI, 2
LOOP back1

; Display prompt to enter the number to search


MOV DX, OFFSET msg3
CALL printmsg
CALL readnum
MOV target, AX

; Search for the target number in num_list


MOV SI, OFFSET num_list
MOV CX, limit

search_loop:
MOV AX, [SI]
CMP AX, target
JE found ; If found, jump to found label
ADD SI, 2
LOOP search_loop

; If not found, display "Number Not Found"


MOV DX, OFFSET msg5
CALL printmsg
JMP end_search

found:
; If found, display "Number found"
MOV DX, OFFSET msg4
CALL printmsg

end_search:
CALL printnewline ; Print newline
MOV AH, 4CH
INT 21H ; Exit to DOS

; Procedure to display a message pointed by DX register


printmsg PROC near
PUSH AX
MOV AH, 09H
INT 21H
POP AX
RET
printmsg ENDP

; Procedure to display newline


printnewline PROC NEAR
PUSH DX
MOV DX, OFFSET newline
CALL printmsg
POP DX
RET
printnewline ENDP

; Procedure to read a decimal number from keyboard into AX


readnum PROC near
PUSH BX
PUSH CX
MOV BX, 0
MOV CX, 10

readnum_back1:
MOV AH, 01H
INT 21H
CMP AL, '0'
JB readnum_last
CMP AL, '9'
JA readnum_last
SUB AL, 30H
PUSH AX
MOV AX, BX
MUL CX
MOV BX, AX
POP AX
MOV AH, 0
ADD BX, AX
JMP readnum_back1

readnum_last:
MOV AX, BX
POP CX
POP BX
RET
readnum ENDP

CODE ENDS
END START

OUTPUT
=========
Enter the limit :5
Enter the numbers :2 6 1 4 8
Enter the number to search :6
Number found
=======================================================================
INFINITE ROTATION
PROGRAM

MOV AL,80
OUT 86,AL
back:
MOV AL,09
OUT 84,AL
CALL 3500
MOV AL,0C
OUT 84,AL INPUT
CALL 3500 ========
MOV AL,06
OUT 84,AL 0000:4000 FF
CALL 3500
MOV AL,03 OUTPUT
OUT 84,AL ==========
CALL 3500 MOTOR ROTATED CLOCKWISE
JMP back INFINETLY
HLT

3500: MOV CX,[4000]


3504: DEC CX
3505: JNZ 3504
3507: RET
18 STEPS CLOCKWISE
PROGRAM

MOV AL,80
OUT 86,AL
MOV CX,04
back:
MOV AL,09
OUT 84,AL
CALL 3500

MOV AL,0C
OUT 84,AL INPUT
CALL 3500 =======
0000:4000 FF
MOV AL,06
OUT 84,AL OUTPUT
CALL 3500 ========

MOV AL,03 MOTOR ROTATED 18 STEPS


OUT 84,AL CLOCKWISE SUCCESSFULLY
CALL 3500

DEC CX
JNZ back

MOV AL,09
OUT 84,AL
CALL 3500

MOV AL,0C
OUT 84,AL
CALL 3500

HLT

3500: MOV BX,[4000]


3504: DEC BX
3505: JNZ 3504
3507: RET
ANTI CLOCK WISE INFINTELY ROTATION
PROGRAM

MOV AL,80
OUT 86,AL
back:
MOV AL,03
OUT 84,AL
CALL 3500
MOV AL,06
OUT 84,AL INPUT
CALL 3500 ========
MOV AL,0C
OUT 84,AL 0000:4000 FF
CALL 3500
MOV AL,09 OUTPUT
OUT 84,AL ==========
CALL 3500 MOTOR ROTATED ANTICLOCKWISE
JMP back INFINETLY
HLT

3500: MOV CX,[4000]


3504: DEC CX
3505: JNZ 3504
3507: RET

You might also like