Microprocessor File
Microprocessor File
Microprocessor File
Microprocessor File
Made by:
Name: Pulkit Aggarwal
Roll No: 755/IT/12
NSIT,Delhi
lea dx,msg2
mov ah,09H
int 21H
mov ah,01H
int 21H
sub al,30H
cmp al,09H
JBE L3
sub al,07H
L3: mov cl,04H
ROL al,cl
mov bh,al
mov ah,01H
int 21H
sub al,30H
cmp al,09H
JBE L4
sub al,07H
L4:ADD bh,al
ADD bl,bh
lea dx,msg3
mov ah,09H
int 21H
mov ch,02H
mov cl,04H
L5:ROL bl,cl
mov bh,bl
AND bl,0FH
cmp bl,09H
JBE L6
ADD bl,07H
L6:ADD bl,30H
mov dl,bl
mov ah,02H
int 21H
mov bl,bh
dec ch
JNZ L5
mov ah,4ch
int 21H
end
Average
.model small
.stack 100
.data
No1
DB 63H
No2
DB 2EH
Avg
DB ?
.code
START:
MOV AX,@data
; [ Initialises
MOV DS,AX
; data segment ]
MOV AL,NO1
ADD AL,NO2
; Add second to it
ADC AH,00H
; Put carry in AH
SAR AX,1
MOV Avg,AL
; Divide sum by 2
; Copy result to memory
END START
Multiplication
.model small
.data
a db 09H
b db 02H
.code
mov
ax, @data
mov
ds, ax
mov
ah, 0
mov
al, a
; Load number1 in al
mov
bl, b
; Load number2 in bl
mul
bl
mov
ch, 04h
mov
cl, 04h
mov
bx, ax
; Result in reg bx
bx, cl
mov
dl, bl
and
dl, 0fH
cmp
dl, 09
jbe
l4
add
dl, 07
l2: rol
l4: add
dl, 30H
mov
ah, 02
int
21H
dec
ch
jnz
l2
; Decrement Count
mov
ah, 4cH
int
21H
; Terminate Program
end
DB 10, 13, 'Enter the total number of elememts in the array : $'
M2
M3
; Display message M1
INT 21H
SUB AL,30H
MOV BH,AL
MOV BL,AL
XOR DI,DI
MOV CL,4
BACK:
MOV AH, 09H
MOV AH,01
INT 21H
SUB AL,30H
SAL AL,CL
MOV CH,AL
MOV AH,01
INT 21H
SUB AL,30H
OR CH,AL
MOV [ARRAY+DI],CH
INC DI
DEC BL
JNZ BACK
MOV CH,BH
AGAIN1: MOV DI,0
AGAIN: MOV DL,[ARRAY+DI]
CMP DL,[ARRAY+DI+1]
JBE SKIP
MOV AH,[ARRAY+DI+1]
MOV [ARRAY+DI],AH
MOV [ARRAY+DI+1],DL
SKIP: INC DI
MOV AH,0
MOV AL,BH
DEC AL
CMP AX,DI
JNZ AGAIN
DEC CH
JNZ AGAIN1
MOV AH, 09H
; Display message M1
INT 21H
MOV BL,BH
XOR DI,DI
BACK1:
MOV AH, 09H
CALL SHOWARR
LEA SI,ARRONE
LEA DI,ARRTWO
MOV CL,10
MVLP:
MOV AL,[SI]
MOV ES:[DI],AL
INC SI
INC DI
CMP CL,00H
JE SKP3
DEC CL
LOOP MVLP
SKP3:
LEA DX,MSG
MOV AH,09H
INT 21H
CALL SHOWARR2
MOV AH,4CH
INT 21H
MAIN ENDP
SHOWARR PROC
LEA SI,ARRONE
MOV CL,10
DSPLP:
MOV DL,[SI]
MOV AH,02H
INT 21H
INC SI
CMP CL,00H
JE SKP2
DEC CL
LOOP DSPLP
SKP2:
RET
SHOWARR ENDP
SHOWARR2 PROC
LEA DI,ARRTWO
MOV CL,10
DSPLP2:
MOV DL,ES:[DI]
MOV AH,02H
INT 21H
INC DI
CMP CL,00H
JE SKP4
DEC CL
LOOP DSPLP2
SKP4:
RET
SHOWARR2 ENDP
END
2) Code conversion
a) BCD to Binary(HEX)
.MODEL SMALL
.STACK 64H
.DATA
TESTARR DB 'abc$'
CHARARR DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA SI,CHARARR
INP: MOV AH,01H
INT 21H
CMP AL,0DH
JE SKP1
AND AX,00FFH
SUB AL,30H
MOV [SI],AX
ADD SI,1
LOOP INP
SKP1: MOV [SI],'$'
LEA SI,CHARARR
MOV DL,0AH
MOV AH,02H
INT 21H
OPT: MOV DH,[SI]
CMP DH,'$'
JE SKP2
;MOV AH,02H
;INT 21H
CALL BCD2BIN
INC SI
LOOP OPT
SKP2:
MOV AH,4CH
INT 21H
MAIN ENDP
BCD2BIN PROC
PUSH AX
PUSH CX
PUSH BX
PUSH DX
PUSH SI
MOV CL,08H
LB :
SAL DH,1
JC PRTONE
CMP CL,04H
JG SKP3
MOV DL,48
MOV AH,02H
INT 21H
JMP SKP3
PRTONE: CMP CL,04H
JG SKP3
MOV DL,49
MOV AH,02H
INT 21H
SKP3: DEC CL
CMP CL,00H
JE SKP4
JMP 040H
SKP4: MOV DL,' '
MOV AH,02H
INT 21H
POP SI
POP DX
POP BX
POP CX
POP AX
RET
BCD2BIN ENDP
.STACK 64H
.DATA
MSG1 DB 13,10,'Enter binary code in BCD format: $'
MSG2 DB 13,10,'Resultant decimal: $'
BINARRAY DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
AND DX,00FFH
LEA SI,BINARRAY
IN1: MOV AH,01H
INT 21H
CMP AL,' '
JNE RST
MOV CL,00H
ADD DL,48
MOV [SI],DL
INC SI
AND DX,0000H
RST: CMP AL,0DH
JE IN1_BRK
SAL DX,1
AND AX,00FFH
SUB AL,30H
ADD DX,AX
LOOP IN1
IN1_BRK: ADD DL,48
MOV [SI],DL
INC SI
MOV DL,'$'
MOV [SI],DL
MOV DL,10
MOV AH,02H
INT 21H
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA DX,BINARRAY
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
AND DX,00FFH
LEA SI,BINARRAY
IN1: MOV AH,01H
INT 21H
CMP AL,' '
JNE RST
MOV CL,00H
MOV [SI],DL
INC SI
AND DX,0000H
RST: CMP AL,0DH
JE IN1_BRK
SAL DX,1
AND AX,00FFH
SUB AL,30H
ADD DX,AX
LOOP IN1
IN1_BRK: MOV [SI],DL
INC SI
MOV DL,'$'
MOV [SI],DL
MOV DL,10
MOV AH,02H
INT 21H
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA DX,BINARRAY
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
INC SI
LOOP OPT
SKP2:
MOV AH,4CH
INT 21H
MAIN ENDP
ASC2BIN PROC
PUSH AX
PUSH CX
PUSH BX
PUSH DX
PUSH SI
MOV CL,08H
LB :
SAL DH,1
JC PRTONE
MOV DL,48
MOV AH,02H
INT 21H
JMP SKP3
PRTONE: MOV DL,49
MOV AH,02H
INT 21H
SKP3: DEC CL
CMP CL,00H
JE SKP4
JMP 03EH
SKP4: MOV DL,' '
MOV AH,02H
INT 21H
POP SI
POP DX
POP BX
POP CX
POP AX
RET
ASC2BIN ENDP
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV BX,00
UP:
MOV AH,01H
INT 21H
CMP AL,0DH
JE DOWN
MOV [INST+BX],AL
INC BX
LOOP UP
DOWN:
MOV DI,0
DEC BX
JNZ CHECK
CHECK:
MOV AL,[INST+BX]
CMP AL,[INST+DI]
JNE FAIL
INC DI
DEC BX
JNZ CHECK
LEA DX,NEW
MOV AH,09H
INT 21H
LEA DX,MSG2
MOV AH,09H
INT 21H
JMP FINISH
FAIL:
LEA DX,MSG3
MOV AH,09H
INT 21H
FINISH:
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
Password Matching
.MODEL SMALL
.DATA
MSG1 DB 13,10,'Create password: $'
MSG2 DB 13,10,'Input password: $'
MSG3 DB 13,10,'Password matched.$'
MSG4 DB 13,10,'Password did not match.$'
PASSWORD DB 20 DUP(0)
INPUTSTR DB 20 DUP(0)
.CODE
MAIN PROC
MOV DX,@DATA
MOV DS,DX
MOV ES,DX
LEA DX,MSG1
MOV AH,09H
INT 21H
LEA SI,PASSWORD
CALL INSTRING
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA SI,INPUTSTR
CALL INSTRING
MOV DL,10
MOV AH,02H
INT 21H
LEA SI,PASSWORD
LEA DI,INPUTSTR
CALL PASSCHECK
MOV AH,4CH
INT 21H
MAIN ENDP
INSTRING PROC
INPASS_LP1: MOV AH,01H
INT 21H
CMP AL,0DH
JE INPASS_SKP
AND AX,00FFH
MOV [SI],AX
ADD SI,1
LOOP INPASS_LP1
INPASS_SKP: MOV [SI],'$'
RET
INSTRING ENDP
PASSCHECK PROC
PASSCHECK_LP: MOV DX,[SI]
MOV CX,[DI]
CMP DX,CX
JNE FAIL
CMP DL,'$'
JE SUCCESS
ADD SI,1
ADD DI,1
LOOP PASSCHECK_LP
SUCCESS: LEA DX,MSG3
MOV AH,09H
INT 21H
RET
FAIL: LEA DX,MSG4
MOV AH,09H
INT 21H
RET
PASSCHECK ENDP
3b) Find the register bit width, byte order of your processor.
Byte order
DATA_HERE SEGMENT
MSG DB "SIZE IS:",13,10,'$'
DATA_HERE ENDS
CODE_HERE SEGMENT
ROL BX,1
CMP BX,DX
JZ LOOPO
INC CX
JMP LOOPS
LOOPO:
MOV DL,CL
ADD DL,30H
MOV AH,02H
INT 21H
MOV AX, 4C00H
INT 21H
CODE_HERE ENDS
END START
Register Width
DATA_HERE SEGMENT
MSG1 DB "LITTLE ENDIAN",13,10,'$'
MSG2 DB "BIG ENDIAN",13,10,'$'
TEMP DW 1 DUP(0)
DATA_HERE ENDS
CODE_HERE SEGMENT
ASSUME DS:DATA_HERE, CS:CODE_HERE,
START:
MOV AX, DATA_HERE
MOV DS,AX
LEA SI, TEMP
MOV [SI], 1234H
MOV CX,[SI]
CMP CH,CL
JL MSG
MOV DX, OFFSET MSG2
MOV AX,0
MOV AH, 09H
INT 21H
MSG:
CODE_HERE ENDS
END START
MOV DX,@DATA
MOV DS,DX
LEA DX,MSGIN
MOV AH,09H
INT 21H
IN1:
MOV AH,01H
INT 21H
CMP AL,0DH
JE NXT
SUB AL,30H
MOV DL,AL
MOV AX,BX
MOV CL,0AH
MUL CL
MOV BX,AX
AND DX,00FFH
ADD BX,DX
MOV DELAYTIME,BX
LOOP IN1
NXT: MOV CX,DELAYTIME
MOV DL,10
MOV AH,02H
INT 21H
LEA SI,MSG1
LP: PUSH DX
MOV DL,[SI]
CMP DL,'$'
JE NXT2
MOV AH,02H
INT 21H
ADD SI,1
POP DX
MOV DI,DELAYTIME
MOV AH, 0
INT 1Ah
MOV BX, DX
Delay:
MOV AH, 0
INT 1Ah
SUB DX, BX
CMP DI, DX
JA Delay
LOOP LP
NXT2: MOV AH,4CH
INT 21H
END
.code
mov ax, @data
mov ds, ax
lea si, prefix
lea di, postfix
mov es, di
jmp label1
label3:
push di
mov di, es
mov al,[si]
mov [di],al
inc di
mov es, di
pop di
dec di
label5: cmp [di],'\' ;di pointing to temp
jz label4
inc di
mov [di],'\'
inc di
inc si
dec cx
jmp label1
label4:
dec di
cmp [di],'\'
jz label4
push si
push di
mov si, di
mov di, es
mov di, 0
pop si
jmp label5
label6:
mov ah, 09h
lea dx, enter
int 21h
lea dx, msg2
int 21h
lea dx, postfix
int 21h
end
$"
mem db 10 dup(0)
.code
main proc
mov ax,@data
mov ds,ax
mov si,0100h
mov bp,0104h
ok:
lea dx,s1
mov ah,09h
int 21h
lea dx,s2
mov ah,09h
int 21h
lea dx,s3
mov ah,09h
int 21h
lea dx,s4
mov ah,09h
int 21h
lea dx,s5
mov ah,09h
int 21h
mov ah,01h
;taking input
int 21h
cmp al,34h
;if exit
je exit
cmp al,31h
;insert
je insert
cmp al,33h
je display1
;display
jmp ok
;45
insert:
lea dx,s9
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,31h
je first
jmp after
ok1: jmp ok
first:
lea dx,s6
mov ah,09h
int 21h
mov ah,01h
int 21h
mov byte ptr [si],al
inc si
mov word ptr [si],0000h
jmp ok
after:
lea dx,s6
mov ah,09h
int 21h
mov ah,01h
int 21h
mov cl,al
lea dx,s10
mov ah,09h
int 21h
mov ah,01h
int 21h
mov di,0100h
search :
;90
mov bx,word ptr [di+1]
mov byte ptr [bp],cl
;storind address
mov dx,bp
inc di
mov word ptr [di],dx
inc bp
inc bp
inc bp
inc bp
jmp ok1
lea dx,s7
mov ah,09h
int 21h
now:
mov dl,byte ptr [si]
mov ah,02h
int 21h
lea dx,s8
;for space
mov ah,09h
int 21h
inc si
mov cx , word ptr [si]
cmp cx,0000h
je ok2
mov si,word ptr[si]
jmp now
;129
; initialize DS
; set BX=10
; load and display the string PROMPT_1
CALL BUBBLE_SORT
INT 21H
MAIN ENDP
;**************************************************************************;
;**************************************************************************;
;------------------------- Procedure Definitions ------------------------;
;**************************************************************************;
;**************************************************************************;
;**************************************************************************;
;----------------------------- PRINT_ARRAY ------------------------------;
;**************************************************************************;
PRINT_ARRAY PROC
; this procedure will print the elements of a given array
; input : SI=offset address of the array
;
: BX=size of the array
; output : none
PUSH AX
PUSH CX
PUSH DX
MOV CX, BX
; set CX=BX
@PRINT_ARRAY:
XOR AH, AH
MOV AL, [SI]
; loop label
; clear AH
; set AL=[SI]
CALL OUTDEC
MOV AH, 2
MOV DL, 20H
INT 21H
INC SI
; set SI=SI+1
LOOP @PRINT_ARRAY
; jump to label @PRINT_ARRAY while CX!=0
POP DX
POP CX
POP AX
RET
; return control to the calling procedure
PRINT_ARRAY ENDP
BUBBLE_SORT PROC
; this procedure will sort the array in ascending order
; input : SI=offset address of the array
;
: BX=array size
; output : none
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
MOV AX, SI
MOV CX, BX
DEC CX
; set AX=SI
; set CX=BX
; set CX=CX-1
@OUTER_LOOP:
MOV BX, CX
MOV SI, AX
MOV DI, AX
; loop label
; set BX=CX
; set SI=AX
; set DI=AX
INC DI
@INNER_LOOP:
MOV DL, [SI]
; set DI=DI+1
; loop label
; set DL=[SI]
@SKIP_EXCHANGE:
; jump label
INC SI
; set SI=SI+1
INC DI
; set DI=DI+1
DEC BX
; set BX=BX-1
JNZ @INNER_LOOP
; jump to label @INNER_LOOP if BX!=0
LOOP @OUTER_LOOP
; jump to label @OUTER_LOOP while CX!=0
POP DI
POP DX
POP CX
POP BX
POP AX
RET
; return control to the calling procedure
BUBBLE_SORT ENDP
OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none
PUSH BX
PUSH CX
PUSH DX
XOR CX, CX
MOV BX, 10
@OUTPUT:
XOR DX, DX
DIV BX
PUSH DX
INC CX
OR AX, AX
JNE @OUTPUT
MOV AH, 2
@DISPLAY:
POP DX
OR DL, 30H
INT 21H
LOOP @DISPLAY
; loop label
; pop a value from STACK to DX
; convert decimal to ascii code
; print a character
; jump to label @DISPLAY if CX!=0
POP DX
POP CX
POP BX
RET
OUTDEC ENDP
END MAIN
MOV CH,BH
AGAIN1: MOV DI,0
AGAIN: MOV DL,[ARRAY+DI]
CMP DL,[ARRAY+DI+1]
JBE SKIP
MOV AH,[ARRAY+DI+1]
MOV [ARRAY+DI],AH
MOV [ARRAY+DI+1],DL
SKIP: INC DI
MOV AH,0
MOV AL,BH
DEC AL
CMP AX,DI
JNZ AGAIN
DEC CH
JNZ AGAIN1
MOV AH, 09H
; Display message M1
MOV DX, OFFSET M2
INT 21H
MOV BL,BH
XOR DI,DI
BACK1:
MOV AH, 09H
; Carrige return and next line
MOV DX, OFFSET M3
INT 21H
MOV DL,[ARRAY+DI]
AND DL,0F0H
SAR DL,CL
ADD DL,30H
MOV AH,02
INT 21H
MOV DL,[ARRAY+DI]
AND DL,0FH
ADD DL,30H
MOV AH,02
INT 21H
INC DI
DEC BL
JNZ BACK1
TER: MOV AH, 4CH
INT 21H
END START
;complement of y
;sbb al, bh
add al, dh
sar al, 1
shr bl, 1
jmp start
label3:
mov ax, es
sar al, 1
jmp start
label2:
mov es, ax
pop ax
cmp ah, 01h
jz label4
mov ax, es
sar al, 1
shr bl, 1
jmp start
label4:
mov ax, es
add al, bh
sar al, 1
shr bl, 1
jmp start
next:
mov cx, 8
mov bl, al
print: mov ah, 2 ; print function.
mov dl, '0'
test bl, 10000000b ; test first bit.
jz zero
lea dx,msg1
mov ah,09h
int 21h
mov dx,0000H
mov cl,8
IN1: CMP CL,0
JE IN1_BRK
MOV AH,01H
INT 21H
SAL DX,1
AND AX,00FFH
SUB AL,30H
ADD DX,AX
LOOP IN1
IN1_BRK:
MOV AX,DX
;================================
AND AX,00FFH
MOV DIVIDEND,AX
;NEXT LINE AND CARRIAGE RETURN==
MOV DL,10
MOV AH,02H
INT 21H
MOV DL,13
MOV AH,02H
INT 21H
;================================
;USER INPUT for DIVISOR==========
lea dx,msg2
mov ah,09h
int 21h
mov dx,0000H
mov cl,8
IN2:CMP CL,0
JE IN2_BRK
MOV AH,01H
INT 21H
SAL DX,1
AND AX,00FFH
SUB AL,30H
ADD DX,AX
LOOP IN2
IN2_BRK:
MOV BX,DX
;================================
MOV DIVISOR,BX
;RESTORING DIVISION==============
MOV AX,DIVIDEND
MOV BX,DIVISOR
MOV CX,8
RD_LP: ROL AX,1
CMP AH,BL
JB NEGVAL
SUB AH,BL
ADD AX,1
NEGVAL: LOOP RD_LP
AND AX,00FFH
MOV RESULT,AX
;NEXT LINE AND CARRIAGE RETURN==
MOV DL,10
MOV AH,02H
INT 21H
;
;
MOV DL,13
MOV AH,02H
INT 21H
;
;
;================================
;DECIMAL OUTPUT CODE================
MOV BL,0AH
MOV AX,RESULT
MOV CX,0100H
PUSH CX
RES1: DIV BL
CMP AL,00H
JE NXT3
MOV CL,AL
MOV CH,00H
MOV RESULT,CX
MOV DL,AH
ADD DL,30H
AND DX,00FFH
PUSH DX
MOV AX,RESULT
LOOP RES1
NXT3: MOV DL,AH
CMP DL,00H
JNE NXT4
ADD DL,01H
NXT4: ADD DL,30H
PUSH DX
LEA DX,msg3
MOV AH,09H
INT 21H
MOV CL,08H
RES2: POP AX
CMP CL,00H
JE SKPND
MOV DL,AL
MOV AH,02H
INT 21H
DEC CL
LOOP RES2
;=================================
SKPND:
MOV AH,4CH
INT 21H
END
int 21h
mov dx,0000H
mov cl,8
IN2:CMP CL,0
JE IN2_BRK
MOV AH,01H
INT 21H
SAL DX,1
AND AX,00FFH
SUB AL,30H
ADD DX,AX
LOOP IN2
IN2_BRK:
MOV BX,DX
;================================
MOV DIVISOR,BX
;NON-RESTORING DIVISION==============
MOV AX,DIVIDEND
MOV BX,DIVISOR
MOV CX,8
ROL AX,1
SUB AH,BL
NRD_LP: CMP AH,80H
JB POSVAL
JMP NEGVAL
NEGVAL: CMP CX,00H
JE NRD_LP_BRK
ROL AX,1
ADD AH,BL
DEC CX
JMP NRD_LP
MOV AH,02H
INT 21H
;
;
MOV DL,13
MOV AH,02H
INT 21H
;
;
;================================
;DECIMAL OUTPUT CODE================
MOV BL,0AH
MOV AX,RESULT
MOV CX,0100H
PUSH CX
RES1: DIV BL
CMP AL,00H
JE NXT3
MOV CL,AL
MOV CH,00H
MOV RESULT,CX
MOV DL,AH
ADD DL,30H
AND DX,00FFH
PUSH DX
MOV AX,RESULT
LOOP RES1
NXT3: MOV DL,AH
CMP DL,00H
JNE NXT4
ADD DL,01H
NXT4: ADD DL,30H
PUSH DX
LEA DX,msg3
MOV AH,09H
INT 21H
MOV CL,08H
RES2: POP AX
CMP CL,00H
JE SKPND
MOV DL,AL
MOV AH,02H
INT 21H
DEC CL
LOOP RES2
;=================================
SKPND:
MOV AH,4CH
INT 21H
END