Вы находитесь на странице: 1из 6

MASM PROGRAMS

Wap to print hello data segment string db hello$ data ends code segment assume cs: code, ds: data start: mov ax , data mov ds , ax mov dx , offset string mov ah,09h int 21h mov ah,4ch int 21h code ends end start Wap to print hello using macro print macro args mov dx, offset args mov ah,09h int 21h endm data segment m1 db hello$ m2 db 0dh,0ah,good morning$ data ends code segment assume cs: code, ds: data start: mov ax , data mov ds , ax print m1 print m2 mov ah,4ch int 21h code ends end start Wap to add two no.s data segment x db 01h y db 02h r db 02dup(?) data ends code segment

assume cs: code, ds: data start: mov ax , data mov ds , ax mov ax , x add ax , y mov di, offset r mov [di] , ax mov ah,4ch int 21h code ends end start Wap to add two numbers entered through keyboard and show the result print macro msg mov dx, offset msg mov ah,09h int 21h endm data segment cr equ 0dh lf equ 0ah msg1 db enter the 1st no:$ msg2 db cr,lf, enter 2nd no:$ msg3 db cr,lf,sum=$ sum dw 0000h outs dw 10 dup(?) data ends code segment assume cs: code, ds: data start: mov ax , data mov ds , ax print msg1 call read add sum , cx print msg2 call read add sum,cx print msg3 mov ax , sum call disp print outs mov ah,4ch int 21h read proc mov ax,0000h mov bx,000ah mov cx,0000h L1: mov ah,01h int 21h cmp al.0dh

jz L2 mov ah,00h sub al,30h push ax mov ax,cx mul bx mov cx,ax pop ax add cx,ax jmp L1 L2: ret read endp disp proc mov bx,000ah mov cx,0000h mov di , offset outs mov dx,0024h push dx inc cx L3: mov dx,0000h div bx add dx,0030h push dx inc cx cmp ax,0000h jz L3 L4: pop [di] inc di loop L4 ret disp endp code ends end start Wap to find the factorial of a number print macro msg mov dx, offset msg mov ah,09h int 21h endm data segment cr equ 0dh lf equ 0ah msg1 db enter the no:$ msg2 db cr,lf, factorial=1$ msg3 db cr,lf, factorial=$ outs dw 10 dup(?) data ends code segment assume cs: code, ds: data

start: mov ax , data mov ds , ax print msg1 call read cmp cx,0000h jz L5 mov bx,0000h mov ax,0001h L6: push cx inc bx mul bx pop cx dec cx jnz L6 print msg3 call disp print outs jmp L7 L5: print msg2 L7: mov ah,4ch int 21h read proc disp proc code ends end start Wap to check the given no is prime or not print macro msg mov dx, offset msg mov ah,09h int 21h endm data segment cr equ 0dh lf equ 0ah m1 db enter the no:$ m2 db cr,lf, prime$ m3 db cr,lf, not prime$ m4 db cr,lf, neither prime nor composite$ data ends code segment assume cs: code, ds: data start: mov ax , data mov ds , ax print m1 call read cmp cx,0000h jz L5 cmp cx,0001h

jz L5 mov bx , cx L7: mov dx,0000h push cx dec bx cmp bx,0001h jz L6 pop ax mov cx,ax div bx cmp dx,0000h jnz L7 print m3 jmp L8 L6: print m2 jmp L8 L5: print m4 L8: mov ah,4ch int 21h read proc disp proc code ends end start Wap to reverse a string print macro msg mov dx, offset msg mov ah,09h int 21h endm data segment cr equ 0dh lf equ 0ah m1 db enter the string$ m2 db cr,lf, entered string$ m3 db cr,lf, reversed string$ outs1 dw 10 dup(?) outs2 dw 10 dup(?) data ends code segment assume cs: code, ds: data start: mov ax , data mov ds , ax print m1 mov si , offset outs1 mov cx, 0000h L1: mov ah,01h int 21h cmp al,0dh jz L2

mov [si],al inc si inc cx jmp L1 print m2 print outs1 L2: mov di , offset outs2 L3: dec si mov al,[si] mov [di],al inc di loop L3 mov al,24h mov [di],al print m3 print outs2 mov ah,4ch int 21h code ends end start

Вам также может понравиться