Anda di halaman 1dari 17

Addition of 16 bit number

Data_here Segment fistno dw 0202h Secondno dw 0202h sum dw 2 dup(0) Data_here ends Code_here segment Assume cs:code_here,ds: data_here start: mov ax,data_here mov ds,ax mov ax,fistno mov dx,0000h add ax,secondno jnc go inc dx go:mov sum,ax mov sum+2,dx int 3 code_here ends end start

Subtraction of 16 bit number


Data_here Segment minuend dw 2222h Subrahend dw 1111h result dw 2 dup(0) Data_here ends Code_here segment Assume cs:code_here,ds: data_here start: mov ax,data_here mov ds,ax mov ax,minuend mov dx,subrahend mov cx,0000h cmp dx,dx jnc ahead mov bx,dx mov dx,ax mov ax,bx

mov cx,0001h ahead: sub ax,dx mov result,ax mov result+2,cx int 3 code_here ends end start
ADDITION OF TWO 3X3 MATRICES data segment dim equ 09h mat1 db 01,02,03,04,05,06,07,08,09 mat2 db 01,02,03,04,05,06,07,08,09 rmat3 dw ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,dim mov si,offset mat1 mov di,offset mat2 mov bx,offset rmat3

next: xor ax,ax mov al,[si] add al,[di] mov word ptr [bx],ax inc si inc di add bx,02 loop next mov ah,4ch int 21h code ends end start

MULTIPLICATION OF TWO 3X3 MATRICES

rocol equ 03h mat1 db 05h,09h,0ah,03h,02h,07h,03h,09h,09h mat2 db 09h,07h,02h,01h,0h,0dh,07h,06h,02h

pmat3 db ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ch,rocol mov bx,offset pmat3 mov si,offset mat1 nextrow:mov di,offset mat2 mov cl,rocol nextcol:mov dl,rocol mov bp,0000h mov ax,0000h sahf next_ele:mov al,[si] mul byte ptr[di] add bp,ax inc si

Sorting in ascending order

data segment values db 57h,46h,32h result db ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax initial:lea bx,values mov dl,00h mov cl,02h check: mov al,[bx] inc bx mov ah,[bx] cmp al,ah jc nxtbyt

mov ch,[bx] mov [bx],al dec bx mov [bx],ch inc bx mov dl,01h nxtbyt: dec cl jnz check mov dh,dl ror dh,1 jc initial int 3 code ends end start

Sorting in descending order


data segment values db 32h,46h,57h result db ? data ends code segment assume cs:code,ds:data start: mov ax,data

mov ds,ax initial:lea bx,values mov dl,00h mov cl,02h check: mov al,[bx] inc bx mov ah,[bx] cmp al,ah jnc nxtbyt mov ch,[bx] mov [bx],al dec bx mov [bx],ch inc bx mov dl,01h nxtbyt: dec cl jnz check mov dh,dl ror dh,1 jc initial int 3 code ends

end start

String Manipulation
assume cs:code,ds:data data Segment sourcestr equ 2000h deststr equ 3000h count equ 0fh data ends code segment start: mov ax,data mov ds,ax mov es,ax mov si,sourcestr mov di,deststr mov cx,count cld rep movsb code ends end start

KEYBOARD INTERRUPT PROGRAM TO DISPLAY THE ASCII CODE OF THE KEY PRESSED

DISP MACRO MSG

;Start of macro to DISP

MOV AH,09H ;Move the function code in AH MOV DX,OFFSET MSG ;Load the address of message in DX INT 21H ;Call DOS service for display ENDM ;End of macro DISP

CODE SEGMENT ASSUME CS: CODE ;Assembler directive ASSUME DS: DATA ;Assembler directive MOV AX,DATA ;Initialize DS to DATA MOV DS,AX DISP MSG1 ;Display MSG1 using macro DISP RDKEY: DISP NL ;Display cursor in next line MOV AH,00H ;Move the function code in AX INT 16H ;Call BIOS service to read key code CMP AL,ESC ;Check weather ESC key is pressed

