THUCHANH
BAIF1:
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO SO NGUYEN THU 1:$'
TB2 DB 13,10,'NHAP VAO SO NGUYEN THU 2:$'
TBTONG DB 13,10,'TONG CUA 2 SO LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;XOA MAN HINH
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
MOV AH,1
INT 21H
SUB AL,30H
MOV DL,AL
HIENXAU TB2
MOV AH,1
INT 21H
SUB AL,30H
ADD DL,AL
HIENXAU TBTONG
ADD DL,30H
MOV AH,2
INT 21H
;TRO VE DOS
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
baif2:
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO SO NGUYEN THU 1:$'
TB2 DB 13,10,'NHAP VAO SO NGUYEN THU 2:$'
TBTONG DB 13,10,'TONG CUA 2 SO LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;XOA MAN HINH
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
MOV AH,1
INT 21H
SUB AL,30H
MOV DL,AL
HIENXAU TB2
MOV AH,1
INT 21H
SUB AL,30H
ADD DL,AL
HIENXAU TBTONG
CMP DL,9
JA HAISO
ADD DL,30H
MOV AH,2
INT 21H
JMP KT
HAISO:
XOR AH,AH
MOV AH,0
MOV AL,DL
MOV DL,10
DIV DL
MOV BL,AH
MOV DL,AL
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,BL
ADD DL,30H
INT 21H
KT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai3:
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP1 DB 13,10,'NHAP VAO SO NHI PHAN 1 (<= 8 BIT):$'
TBNHAP2 DB 13,10,'NHAP VAO SO NHI PHAN 2 (<= 8 BIT):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBTONG DB 13,10,'TONG CUA HAI SO NHI PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP1
CALL NHAPNP
XOR DX,DX
MOV DL,BL
HIENXAU TBNHAP2
CALL NHAPNP
XOR BH,BH
ADD DX,BX
HIENXAU TBTONG
MOV BX,DX
XOR DX,DX
XOR CX,CX
TACH:XOR DL,DL
SHR BX,1
ADC DL,30H
PUSH DX
INC CX
CMP BX,0
JNE TACH
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
NHAPNP PROC
KHOITAO:
XOR BL,BL ;MOV BL,0
MOV CX,8
MOV AH,1
NHAP:
INT 21H
CMP AL,13
JE KTNHAP
CMP AL,30H
JB NHAPLAI
CMP AL,31H
JA NHAPLAI
SUB AL,30H
SHL BL,1
OR BL,AL
LOOP NHAP
JMP KTNHAP
NHAPLAI:
HIENXAU TBNHLAI
JMP KHOITAO
KTNHAP:
RET
NHAPNP ENDP
END MAIN
bai4:
;NHAP TUNG SO, NHAP DEN DAU CHUYEN THANH SO DEN DO
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO MOT SO THAP PHAN:$'
TB2 DB 13,10,'DANG NHI PHAN LA:$'
.CODE
MAIN PROC
;khoi tao thanh ghi DS
MOV AX,@DATA
MOV DS,AX
;XOA MAN HINH
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
;HIEN THONG BAO NHAP SO THAP PHAN
HIENXAU TB1
;NHAP TUNG SO, NHAN SO TINH DUOC TRUOC DO VOI 10 ROI CONG VOI SO VUA NHAP
XOR CX,10
MOV DI,0
NHAP:
MOV AH,1
INT 21H
CMP AL,13
JE THOI ;NEU AN ENTER THI THOAT
CMP AL,'-'
JNE TIEP
MOV DI,1
JMP NHAP
TIEP:SUB AL,30H
XOR AH,AH
PUSH AX ;DUA SO VUA NHAP VAO NGAN XEP
MOV AX,BX ; DUA SO TINH DUOC TRUOC DO VAO AX DE NHAN VOI 10
MUL CX ; NHAN SO TRUOC DO TINH DUOC VOI 10
MOV BX,AX ;DUA TICH SANG BX
POP AX ; LAY LAI SO DE TRONG NGA XEP
ADD BX,AX ; CONG SO DO VOI BX ROI DE KET QUA TRONG BX
JMP NHAP
THOI:
CMP DI,0
JE DUARA
NEG BX
DUARA:
HIENXAU TB2
CALL HIENBIN
;TRO VE DOS
MOV AH,4CH
INT 21H
MAIN ENDP
HIENBIN PROC
;CAT CAC THANH GHI
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,16
MOV AH,2
MOV DH,0
HIEN:
XOR DL,DL
ROL BX,1
ADC DL,30H
INT 21H
INC DH
CMP DH,4
JNE HIENTIEP
MOV AH,2
MOV DL,' '
INT 21H
MOV DH,0
HIENTIEP:
LOOP HIEN
POP DX
POP CX
POP BX
POP AX
RET ;TRO VE CHUONG TRINH CHINH
HIENBIN ENDP
END MAIN
bai5:
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO MOT SO THAP PHAN (0-65535):$'
TBSAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TB2 DB 13,10,'DANG NHI PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
XOR BX,BX
MOV CX,10
NHAP:
MOV AH,1
INT 21H
CMP AL,13
JE THOI
CMP AL,'0'
JB NHAPLAI
CMP AL,'9'
JA NHAPLAI
SUB AL,30H
XOR AH,AH
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
ADD BX,AX
JMP NHAP
NHAPLAI:
HIENXAU TBSAI
XOR BX,BX
JMP NHAP
THOI:
HIENXAU TB2
XOR DH,DH
XOR CX,CX
XOR AL,AL
TACH:XOR DL,DL
SHR BX,1
ADC DL,30H
PUSH DX
INC CX
INC AL
CMP AL,4
JNE KTRABX ;KIEM TRA BX
MOV DL,' '
PUSH DX
INC CX
XOR AL,AL
KTRABX:
CMP BX,0
JNE TACH
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai6:
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO MOT SO THAP PHAN (0-65535):$'
TB2 DB 13,10,'DANG SO HEX LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
XOR BX,BX ;DUNG BX CHUA SO NHAP VAO DANG HE 10
MOV CX,10
NHAP:
MOV AH,1
INT 21H
CMP AL,13
JE THOI
SUB AL,30H
XOR AH,AH
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
ADD BX,AX
JMP NHAP
THOI:
HIENXAU TB2
MOV AH,2
INT 21H
DEC CH
JMP TIEP
CHUSO:
ADD DL,37H
INT 21H
DEC CH
CHUSO:
ADD DL,37H
INT 21H
DEC CH
TIEP:
MOV CL,4
ROL BX,CL
CMP CH,0
JNE HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai7:
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 'NHAP VAO MOT SO THAP PHAN (0-65535):$'
TB2 DB 13,10,'DANG SO HEX LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
XOR BX,BX ;DUNG BX CHUA SO NHAP VAO DANG HE 10
MOV CX,10
NHAP:
MOV AH,1
INT 21H
CMP AL,13
JE THOI
SUB AL,30H
XOR AH,AH
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
ADD BX,AX
JMP NHAP
THOI:
HIENXAU TB2
XOR DH,DH
XOR AX,AX
TACH:MOV DL,BL
MOV CL,4
SHR BX,CL
AND DL,0FH
CMP DL,9
JA CHUSO
ADD DL,30H
PUSH DX
INC AX
JMP TIEP
CHUSO:
ADD DL,37H
PUSH DX
INC AX
TIEP:
CMP BX,0
JNE TACH
MOV CX,AX
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai8:
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO SO NHI PHAN (<= 16 BIT):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBRA DB 13,10,'DANG THAP PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BX,BX
MOV CX,16
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,30H
JB NHAPLAI
CMP AL,31H
JA NHAPLAI
SUB AL,30H
SHL BX,1
OR BL,AL
JMP TIEP
NHAPLAI:
HIENXAU TBNHLAI
XOR BX,BX
MOV CX,16
TIEP:
LOOP NHAP
KTNHAP:
HIENXAU TBRA
XOR CX,CX
MOV AX,BX
MOV BX,10
CHIA:XOR DX,DX
DIV BX
ADD DX,30H
PUSH DX
INC CX
CMP AX,0
JNE CHIA
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai9
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO SO NHI PHAN (<= 8 BIT):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBRA DB 13,10,'DANG THAP PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BL,BL
MOV CX,8
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,30H
JB NHAPLAI
CMP AL,31H
JA NHAPLAI
SUB AL,30H
SHL BX,1
OR BL,AL
JMP TIEP
NHAPLAI:
HIENXAU TBNHLAI
XOR BL,BL
MOV CX,8
TIEP:
LOOP NHAP
KTNHAP:
HIENXAU TBRA
AND BL,BL
JNS SODUONG
MOV AH,2
MOV DL,'-'
INT 21H
NEG BL
SODUONG:
XOR CX,CX
MOV AL,BL
MOV BL,10
CHIA:XOR AH,AH
DIV BL
XOR DX,DX
ADD AH,30H
MOV DL,AH
PUSH DX
INC CX
CMP AL,0
JNE CHIA
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai10
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO SO NHI PHAN (<= 16 BIT):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBRA DB 13,10,'DANG SO HEX LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BX,BX
MOV CX,16
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,30H
JB NHAPLAI
CMP AL,31H
JA NHAPLAI
SUB AL,30H
SHL BX,1
OR BL,AL
JMP TIEP
NHAPLAI:
HIENXAU TBNHLAI
XOR BX,BX
MOV CX,16
TIEP:
LOOP NHAP
KTNHAP:
HIENXAU TBRA
MOV AH,2
MOV CH,4
HIEN:MOV DL,BH
MOV CL,4
SHR DL,CL
CMP DL,9
JA CHUSO
ADD DL,30H
INT 21H
DEC CH
JMP KTRA
CHUSO:
ADD DL,37H
INT 21H
DEC CH
KTRA:
MOV CL,4
ROL BX,CL
CMP CH,0
JNE HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai11
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO SO NHI PHAN (<= 16 BIT):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBRA DB 13,10,'DANG SO HEX LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BX,BX
MOV CX,16
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,30H
JB NHAPLAI
CMP AL,31H
JA NHAPLAI
SUB AL,30H
SHL BX,1
OR BL,AL
JMP TIEP
NHAPLAI:
HIENXAU TBNHLAI
XOR BX,BX
MOV CX,16
TIEP:
LOOP NHAP
KTNHAP:
HIENXAU TBRA
XOR AX,AX
TACH: MOV DL,BL
MOV CL,4
SHR BX,CL
AND DL,0FH
CMP DL,9
JA CHUSO
ADD DL,30H
PUSH DX
INC AX
JMP KTRA
CHUSO:
ADD DL,37H
PUSH DX
INC AX
KTRA:
CMP BX,0
JNE TACH
MOV CX,AX
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai12
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO SO HEX (<= 4 SO):$'
TBNHLAI DB 13,10,'NHAP SAI, NHAP LAI:$'
TBRA DB 13,10,'DANG THAP PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BX,BX
MOV CX,4
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,'A'
JB KTRA1
CMP AL,'F'
JA KTRA1
JMP CHUCAI
KTRA1:
CMP AL,'a'
JB KTRA2
CMP AL,'f'
JA KTRA2
SUB AL,20H
JMP CHUCAI
KTRA2:
CMP AL,'0'
JB NHAPLAI
CMP AL,'9'
JA NHAPLAI
JMP CHUSO
CHUSO:
SUB AL,30H
;AND AL,0FH
PUSH CX
MOV CL,4
SHL BX,CL
OR BL,AL
POP CX
JMP TIEP
CHUCAI:
SUB AL,37H
;AND AL,0FH
PUSH CX
MOV CL,4
SHL BX,CL
OR BL,AL
POP CX
JMP TIEP
NHAPLAI:
HIENXAU TBNHLAI
XOR BX,BX
MOV CX,4
JMP NHAP
TIEP:
LOOP NHAP
KTNHAP:
;DUA RA
XOR CX,CX
MOV AX,BX
MOV BX,10
CHIA:XOR DX,DX
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,0
JNE CHIA
HIENXAU TBRA
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai13
.MODEL SMALL
HIENXAU MACRO X
PUSH AX
PUSH DX
MOV AH,9
LEA DX,X
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 13,10,'NHAP VAO MOT SO HEX (<= 4 SO):$'
TBRA DB 13,10,'DANG THAP PHAN LA:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
XOR BX,BX
MOV CX,4
MOV AH,1
NHAP:INT 21H
CMP AL,13
JE KTNHAP
CMP AL,'9'
JA CHUCAI
SUB AL,30H
AND AL,0FH
MOV CL,4
SHL BX,CL
OR BL,AL
JMP TIEP
CHUCAI:
SUB AL,37H
AND AL,0FH
MOV CL,4
SHL BX,CL
OR BL,AL
TIEP:
DEC DH
CMP DH,0
JNE NHAP
KTNHAP:
;DUA RA
XOR AL,AL
XOR CX,CX
TACH:XOR DL,DL
SHR BX,1
ADC DL,30H
PUSH DX
INC CX
INC AL
CMP AL,4
JNE KTRA
MOV DL,' '
PUSH DX
INC CX
XOR AL,AL
KTRA:
CMP BX,0
JNE TACH
HIENXAU TBRA
MOV AH,2
HIEN:POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai14
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBA DB 'NHAP VAO CANH A:$'
TBB DB 13,10,'NHAP VAO CANH B:$'
TBDT DB 13,10,'DIEN TICH CUA HINH CHU NHAT LA:$'
TBCV DB 13,10,'CHU VI CUA HINH CHU NHAT LA:$'
.code
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBA
MOV AH,1
INT 21H
SUB AL,30H
MOV BH,AL
HIENXAU TBB
MOV AH,1
INT 21H
SUB AL,30H
MOV BL,AL
HIENXAU TBDT
MOV AL,BH
MUL BL
CALL HIEN10
HIENXAU TBCV
MOV AL,BH
ADD AL,BL
SHL AL,1
CALL HIEN10
MOV AH,4CH
INT 21H
MAIN ENDP
;CHUONG TRINH CON
HIEN10 PROC
CMP AL,9
JA HAISO
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
JMP KTHUC
HAISO:
XOR AH,AH
MOV DL,10
DIV DL
MOV DH,AH
MOV DL,AL
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,DH
ADD DL,30H
INT 21H
KTHUC:
RET
HIEN10 ENDP
END MAIN
bai15
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TB1 DB 13,10,'NHAP VAO MOT XAU KY TU:$'
TB2 DB 13,10,'XAU DAO LA:$'
XAUKT DB 80 DUP(?)
XAUDAO DB 80 DUP(?)
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;XOA MAN HINH
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TB1
MOV SI,0
MOV AH,1
NHAP:
INT 21H
CMP AL,13
JE KTNHAP
MOV XAUKT[SI],AL
INC SI
JMP NHAP
KTNHAP:
MOV XAUKT[SI],'$'
; XAY DUNG XAU DAO
MOV CX,SI
DEC SI
MOV DI,0
CHUYEN:
MOV AL,XAUKT[SI]
MOV XAUDAO[DI],AL
DEC SI
INC DI
LOOP CHUYEN
MOV XAUDAO[DI],'$'
HIENXAU TB2
;DUA CON TRO RA GIUA MAN HINH
MOV AH,2
MOV DX,80
SUB DX,DI
SHR DX,1 ;CHIA2
MOV DH,12
MOV BH,0
INT 10H
HIENXAU XAUDAO
MOV AH,1
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai16
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 'NHAP VAO 1 XAU CHU CAI:$'
TBSAI DB 13,10,'XAU KY TU CHI GOM CAC CHU CAI',13,10,'NHAP LAI:$'
TBRA DB 13,10,'SO KY TU A HOAC a LA:$'
XAUKT DB 80 DUP(?)
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBNHAP
MOV SI,0
MOV AH,1
NHAP:
INT 21H
CMP AL,13
JE KTNHAP
CMP AL,'A'
JB XETTIEP ;<'A'
CMP AL,'Z'
JA XETTIEP ;>'Z'
;CHU HOA
MOV XAUKT[SI],AL
INC SI
JMP NHAP
XETTIEP:
CMP AL,'a'
JB NHAPLAI ;<'a'
CMP AL,'z'
JA NHAPLAI ;>'z'
MOV XAUKT[SI],AL
INC SI
JMP NHAP
NHAPLAI:
HIENXAU TBSAI
MOV SI,0
JMP NHAP
KTNHAP:
;DEM
MOV CX,SI
MOV SI,0
XOR BX,BX
DOC:
MOV AL,XAUKT[SI]
CMP AL,'A'
JE DEM
CMP AL,'a'
JE DEM
JMP TIEP
DEM:
INC BX
TIEP:
INC SI
LOOP DOC
HIENXAU TBRA
MOV AX,BX
MOV BX,10
XOR CX,CX
CHIA:
XOR DX,DX
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,0
JNE CHIA
MOV AH,2
HIEN:
POP DX
INT 21H
LOOP HIEN
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai17
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAP DB 'NHAP VAO 1 XAU CHU CAI:$'
TBSAI DB 13,10,'XAU KY TU CHI GOM CAC CHU CAI',13,10,'NHAP LAI:$'
TBRA DB 13,10,'XAU CHU HOALA:$'
XAUKT DB 80 DUP(?)
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
HIENXAU TBNHAP
MOV SI,0
MOV AH,1
NHAP:
INT 21H
CMP AL,13
JE KTNHAP
CMP AL,65
;CHU HOA
JB XETTIEP ;<65
CMP AL,90
JA XETTIEP ;>90
;CHU HOA
MOV XAUKT[SI],AL
INC SI
JMP NHAP
XETTIEP:
CMP AL,97
JB NHAPLAI ;<97
CMP AL,122
JA NHAPLAI ;>122
SUB AL,32
MOV XAUKT[SI],AL
INC SI
JMP NHAP
NHAPLAI:
HIENXAU TBSAI
MOV SI,0
JMP NHAP
KTNHAP:
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBRA:
MOV DX,80
SUB DX,SI
SHR DX,1
MOV AH,2
MOV DH,12
MOV BH,0
INT 10H
MOV XAUKT[SI],'$'
HIENXAU XAUKT
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai18
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAPN DB 'NHAP VAO SO PHAN TU CUA DAY:$'
TBNHAPAI DB 13,10,'NHAP VAO SO THU $'
TBMAX DB 13,10,'GIA TRI LON NHAT LA $'
M DB 9 DUP(?)
N DB ?
MAX DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBNHAPN
MOV AH,1
INT 21H
SUB AL,30H
MOV N,AL
XOR CH,CH
MOV CL,N
MOV SI,0
NHAPSO:
HIENXAU TBNHAPAI
MOV DX,SI
ADD DL,31H
MOV AH,2
INT 21H ;DUA RA SI+1
MOV DL,':'
INT 21H ;DUA RA DAU :
MOV DL, ' '
INT 21H ;DUA RA DAU CACH
MOV AH,1
INT 21H ;NHAP VAO CAC SO CUA DAY
SUB AL,30H
MOV M[SI],AL
INC SI
LOOP NHAPSO
;TIM MAX
MOV AL,M[0]
MOV MAX,AL
XOR CH,CH
MOV CL,N
MOV SI,0
LAP:
MOV AL,M[SI]
CMP AL,MAX
JNA TIEP
MOV MAX,AL
TIEP:INC SI
LOOP LAP
;DUA RA MAX
HIENXAU TBMAX
MOV AH,2
MOV DL,MAX
ADD DL,30H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai19
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAPN DB 'NHAP VAO SO PHAN TU CUA DAY:$'
TBNHAPAI DB 13,10,'NHAP VAO SO THU $'
TBMIN DB 13,10,'GIA TRI NHO NHAT LA $'
M DB 9 DUP(?)
N DB ?
MIN DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBNHAPN
MOV AH,1
INT 21H
SUB AL,30H
MOV N,AL
XOR CH,CH
MOV CL,N
MOV SI,0
NHAPSO:
HIENXAU TBNHAPAI
MOV DX,SI
ADD DL,31H
MOV AH,2
INT 21H ;DUA RA SI+1
MOV DL,':'
INT 21H ;DUA RA DAU :
MOV DL, ' '
INT 21H ;DUA RA DAU CACH
MOV AH,1
INT 21H ;NHAP VAO CAC SO CUA DAY
SUB AL,30H
MOV M[SI],AL
INC SI
LOOP NHAPSO
;TIM MIN
MOV AL,M[0]
MOV MIN,AL
XOR CH,CH
MOV CL,N
MOV SI,0
LAP:
MOV AL,M[SI]
CMP AL,MIN
JNB TIEP
MOV MIN,AL
TIEP:INC SI
LOOP LAP
;DUA RA MIN
HIENXAU TBMIN
MOV AH,2
MOV DL,MIN
ADD DL,30H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
bai20
.MODEL SMALL
HIENXAU MACRO XAU
PUSH AX
PUSH DX
LEA DX,XAU
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
.STACK 100H
.DATA
TBNHAPN DB 'NHAP VAO SO PHAN TU CUA DAY:$'
TBNHAPAI DB 13,10,'NHAP VAO SO THU $'
TBRA DB 13,10,'DAY SO VUA NHAP LA:',13,10,'$'
TBTONG DB 13,10,'TONG CUA DAY LA:$'
M DB 9 DUP(?)
N DB ?
TONG DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,0FH
INT 10H
MOV AH,0
INT 10H
HIENXAU TBNHAPN
MOV AH,1
INT 21H
SUB AL,30H
MOV N,AL
XOR CH,CH
MOV CL,N
MOV SI,0
NHAPSO:
HIENXAU TBNHAPAI
MOV DX,SI
ADD DL,31H
MOV AH,2
INT 21H ;DUA RA SI+1
MOV DL,':'
INT 21H ;DUA RA DAU :
MOV DL, ' '
INT 21H ;DUA RA DAU CACH
MOV AH,1
INT 21H ;NHAP VAO CAC SO CUA DAY
SUB AL,30H
MOV M[SI],AL
INC SI
LOOP NHAPSO
;TIM TONG
MOV TONG,0
XOR CH,CH
MOV CL,N
MOV SI,0
LAP:
MOV AL,M[SI]
ADD TONG,AL
INC SI
LOOP LAP
;DUA DAY SO RA
HIENXAU TBRA
XOR CH,CH
MOV CL,N
MOV AH,2
HIEN:
MOV DL,M[SI]
ADD DL,30H
INT 21H
MOV DL,' '
INT 21H
INC SI
LOOP HIEN
;DUA TONG RA
HIENXAU TBTONG
CMP TONG,9
JA HAISO
MOV DL,TONG
ADD DL,30H
MOV AH,2
INT 21H
JMP KETTHUC
HAISO:
XOR AH,AH
MOV AL,TONG
MOV BL,10
DIV BL
MOV BL,AH ;DUA SO DU SANG BL
MOV AH,2
MOV DL,AL
ADD DL,30H
INT 21H ;DUA THUONG RA
MOV DL,BL
ADD DL,30H
INT 21H ;DUA SO DU RA
KETTHUC:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Bạn đang đọc truyện trên: AzTruyen.Top