masm.docx

13
;PROGRAM THAT DISPLAYS ASCII CHARACTER SET: STANDARD AND EXTENDED ASCII CHARACTERS .model medium .stack AscInfo segment LastAsc equ 255d AScCount equ 256d SAscCount equ 128d EAscCount equ 128d NewLine equ 10d Space equ 255d msg1 db 'Below is the full ascii character set in its two categories: $' msg2 db '(1) Standard ascii characters: $ ' msg3 db '(2) Extended ascii characters: $' AscInfo ends AscCoding segment assume cs: AScCoding ,ds :AscInfo org 100h start: mov ax, AscInfo mov dx, ax lea dx,msg1 mov ah, 09h int 21h mov dl , LastAsc mov cx, AScCount StoreASc: push dx dec dl loop StoreAsc mov dl, Newline mov ah, 02h int 21h lea dx, msg2 mov ah, 09h int 21h mov ah,02h mov cx,SAscCount OutSAsc: pop dx int 21h mov dl,Space int 21h loop OutSAsc mov ah, 02h mov dl, Newline int 21h lea dx, msg3 mov ah, 09h int 21h mov ah, 02h

Upload: fundooillusion

Post on 26-Oct-2015

11 views

Category:

Documents


2 download

DESCRIPTION

86 beginning

TRANSCRIPT

Page 1: MASM.docx

;PROGRAM THAT DISPLAYS ASCII CHARACTER SET: STANDARD AND EXTENDED ASCII CHARACTERS .model medium .stack AscInfo segment LastAsc equ 255d AScCount equ 256d SAscCount equ 128d EAscCount equ 128d NewLine equ 10d Space equ 255d msg1 db 'Below is the full ascii character set in its two categories: $' msg2 db '(1) Standard ascii characters: $ ' msg3 db '(2) Extended ascii characters: $'

AscInfo ends AscCoding segment assume cs: AScCoding ,ds :AscInfo org 100h start: mov ax, AscInfo mov dx, ax lea dx,msg1 mov ah, 09h int 21h mov dl , LastAsc mov cx, AScCount StoreASc: push dx dec dl loop StoreAsc mov dl, Newline mov ah, 02h int 21h lea dx, msg2 mov ah, 09h int 21h mov ah,02h mov cx,SAscCount OutSAsc: pop dx int 21h mov dl,Space int 21h loop OutSAsc mov ah, 02h mov dl, Newline int 21h lea dx, msg3 mov ah, 09h int 21h mov ah, 02h mov cx,EAscCount OutEAsc: pop dx int 21h mov dl,Space int 21h loop OutEAsc mov ah, 04ch int 21h AscCoding ends end start

Page 2: MASM.docx

Sorting numbers in ascending oreder (signed) using 8086 in assembly language

assume cs:code,ds:datadata segmentorg 2000hseries db 81h,82h,93h,95h,10h,56h,33h,99h,13h,44hcount dw 10ddata endscode segmentstart:mov ax,datamov ds,axmov dx,countdec dxgo:mov cx,dxlea si,seriesnxt_byte:mov al,[si]cmp al,[si+1]jl nextxchg al,[si+1]xchg al,[si]next:inc siloop nxt_bytedec dxjnz gomov ah,4chint 21hcode endsend start

Page 3: MASM.docx

Program to sort numbers in ascending order using 8086 (unsigned numbers)assume cs:code,ds:datadata segmentorg 2000hseries db 81h,82h,93h,95h,10h,56h,33h,99h,13h,44hcount dw 10ddata endscode segmentstart:mov ax,datamov ds,axmov dx,countdec dxgo:mov cx,dxlea si,seriesnxt_byte:mov al,[si]cmp al,[si+1]jb nextxchg al,[si+1]xchg al,[si]next:inc siloop nxt_bytedec dxjnz gomov ah,4chint 21hcode endsend start

Page 4: MASM.docx

Following is the Assembly language program for a real time clock

LCALL 061DAGAIN MOV DPTR, #2845REPEAT DEC82 ; Decrement DPLMOVX A,@DPTRMOV R3,AMOV R5,#02LCALL 059EMOV A,20LCALL 2006MOVA,82CJNE A,#42; REPEAT (ED)MOVA,#OD ; OD = ASCII FOR ENTERLCALL 2006LJMP; AGAIN ( 6003 )

To change the RTC

2844-hrs2843-minutes2842-seconds

Page 5: MASM.docx

WAVEFORM GENERATING PROGRAMAim : Program for Digital to Analog conversionApparatus : 8086 Microprocessor kit with D/A converter Module.MOVW DX #CMD55MOVB AL #MODEOUTB DXMOVB AL #00HLOOP:MOVW DX, #PORTAOUTB DXMOVW DX, #PORTBOUTB DXINCW AXJMP LOOPOPCODE:8000    BA E7 FF

