Vous êtes sur la page 1sur 15

MICROPROCESSOR 8086 Programming Examples

## Setting the Cursor Interrupt 10H Function 02H AH Register Required Page Number BH Register Row DH Register Column DL Register ## Clearing the Screen Interrupt 10H Function 06H AH Register Number of Lines to Scroll AL Register Attribute Value( color ,reverse video blinking) Starting Row: Column CX Register Ending Row: Column DX Register ## Display Interrupt 21H Function 09H in AH Register Requires definition of display string in data area immediately followed by $ sign. Load address of display string in dx.

BH Register

Samrat Subedi samratsubedi@kec.edu.np

## Keyboard Input Interrupt 21H Function OA in AH register Address of Paralist DX register

## Screen Display For single Character Interrupt 21H Function 02H Character to display

DL(ASCII)

## single character input interrupt 21H Function 01H Input character AL

## DIVISION Dividend AX reg. Divisor 8 bit reg./memory Q AL R AH Dividend DX:AX Divisor 16 bit reg./Memory Q AX
Samrat Subedi samratsubedi@kec.edu.np

R DX ## MULTIPLICATION Multiplicand AL AX Multiplier 8-bit mem/Reg. 16-bit mem/Reg Product AX DX:AX

6. Display the name of your college on location 08,15 with white on black(07) color attribute.

dosseg . model small . stack 100h . data college db 'katipur engineering college','$' . code main proc mov ax@data mov ds,ax ; clearing the screen mov ah,06H mov al , 00H mov bh ,07H mov cx,000H mov dx ,184FH INT 10H ; setting cursor to 08,15 mov ah, 02H
Samrat Subedi samratsubedi@kec.edu.np

mov bh,00H mov dh,08H mov dl,15H INT 10H ; display mov ah,09H Lea dx,college INT 21H mov ax,4c00h INT 21H Main Endp End Main 7. Display ASCII character dosseg . model small . stack 100h . data ASCHAR db,00,'$' . code main proc mov ax@data mov ds,ax write down same code as in above program to set cursor and clearing the screen ;display ASCII mov cx,256 Lea dx,ASCHR nxt: mov ah,09H INT 21H INC ASCHAR loop nxt
Samrat Subedi samratsubedi@kec.edu.np

mov ax,4c00h INT 21H Main Endp End Main 8. Write an assembly language program to read string of maximum 70 character and display it on the centre of screen.

dosseg . model small . stack 100h . data maxlen db 70 actlen db ? string 71 dup('$') . code main proc far mov ax@data mov dx, ax mov ah,0AH Lea DX, maxlen int 21H (clear the screen-yourself) :set the cursor(style 1) mov bl, act_len SHR bl,01H mov dl,40 SUB DL,BL mov dh, mov bh,00H INT 10H set the cursor style 2)
Samrat Subedi samratsubedi@kec.edu.np

mov al, actlen mov ah,00H mov bl,02H div bl mob bl,al mov al,28H sub al,bl mov ah,02H mov bh,00H mov dh,12H mov dl,al int 10H ; Display mov ah,09H Lea DX,string INT 21H mov ax,4c00h INT 21H Main Endp End Main 9. Add table of data and display in hex format.

dosseg . model small . stack 100h . data st0 dw 30h,40h,60h st1 db 4dup(' '),'$' . code main proc mov ax@data
Samrat Subedi samratsubedi@kec.edu.np

mov ds,ax Lea si,st0 mov ax,0000H mov cx,0003H addn: Add ax,[si] inc si inc si loop addn mov bx,ax Lea si,st1+3 mov cx,04H Again: Push cx and ax,000f cmp al,0aH Ja L1 OR al,30H L2: mov [si],al mov cl,04H mov ax,bx RCR ax,cl mov bx,ax dec si POP cx loop again mov ah,09H Lea dx,St1 int 21H mov ax,4c00H INT 21H L1: add al,57H JMP l2 main endp end main
Samrat Subedi samratsubedi@kec.edu.np

10. Add table of data and display in hex format


Logic to convert hex to decimal A|4D2H__ 4 A|7BH___ 3 A|C_____ 2 1

i.e 4DH= 1234D

Dosseg . model small . stack 100h .data st0 dw 30,40 st1 dh 4dup(' '),'$' .code main proc mov ax@data mov ds, ax lea si, st0 mov ax,0000h mo cx, 0002h addn: add ax,[si] inc si inc si loop addn Lea si,st1+3 Mov cx,0010 {000Ah} L2: Cmp ax,cx Jb li Xor dx,dx Div cx
Samrat Subedi samratsubedi@kec.edu.np