JE OVER ;If yes, jump to OVER, otherwise write character to function code in AH MOV AH,02H ;Move the function code in AH MOV DL,AL ;Load hexcode of key pressed in DL INT 21H ;Call DOS service for display MOV SI,OFFSET ASCI ;Get address for saving ASCII code CALL HEX2ASC ;Call procedure hex to ASCII converter DISP MSG2 ;Display MSG2 using macro DISP DISP ASCI ;Display ASCCI code using macro DISOP JMP RDKEY ;Jump to RDKEY to read next key code OVER: MOV AH,4CH ;Move the function code in AH MOV AL,00H INT 21H ;Return to command prompt HEX2ASC PROC NEAR ;Start of procedure HEX2ASC MOV BL,AL ;Save the key code in BL register AND AL,0F0H ;Mask the lower nibble of key code MOV CL,04H ;rotate upper nibble to lower nibble position ROL AL,CL MOV DL,0AH ;Check weather upper nibble is less than OAH CMP AL,DL JL SKIP1 ;If ;upper nibble is

ADD AL,07H ;less than 0AH,thaen add 30H or if upper SKIP1: ADD AL,30H ;nibble is grater ;than 0AH, then add 37H MOV [SI],AL ;Store the ASCII code of upper nibble MOV AL,BL ;Get the key code in AL register AND AL,0FH ;Mask the upper nibble CMP AL,DL ;Check lower nibble is less than 0Ah JL SKIP2 ;If lower nibble is less than 0AH,. ADD AL,07H ;then add 30H or if lower nibble is SKIP2: ADD AL,30H ;greater than 0aH,then add 37H MOV [SI+1],AL ;Store ASCII code of lower nibble MOV AL,'$' ;Append end of string MOV [SI+2],AL RET ;Return to main program ;End of procedure HEX2ASC

HEX2ASC ENDP CODE ENDS

;Assembler directive ;Assembler directive

DATA SEGMENT

CR EQU 0DH ;ASCII for carriage return LF EQU 0AH ;ASCII for line feed ESC EQU 1BH ;ASCII for escape ASCI DB 8 DUP(0) ;Assembler directive MSG1 DB 'Press any key to test and esc to exit','$' MSG2 DB 'Normal ASCII character code=','$' NL DB CR,LF,'$'

DATA ENDS END

;Assembler directive

;Assembler directive

DISPLAY INTERRUPT

.MODEL SMALL .STACK 64 .DATA MSG DB 'WELCOME TO FOMRA$' .CODE MOV AX, @DATA MOV DS, AX MOV AH, 02H MOV DH, 12H MOV DL, 18H INT 10H MOV AH,09H MOV BX, 97H MOV CX, 10H INT 10H MOV AH, 09H LEA DX, MSG

INT 21H MOV AH, 4CH INT 21H END

FILE MANIPULATION
PROGRAM TO CREATE AND DELETE FILE _data segment ; data segment begins here

file_name db 'new.txt',0 ; name of file to be deleted msg1 db 'successful$' ; messages

msg2 db 'not successful$' _data ends ; end of data segment ; code segment begins here

_code segment

assume cs:_code, ds:_data start: mov ax,_data mov ds, ax mov dx, offset file_name

mov ah, 41h int 21h jc errmsg mov dx, offset msg1 jmp last errmsg: mov dx, offset msg2

; call of interrupt to delete file ; int 21h, function 41h

last: mov ah, 09h ; call of interrupt to display message int 21h ; int 21h, function 09h ; call of interrupt to terminate

mov ax,4c00h program int 21h

_code ends ; code segment ends here end start

TASM Simulation
Steps: 1. 2. 3. 4. Paste the 8086 tools file in c: drive Go to the note pad, create a new text file and type your program Then save file as file name.asm (make sure the extension must in .asm) Go to command prompt:

To open command prompt: Start>>Run>>Type cmd To execute program: In command window type cd\ c:\ cd 8086 tools c:\ 8086 tools\ tasm file name.asm c:\ 8086 tools\ tlink file name.obj c:\ 8086 tools\ debug file name.exe -g To show output

-d 0000 [output address] -e 0000 [input or output address] -q [quit debugger]

d- Display output e- Edit memory

q- Quit debugger

Anda mungkin juga menyukai