8086 Assembly Language Program
8086 Assembly Language Program
8086 Assembly Language Program
numbers
DATA SEGMENT
NUM1 DW 000AH
NUM2 DW 0004H
GCD DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
;Load the Data to AX.
MOV DS,AX
;Move the Data AX to DS.
MOV AX,NUM1
;Move the first number to AX.
MOV BX,NUM2
;Move the second number to BX.
UP: CMP AX,BX
;Compare the two numbers.
JE EXIT
;If equal, go to EXIT label.
JB EXCG
;If first number is below than second,
;go to EXCG label.
UP1: MOV DX,0H
;Initialize the DX.
DIV BX
;Divide the first number by second number.
CMP DX,0
;Compare remainder is zero or not.
JE EXIT
;If zero, jump to EXIT label.
MOV AX,DX
;If non-zero, move remainder to AX.
JMP UP
;Jump to UP label.
EXCG:XCHG AX,BX
;Exchange the remainder and quotient.
JMP UP1
;Jump to UP1.
EXIT:MOV GCD,BX
;Store the result in GCD.
MOV AH,4CH
INT 21H
CODE ENDS
END START
CALL DISPNUM
mov dl, ' '
mov ah, 02h
int 21h
mov bl, f2
CALL DISPNUM
mov dl, ' '
mov ah, 02h
int 21h
mov ch, 00h
up1:
cmp ch, n
jae exit
mov al, f1
add al, f2
mov f3, al
mov bl, f3
CALL DISPNUM
mov dl, ' '
mov ah, 02h
int 21h
mov al, f2
mov f1, al
mov al, f3
mov f2, al
inc ch
jmp up1
exit:
mov ah, 4ch
int 21h
DISPNUM PROC NEAR
MOV DL, BL
AND DL, 0F0H
; display 1st digit
MOV CL, 04H
SHR DL, CL
CMP DL, 09H
JBE L2
ADD DL, 07H
L2: ADD DL, 30H
MOV AH, 02H
INT 21H
MOV DL, BL
AND DL, 0FH
CMP DL, 09H
;display 2nd digit
JBE L3
ADD DL, 07H
L3: ADD DL, 30H
MOV AH, 02H
INT 21H
RET
DISPNUM ENDP
code ends
end start
DATA SEGMENT
NUM DB 12H
MES1 DB 10,13,'DATA IS POSITIVE $'
MES2 DB 10,13,'DATA IS NEGATIVE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1
JC NEGA
;Move the Number to AL.
;Perform the rotate left side for 1 bit position.
;Check for the negative number.
MOV DX,OFFSET MES1 ;Declare it positive.
JMP EXIT ;Exit program.
NEGA: MOV DX,OFFSET MES2;Declare it negative.
EXIT: MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
INT 21H
CODE ENDS
END START
8086 Assembly Language Program for Logical ones and zeros in a given data
DATA SEGMENT
X DB 0AAH
ONE DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,X
MOV BL,8
;Initialize BL to 8.
MOV CL,1
;Initialize CL to 1.
UP: ROR AH,CL
;Perform the single bit rotate operation
;with respect to right.
JNC DOWN
;If no carry go to DOWN label.
INC ONE
;Increment one.
JMP DOWN1
;Jump to DOWN1.
DOWN: INC ZERO
;Increment ZERO.
DOWN1: DEC BL
;Decrement the BL.
JNZ UP
;If no zero go to UP label.
MOV AH,4CH
INT 21H
CODE ENDS
END START
8086 Assembly Language Program to Find Largest Number Among the Series
DATA SEGMENT
X DW 0010H,52H,30H,40H,50H
LAR DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
MOV AX,[SI]
DEC CX
UP: CMP AX,[SI+2]
JA CONTINUE
MOV AX,[SI+2]
CONTINUE:ADD SI,2
DEC CX
JNZ UP
MOV LAR,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
8086 Assembly Language Program to find smallest number among the series
DATA SEGMENT
X DW 0060H,0020H,0030H,0040H,0050H
MES DB 10,13,'SMALLEST NUMBER AMONG THE SERIES IS $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
MOV AX,[SI]
DEC CX
UP: CMP AX,[SI+2]
JB CONTINUE
MOV AX,[SI+2]
CONTINUE:ADD SI,2
DEC CX
JNZ UP
AAM
ADD AX,3030H
MOV BX,AX
MOV AH,09H
LEA DX,MES
INT 21H
MOV DL,BH
MOV AH,02H
INT 21H
MOV DL,BL
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2
MOV CX,LEN
CLD
REP MOVSB
MOV AH,4CH
INT 21H
CODE ENDS
END START
AND AX,0F0H
MOV CX,0AH
MUL CX
ADD AX,BX
MOV BIN,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Return To Dos
endp
hexToAsc proc near
;AX input , si point result storage addres
mov cx,00h
mov bx,0ah
hexloop1:
mov dx,0
div bx
add dl,'0'
push dx
inc cx
cmp ax,0ah
jge hexloop1
add al,'0'
mov [si],al
hexloop2:
pop ax
inc si
mov [si],al
loop hexloop2
inc si
mov al,'$'
mov [si],al
ret
endp
message db "HexToAsc Character =
strHextToAsc db "
$"
"
end main
ret
Read the current time from the system and display it in the standard format on the
screen.
DATA SEGMENT
MSG1 DB 'CURRENT TIME IS
HR DB ?
MIN DB ?
SEC DB ?
MSEC DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH,2CH
INT 21H
MOV HR, CH
MOV MIN, CL
MOV SEC, DH
MOV MSEC, DL
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AL, HR
AND AL
AAM
MOV BX, AX
CALL DISPLAY
MOV DL, ':'
MOV AH, 02H
INT 21H
MOV AL, MIN
AAM
MOV BX, AX
CALL DISPLAY
MOV DL, ':'
MOV AH, 02H
INT 21H
MOV AL, SEC
: $'
; DISPLAY MINUTES
; DISPLAY ':' AFTER DISPLAYING MINUTES
AAM
MOV BX, AX
CALL DISPLAY
MOV DL, '.'
MOV AH, 02H
INT 21H
MOV AL, MSEC
AAM
MOV BX, AX
CALL DISPLAY
MOV AH, 4CH
INT 21H
DISPLAY PROC NEAR
MOV DL, BH
ADD DL, 30H
MOV AH, 02H
INT 21H
MOV DL, BL
ADD DL, 30H
MOV AH, 02H
INT 21H
RET
DISPLAY ENDP
CODE ENDS
END START
; DISPLAY SECONDS
; DISPLAY '.' AFTER DISPLAYING SECONDS
; DISPLAY BH VALUE
; DISPLAY BL VALUE