0% found this document useful (0 votes)
8 views12 pages

Sum of Natural Numbers 1 To 10: .Model Small .Stack .Data Z DB 1,2,3,4,5,6,7,8,9,10 .Code

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

Sum of natural numbers 1 to 10

.model small

.stack

.data

z db 1,2,3,4,5,6,7,8,9,10

.code

display macro

aam

add ax,3030h

mov dl,ah

mov dh,al

mov ah,02h

int 21h

mov dl,dh

mov ah,02h

int 21h

endm

main proc

mov ax,@data

mov ds,ax

mov cx,10

mov si,0

mov ax,0
top: add al, z[si]

inc si

loop top

display

mov ah,4ch

int 21h

main endp

end main

Receive a string and print it in reverse order:


.model small

.stack

.data

msg1 db 'The string is:$'

msg2 db 'The reverse is:$'

.code

display macro

aam

add ax,3030h

mov dl,ah

mov dh,al
mov ah,02h

int 21h

mov dl,dh

mov ah,02h

int 21h

endm

lfeed macro

mov dl, 0dh

mov ah,02h

int 21h

mov dl, 0ah

mov ah,02h

int 21h

endm

main proc

mov ax,@data

mov ds,ax

lea dx,msg1

mov ah,09h

int 21h
mov cx,00

top:

mov ah,01h

int 21h

cmp al,0Dh

je down1

push ax

inc cx

jmp top

down1:

lfeed

lea dx,msg2

mov ah,09h

int 21h

down:

pop dx

mov ah,02h

int 21h

loop down

mov ah,4ch

int 21h
main endp

end main

3. Program to receive a string and change the case.


.MODEL SMALL

.DATA

MSG1 DB 'ENTER THE LOWERCASE LETTER:$'

MSG2 DB 'THE UPPERCASE LETTER IS :$'

.STACK

.CODE

DISPLAY MACRO

AAM

ADD AX,3030H

MOV DL,AH

MOV DH,AL

MOV AH,02H

INT 21H

MOV DL,DH

MOV AH,02H

INT 21H

ENDM

LFEED MACRO

MOV DL, 0DH

MOV AH,02H
INT 21H

MOV DL, 0AH

MOV AH,02H

INT 21H

ENDM

MAIN PROC

MOV AX,@DATA

MOV DS,AX

TOP:

LFEED

LEA DX, MSG1

MOV AH,09H

INT 21H

MOV AH,01H

INT 21H

CMP AL, 0DH

PUSH AX

JE DOWN

LFEED

LEA DX,MSG2

MOV AH,09H
INT 21H

POP AX

SUB AL,32 ;(AND AL, 11011111B)

MOV DL,AL

MOV AH,02H

INT 21H

JMP TOP

DOWN:

MOV AH,4CH

INT 21H

MAIN ENDP

END MAIN

reverse a string using array


.model small

.stack

.data

msg1 db 'The string is:$'

msg2 db 'The reverse is:$'

y db ?

.code

display macro

aam
add ax,3030h

mov dl,ah

mov dh,al

mov ah,02h

int 21h

mov dl,dh

mov ah,02h

int 21h

endm

lfeed macro

mov dl, 0dh

mov ah,02h

int 21h

mov dl, 0ah

mov ah,02h

int 21h

endm

main proc

mov ax,@data

mov ds,ax
lea dx,msg1

mov ah,09h

int 21h

mov si,0

top:

mov ah,01h

int 21h

cmp al,0Dh

je down1

mov y[si],al

inc si

jmp top

down1:

mov cx,si

lfeed

lea dx,msg2

mov ah,09h

int 21h

down:

dec si

mov dl,y[si]

mov ah,02h
int 21h

loop down

mov ah,4ch

int 21h

main endp

end main

To print “SURYA”
.model small

.stack

.data

z db 's','u','r','y','a'

.code

display macro

aam

add ax,3030h

mov dl,ah

mov dh,al

mov ah,02h

int 21h

mov dl,dh

mov ah,02h

int 21h
endm

lfeed macro

mov dl, 0dh

mov ah,02h

int 21h

mov dl, 0ah

mov ah,02h

int 21h

endm

main proc

mov ax,@data

mov ds,ax

mov cx ,5

mov si,0

top:

mov dl,z[si]

mov ah,02h

int 21h

inc si

loop top
mov ah,4ch

int 21h

main endp

end main

You might also like