BO 80EEBO 00BA 00BA E1 FFEEBAA E3 FFEE40EB F5

Page 6: MASM.docx

12. BCD ADDITION 2 nosAim : Program to implement BCD AdditionApparatus :  PC with masm Softwaredata segmentv1 dw 0009hv2 dw 0008htotal dw ?data endscode segmentassume cs:code,ds:datastart:mov ax,datamov ds,axmov ax,v1add ax,v2daaint 3code endsend start

Page 7: MASM.docx

8 bit unpacked bcd additiondata segmenta db 07hb db 03hc db ?data endscode segmentassume cs:code,ds:datastart:mov ax,datamov ds,axmov ax,0000hmov al,aadd al,bmov c,alaaaint 3hcode endsend start

Page 8: MASM.docx

8 bit packed bcd additiondata segmenta db 45hb db 55hdata endscode segmentassume cs:code,ds:datastart:mov ax,datamov ds,axmov ax,0000hmov al,aadd al,bdaaint 3hcode endsend start

Page 9: MASM.docx

8086 ASSEMBLY PROGRAM TO SEARCH A CHARACTER IN A ENTERED STRING

DATA SEGMENTMSG1 DB 10,13,'CHARACTER FOUND :) $'MSG2 DB 10,13,'CHARACTER NOT FOUND :($'MSG3 DB 10,13,'ENTER THE STRING : $'MSG4 DB 10,13,'ENTER THE CHARACTER  TO BE SEARCHED : $'NEW DB 10,13,'$'INST DB 10 DUP(0)DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXLEA DX,MSG3MOV AH,09HINT 21HMOV BX,00UP:                             MOV AH,01HINT 21HCMP AL,0DHJE DOWNMOV [INST+BX],ALINC BXJMP UPDOWN:LEA DX,NEWMOV AH,09HINT 21HLEA DX,MSG4MOV AH,09HINT 21HMOV AH,01HINT 21HMOV CX,BXMOV DI,0UP1:CMP AL,[INST+DI]JE DOWN1INC DILOOP UP1LEA DX,MSG2MOV AH,09HINT 21HJMP FINISHDOWN1:LEA DX,MSG1MOV AH,09HINT 21HFINISH:INT 3CODE ENDSEND STARTEND

Page 10: MASM.docx

Pack 2 unpacked BCD nos= ACCII to BCD.model small                                                                                         .dataa db 09Hb db 02H.code       mov     ax,@data       ; Initialize data section       mov     ds,ax       mov     al,a               ; Load number1 in al       mov     bl,b              ; Load number2 in bl       rcl       al,4              ; rotate first number 4 times to make it 90h       add      al,bl              ; add numbers and result in al       mov     ch,02h ; Count of digits to be displayed       mov     cl,04h           ; Count to roll by 4 bits       mov     bh,al             ; Result in reg bhl2:   rol        bh,cl             ; roll bl so that msb comes to lsb       mov     dl,bh            ; load dl with data to be displayed       and      dl,0fH           ; get only lsb       cmp     dl,09            ; check if digit is 0-9 or letter A-F       jbe       l4      add       dl,07            ; if letter add 37H else only add 30Hl4:   add       dl,30H       mov     ah,02            ; Function 2 under INT 21H (Display character)       int       21H       dec      ch                ; Decrement Count       jnz       l2       mov     ah,4cH          ; Terminate Program       int       21H       end

Page 11: MASM.docx

Unpack 2 packed BCD nos= BCD to ASCII.model small.dataa db 92H    .code       mov     ax, @data      ; Initialize data section       mov     ds, ax       mov     al, a              ; Load number1 in al       and      al, 0f0h         ; mask lower nibble       rcr       al, 4             ; rotate it 4 times to right to make it 09h       mov     bh, al            ; store result in bh       call      disp              ; display the upper nibble       mov     al, a              ; Load number1 in al       and      al, 0fh           ; mask upper nibble       mov     bh, al            ; store result in bh       call      disp              ; display the lower nibble       mov     ah, 4cH         ; Terminate Program       int       21H disp  proc near       mov     ch, 02h         ; Count of digits to be displayed       mov     cl, 04h ; Count to roll by 4 bitsl2:    rol       bh, cl            ; roll bl so that msb comes to lsb       mov     dl, bh           ; load dl with data to be displayed       and      l, 0fH            ; get only lsb       cmp     dl, 09           ; check if digit is 0-9 or letter A-F       jbe       l4       add      dl, 07           ; if letter add 37H else only add 30Hl4:    add      dl, 30H       mov     ah, 02           ; Function 2 under INT 21H (Display character)       int       21H       dec      ch                ; Decrement Count       jnz       l2       mov     ah, 02h       mov     dl, ' '       int       21h       endpret      end