Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Name:

Rana Muhammad Aqdas

Section:

BSCS 5[A]

Roll No:

Bcsm-S19-046

Class Task Topic:

"Stack"

Submitted to:

Mam SARA

Date:

09/04/2021
Task 1: Define a procedure to reverse an input given by user. You can use the following
algorithm:

Display a “?”

Initialize count to 0

Read a character

WHILE character is not carriage return Do

push character onto the stack

increment count

read a character

END_WHILE

Go to a new line

For count times Do

pop a character from the stack

display it

END_FOR

CODE:
.MODEL SMALL

.STACK 100H

.DATA
.CODE

Main Proc

MOV AH,2

MOV DL, '?'

INT 21H

XOR CX,CX

MOV AH,1

INT 21H

WHILE:

CMP AL,0DH

JE END_WHILE

PUSH AX

INC CX

INT 21H

JMP WHILE

END_WHILE:

MOV AH,2

MOV DL,0DH

INT 21H
MOV DL,0AH

INT 21H

JCXZ EXIT

TOP:

POP DX

INT 21H

LOOP TOP

EXIT:

MOV AH,4CH

INT 21H

MAIN ENDP

END MAIN

Output:
Task 2: Write an assembly program that lets the user to type some text, consisting of
words separated by blanks, ending with carriage return, and display the text in the same
word order as entered, but with the letters in each word reversed. For example, “this is a
test” becomes “siht si a test”.

CODE:
.MODEL SMALL

.STACK 100H

.DATA

PROMPT_1 DB 'Enter the string : $\'

PROMPT_2 DB 0DH,0AH,'The string with words in reverse order : $\'

COUNT DW 0

.CODE

MAIN PROC

MOV AX, @DATA

MOV DS, AX

LEA DX, PROMPT_1

MOV AH, 9

INT 21H

XOR CX, CX

MOV AH, 1

@INPUT:

INT 21H
CMP AL, 0DH

JE @END_INPUT

PUSH AX

INC CX

JMP @INPUT

@END_INPUT:

MOV BX, 50H

XCHG BX, SP

PUSH 0020H

XCHG BX, SP

INC COUNT

@LOOP_1:

POP DX

XCHG BX, SP

PUSH DX

XCHG BX, SP

INC COUNT

LOOP @LOOP_1

LEA DX, PROMPT_2

MOV AH, 9

INT 21H
MOV CX, COUNT

MOV COUNT, 0

PUSH 0020H

INC COUNT

@OUTPUT:

XCHG BX, SP

POP DX

XCHG BX, SP

CMP DL, 20H

JNE @SKIP_PRINTING

MOV AH, 2

@LOOP_2:

POP DX

INT 21H

DEC COUNT

JNZ @LOOP_2

MOV DX, 0020H

@SKIP_PRINTING:

PUSH DX

INC COUNT

LOOP @OUTPUT
MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN
Output:

You might also like