Monday, January 7, 2013

8086 MICROPROCESSOR LAB PROGRAMMING

ASCENDING ORDER
File extension is :asm. for example ascending.asm
mov dx,04
again0:mov cx,dx
mov si,8000h
again1:mov ax,[si]
cmp ax,[si+2]
jge pr1
xchg [si+2],ax
xchg [si],ax
pr1:add si,02
loop again1
dec dx
jnz again0
hlt
ret


DESCENDING ORDER


org 100h

mov dx,04h
again0:mov cx,dx
mov si,8000h
again1:mov ax,[si]
cmp ax,[si+1]
jge pri
xchg [si+2],ax
xchg [si],ax
pri:add si,01h
loop again1
dec dx
jnz again0
hlt
ret

BLOCK TRANSFER

mov si,8000h
mov di,8020h
mov cx,05
nxt:mov ah,[si]
mov [di],ah
inc si
inc di
dec cx
jnz nxt
hlt

org 100h
MOV SI,8000H
MOV DI,8020H
MOV CX,05
NXT:MOV AH,[SI]
MOV [DI],AH
INC SI
INC DI
DEC CX
JNZ NXT
HLT
ret

FACTORIAL
mov bx,[8000h]
mov ax,1
start:mul bx
aam
dec bx
jnz start
mov [8010h],ax
hlt
ret


mov ax,8000h
mov dx,ax
inc dx
inc dx
cmp ax,dx
hlt
ret

org 100h
MOV BX, [8000H]
MOV AX, 1
START:MUL BX
DEC BX
JNZ START
MOV [8010H],AX
HLT
ret

SMALLEST NUMBER

start:mov si,8000H
mov cx,05h
mov al,[si]
again: cmp al,[si+1]
jl next
mov al,[si+1]
next:inc si
dec cx
jnz again
mov si,8080H
mov [si],al
hlt
ret
REVERSE A STRING
mov si,8006h
mov di,9000h
mov cx,06h
again:std
lodsb
cld
stosb
dec cx
jnz again
hlt
ret


SUM OF N NUMBERS
mov bx,00h
mov dx,bx
mov cx,[8000h]
again:inc bx
add dx,bx
daa
cmp cx,bx
jnz again
mov [8010h],dx
hlt
ret


ADD A NUMBER
org 100h
MOV AX,03
MOV BX,05
ADD AX,BX
MOV [2050H],AX
HLT
Ret
ASCENDING ORDER

org 100h
mov dx,04
again0:mov cx,dx
mov si,8000h
again1:mov ax,[si]
cmp ax,[si+2]
jge pr1
xchg [si+2],ax
xchg [si],ax
pr1:add si,02
loop again1
dec dx
jnz again0
hlt
ret


SUM OF N NUMBER

org 100h
MOV BX,00H
MOV DX,BX
MOV CX,[8000H]
AGAIN:INC BX
ADD DX,BX
CMP CX,BX
JNZ AGAIN
MOV [8010H],DX
HLT
ret

org 100h
MOV BX,OOH
MOV DX,BX
MOV CX,[8000H]
AGAIN:INC BX
ADD DX,BX
CMP CX,DX
JNZ AGAIN
MOV [8010H],DX
HLT
ret

org 100h
mov bx,00h
mov dx,bx
mov cx,[8000h]
again:inc bx
add dx,bx
daa
cmp cx,bx
jnz again
mov [8010h],dx
hlt
ret

REVERSE A STRING
org 100h
MOV SI,8006H
MOV DI,9000H
MOV CX,06H
AGAIN:STD
LODSB
CLD
STOSB
DEC CX
JNZ AGAIN
HLT
ret

org 100h
mov si,8006h
mov di,9000h
mov cx,06h
again:std
lodsb
cld
stosb
dec cx
jnz again
hlt
ret
SMALLEST NUMBER
org 100h
start:mov si,8000H
mov cx,05h
mov al,[si]
again: cmp al,[si+1]
jl next
mov al,[si+1]
next:inc si
dec cx
jnz again
mov si,8080H
mov [si],al
hlt
ret
LARGEST NUMBER
org 100h
MOV SI,8000H
MOV CX,08H
MOV AL,[SI]
AGAIN:CMP AL,[SI+1]
JNL NEXT
MOV AL,[SI+1]
NEXT:INC SI
DEC CX
JNZ AGAIN
MOV SI,8080H
MOV [SI],AL
HLT
Ret

0 comments:

Post a Comment