Or dl 30h Mov [si],dl Dec si Jmp L2 L1: Or al,30h Mov [si],al Mov ah,09h Lea dx st1 Int 21h Mov ax,4c00h Int 21h Main endp End main

11. Display list of words in decimal format Dosseg . model small . stack 100h .data val1 dw 20,50,60 val2 db 4dup(' '),'$' .code Main proc Mov ax@data Mov ds,ax Lea si, val1 Mov ax,0000h Mov cx,00003h Nxt: Mov ax,[si] Mov bx,0010
Samrat Subedi samratsubedi@kec.edu.np

Lea di val2+3 L2: Cmp ax,bx Jb L1 Xor dx,dx Div bx Or dl 30h Mov [di],al Mov ah 09h Lea dx val2 Int 21h Inc si Inc si Loop nxt Mov ax,4c00h Main endp End main 12. Separate words from string Dosseg .model small .stack 100h .data para_list label type {option} max_len db 20 act_len db ? kb_data db 50 dup(' ') . code main proc mov ax @ data mov ds,ax ;input string and set delimiter
Samrat Subedi samratsubedi@kec.edu.np

mov ah 0Ah lea dx, para_list int 21h mov bx,dx mov [bx+act_len+1] ; clear screen{u can do it urself} lea si kb_data mov ch,00h mov cl, act_len ; set cursor location mov dh, 00h call curlocation nxtchar: mov al, [si] cmp al, ' ' je nxtrow ; display char mov ah,02h mov dl,al int 21h nxtword: inc si loop nxtchar mov ax, 4c00h int 21h main endp nxtrow: inc dh call curlocation jmp nxtword curlocation: mov ah, 02h mov bh, 00h
Samrat Subedi samratsubedi@kec.edu.np

mov dl, 00h int 10h ret End main

13. Number input dosseg .model small .stack 100h .code main proc far mov ax,@data mov ds,ax mov ah,01h int 21h mov dl, al mov ah,01h int 21h add al, dl aaa ( ascii adjust after addition) mov dx, ax OR dh,30h OR dl,30h Mov ah,02h Mov ax,4c00h Int 21h Main endp End main

Samrat Subedi samratsubedi@kec.edu.np

14. write an assembly language program using 8086 instruction to read a string of max length 40 char and display each word on a centre of screen. .model small .stack 64h .data Max_len db 40 Act_len db ? String_1 db 40dup('$') .code main proc far mov ax@data mov ds,ax mov ah,0Ah lea dx, max_len (or mov dx offset max_len) int 21h Mov si,00h ; starting of word Mov di,00h ;ending of word Mov cl,act_len Mov ch, 00h ; set counter Start: mov al , string_1[di] Cmp al,20h (or cmp al , ' ') Je L2 Inc di Loop start L2: Mov ax, di Sub cx, si Mov si,di Inc si Mov bl,al ; total length of a word Shr al, 1
Samrat Subedi samratsubedi@kec.edu.np

Call set_cursor Call display Inc dh Loop start Mov ax, 4c00h Int 21h Main endp Set_cursor proc near Mov dl,40 Sub dl, al Mov ah, 02h Int 21h Ret Display proc near L3: mov ah, 02h Mov dl, string_1[di-bx] Int 21h Dec bx Jnz L3 15. write an assembly language program to read two single digit number multiply them and then display the result in decimal format. . model small .stack 64h .data String db " Please input two number", 0Ah,0dd,'$' .code Main proc far Mov ax, @data Mov ds,ax
Samrat Subedi samratsubedi@kec.edu.np

Mov ah,09h Lea dx.string Int 21h Mov ah,01h Int 21h Sub al,30h ; character input is in AL Mov bl,al Mov ah,01h Int 21h Sub al,30h Mul bl Mov cl ,0Ah Div cl Mov dh ah Add al,30h Mov ah,02h Mov dl,al Int 21h Add dh ,30h Mov ah, 02h Int 21h Mov ax,4c00h Int 21h Main endp End main. Micro program:Micro-program is a special program written in the central memory of computer to perform the timing and sequencing of the micro operation. In register to register transfer operation where fetch and execute cycle of complete instruction are divided into small operation which can be executed in a single clock period. These operation are called micro operation.
Samrat Subedi samratsubedi@kec.edu.np

Vous aimerez peut-être aussi